[ create a new paste ] login | about

joshua_cheek

Name:
Email:
Site/Blog:
Location:
Default language: Ruby
Favorite languages:
About:

Saved pastes by joshua_cheek:

Ruby, pasted on May 10:
1
2
3
4
5
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)
Ruby, pasted on Sep 22:
1
2
3
4
5
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)
Ruby, pasted on Jun 11:
1
2
3
4
5
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)
C, pasted on Mar 29:
1
2
3
4
5
#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)
Ruby, pasted on Feb 26:
1
2
3
4
5
# 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)
Ruby, pasted on Feb 14:
1
2
3
4
5
class StoreAndCall
  
  def initialize(&lambda)
    @lambda = lambda # store lambda in instance var, for use in foo
  end
...
view (17 lines, 1 line of output)
Ruby, pasted on Jan 12:
1
2
3
4
# 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)
C, pasted on Nov 30:
1
2
3
4
5
#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)
C, pasted on Nov 30:
1
2
3
4
5
#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)
C, pasted on Nov 26:
1
2
3
4
5
int i;

# 18 "pass_by_name_vs_pass_by_value.c"
int three_times( int a )
{
...
view (29 lines, 2 lines of output, 1 comment)
C, pasted on Nov 26:
1
2
3
4
5
#include <stdio.h>
#include <stdarg.h>

void say_hello( char* name ) 
{
...
view (66 lines, 15 lines of output, 1 comment)
C, pasted on Nov 26:
1
2
3
4
5
#include <stdio.h>

int i;

//pass by name
...
view (43 lines, 2 lines of output, 1 comment)
C, pasted on Nov 19:
1
2
3
4
5
#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)
C, pasted on Nov 19:
1
2
3
4
#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)
C, pasted on Nov 19:
1
2
3
4
#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)
C, pasted on Nov 15:
1
2
3
4
5
#include <stdio.h>

int main()
{
  int a = 3;
...
view (11 lines, 2 lines of output, 1 comment)
C, pasted on Nov 15:
1
2
3
4
#include <stdio.h>

int main()
{
...
view (32 lines, 2 lines of output, 1 comment)
C, pasted on Nov 15:
1
2
3
4
5
#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)
C, pasted on Nov 12:
1
2
3
4
5
void myFunction(int* values) {
  while(*values) printf("%d\n" , *values++ );
}

int main()
...
view (9 lines, 4 lines of output, 1 comment)
C, pasted on Nov 11:
1
2
3
4
#include <stdio.h>
#include <string.h>

exec sql include sqlca;
...
view (94 lines, 1 comment)
C, pasted on Nov 1:
1
2
3
4
5
#include <stdio.h>

int main()
{
  typedef struct { char* chars; } string;  
...
view (24 lines, 1 line of output, 1 comment)
C, pasted on Nov 1:
1
2
3
4
5
#include <stdio.h>

int main()
{
  typedef struct string { char* chars; } Table1 , Table2;
...
view (24 lines, 1 line of output, 1 comment)
Ruby, pasted on Oct 31:
1
2
3
4
class Setting
  def self.all
    [ Setting.new( 'key1' , 'val1' , 'desc1' ) ,
      Setting.new( 'key2' , 'val2' , 'desc2' ) ,
...
view (43 lines, 8 lines of output, 1 comment)
Ruby, pasted on Oct 29:
1
2
3
4
5
#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)
Ruby, pasted on Oct 27:
1
2
3
4
5
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)
Ruby, pasted on Oct 26:
1
2
3
4
5
#Learning Ruby chapter 9

#single inheritance
#modules = interfaces from Java
class Hello
...
view (165 lines, 18 lines of output, 1 comment)
Ruby, pasted on Oct 26:
1
2
3
4
5
#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)
Ruby, pasted on Oct 26:
1
2
3
4
5
#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)
Ruby, pasted on Oct 26:
1
2
3
4
5
#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)
Ruby, pasted on Oct 26:
1
2
3
4
5
#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)
Ruby, pasted on Oct 26:
1
2
3
4
5
#Learning Ruby chapter 3

#using conditional
x = 256
puts "1 x=256" if x == 256
...
view (78 lines, 20 lines of output, 1 comment)
Ruby, pasted on Oct 26:
1
2
3
4
5
#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)
Ruby, pasted on Oct 26:
1
2
3
4
5
#Learning Ruby chapter 1
puts "VERSION = #{VERSION}"

#appending a string
puts "1Hello " + "world"
...
view (79 lines, 22 lines of output, 1 comment)
Ruby, pasted on Oct 26:
1
2
3
4
$stdin = DATA

print "Enter your first name: "
fname = gets.chomp
...
view (13 lines, 2 lines of output, 1 comment)
Ruby, pasted on Oct 25:
1
2
3
4
5
# 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)
C, pasted on Oct 23:
1
2
3
4
5
//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)
C, pasted on Oct 22:
1
2
3
4
5
#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)
C, pasted on Oct 21:
1
2
3
4
5
#include<stdio.h>

#define STR_SIZE 50

typedef struct
...
view (38 lines, 40 lines of output, 1 comment)
Ruby, pasted on Oct 21:
1
2
3
4
5
puts "VERSION = #{VERSION}"

output = ['five','four','three','two','one','zero']
puts "Input Converted to:"
output=output.reverse
...
view (15 lines, 15 lines of output)
Ruby, pasted on Oct 21:
1
2
3
4
5
puts "VERSION = #{VERSION}"

my_array = [1,2,3,4]

puts "\nputs my_array"
...
view (18 lines, 19 lines of output)
Ruby, pasted on Oct 21:
1
2
3
4
5
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)
Ruby, pasted on Oct 21:
1
2
3
4
my_array = [1,2,3,4]

puts "\nputs my_array"
puts my_array
...
view (16 lines, 18 lines of output)
Ruby, pasted on Oct 18:
1
2
3
4
5
puts "VERSION = #{VERSION}"


class RPS
  
...
view (40 lines, 10 lines of output)