joshua_cheek
|
codepad
|
|
joshua_cheek
|
Saved pastes by joshua_cheek:
def get_record(file)
make = file.gets.chomp
model = file.gets.chomp
colour = file.gets.chomp
mileage = file.gets.chomp
|
view (189 lines, 87 lines of output) |
require 'rubygems'
# adds the pp method, which stands for "pretty print"
# is useful for visualising long arrays/hashes
require 'pp'
|
view (33 lines, 39 lines of output) |
class IceCreamStand
def service( person , hooks = Hash.new )
hooks[:before]['ice cream'] if hooks[:before]
puts "Ice Cream Stand: Here is some Ice Cream for #{person.name}!"
hooks[:after]['ice cream'] if hooks[:after]
|
view (73 lines, 21 lines of output) |
#include <stdio.h>
int main() {
char a[]="#include <stdio.h>%2$cint main() {%2$c char a[]=%3$c%1$s%3$c;%2$c printf(a,a,10,34);%2$c return 0;%2$c}";
printf(a,a,10,34);
return 0;
|
view (6 lines, 6 lines of output) |
# a simple tree that keeps track of the value of a node
# each node tracks it's parent, but parents do not track their children
# so you can only traverse the tree from end to start
class SimpleTree
|
view (73 lines, 7 lines of output) |
class StoreAndCall
def initialize(&lambda)
@lambda = lambda # store lambda in instance var, for use in foo
end
|
view (17 lines, 1 line of output) |
# a possible solution to http://www.ruby-forum.com/topic/201997
require 'rexml/document'
require 'rexml/formatters/pretty'
|
view (60 lines, 32 lines of output) |
#include <stdio.h>
#include <stdlib.h>
//argc holds how many parameters the program received when called
//argv holds their values
|
view (53 lines, 1 line of output, 1 comment) |
#include <stdio.h>
#include <stdlib.h>
//argc holds how many parameters the program received when called
//argv holds their values
|
view (45 lines, 1 comment) |
#include <stdio.h>
void case_test( int outter , int inner )
{
printf( "before switch: outter=%d , inner=%d\n" , outter , inner );
|
view (27 lines, 9 lines of output, 1 comment) |
#include <stdio.h>
int cube( int x ) { printf("2mul %d\n",x); return x*x*x; }
int sum( int x , int y , int z ) { printf("2add\n"); return x+y+z; }
|
view (18 lines, 14 lines of output, 1 comment) |
#include <stdio.h>
int is_greater_than_20 ( int x ){ printf( "FIRST\n" ); return x > 20 ; }
int is_less_than_30 ( int x ){ printf( "SECOND\n" ); return x < 30 ; }
|
view (17 lines, 11 lines of output, 1 comment) |
#include<stdio.h>
#define FSM
#define STATE(x) s_##x :
#define NEXTSTATE(x) goto s_##x
|
view (38 lines, 8 lines of output, 1 comment) |
void myFunction(int* values) {
while(*values) printf("%d\n" , *values++ );
}
int main()
|
view (9 lines, 4 lines of output, 1 comment) |
#include <stdio.h>
int main()
{
typedef struct string { char* chars; } Table1 , Table2;
|
view (24 lines, 1 line of output, 1 comment) |
class Setting
def self.all
[ Setting.new( 'key1' , 'val1' , 'desc1' ) ,
Setting.new( 'key2' , 'val2' , 'desc2' ) ,
|
view (43 lines, 8 lines of output, 1 comment) |
#initialize variables / constants
print "How many dice do you wish to play with? "
NUMBER_OF_DICE = gets.to_i
FAIL_VALUE = 1
score , turns , rolls = 0 , 0 , Array.new(NUMBER_OF_DICE)
|
view (40 lines, 1 comment) |
today = Time.now
# To format the time, you submit a format string to the strftime method
# the options you can use in the string can be seen at
|
view (25 lines, 6 lines of output) |
#Learning Ruby chapter 9
#single inheritance
#modules = interfaces from Java
class Hello
|
view (165 lines, 18 lines of output, 1 comment) |
#Learning Ruby chapter 7
h = {"a" => 1 , "b" => 2 , 3 => "c" , :x => [1,2,3] , [0,1,2] => [:r,:s,:t]}
puts "pre: h = #{h.inspect}"
|
view (46 lines, 25 lines of output, 1 comment) |
#Learning Ruby chapter 6
a = [1,3,5,7]
b = [2,4,6,7]
puts "1 intersection: #{a.inspect} & #{b.inspect} = #{(a&b).inspect}"
|
view (86 lines, 36 lines of output, 1 comment) |
#Learning Ruby chapter 5
#hierarchy and reflection
puts "1 #{1.class}"
puts "2 #{1.class.ancestors.inspect}"
|
view (95 lines, 47 lines of output, 1 comment) |
#Learning Ruby chapter 4
#strings
puts "1 #{"".empty?}" #.empty? instead of .length==0
x = String.new("abc")
|
view (54 lines, 21 lines of output, 1 comment) |
#Learning Ruby chapter 2
#blocks: iterate through something
pacific = ["Washington" , "Oregon" , "California" ]
pacific.each do |state|
|
view (229 lines, 57 lines of output, 1 comment) |
#Learning Ruby chapter 1
puts "VERSION = #{VERSION}"
#appending a string
puts "1Hello " + "world"
|
view (79 lines, 22 lines of output, 1 comment) |
# comments begin with pound
# define a function
def my_function( param1 , param2=5 )
return param1*param2
|
view (51 lines, 10 lines of output, 1 comment) |
//returns the number of matches, where a match is some character in both strings
int find_match( char m[] , char s[] )
{
//using 384 because it guarantees that no matter how the compiler interprets a char
//it will have enough room. The union of possible domains should be -128 through 255
|
view (32 lines, 3 lines of output, 1 comment) |
#include<stdio.h>
void print_chars( char c , int how_many , char* separator )
{
while( how_many-- )
|
view (25 lines, 5 lines of output, 1 comment) |
puts "VERSION = #{VERSION}"
output = ['five','four','three','two','one','zero']
puts "Input Converted to:"
output=output.reverse
|
view (15 lines, 15 lines of output) |
output = ['five','four','three','two','one','zero']
puts "Input Converted to:"
output=output.reverse
output.each do |text|
|
view (13 lines, 14 lines of output) |