Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
JoshCheek / data.txt
Created August 28, 2010 19:57
show erb example from docs with files
From: James Edward Gray II <james@grayproductions.net>
To: <%= to %>
Subject: Addressing Needs
<%= to[/\w+/] %>:
Just wanted to send a quick note assuring that your needs are being
addressed.
I want you to know that my team will keep working on the issues,
# my submission for http://rubylearning.com/blog/2010/07/31/rpcfn-cycle-tracks-12/
#
# update: I hadn't realized it, but this challenge actually ended today.
# Mine was very similar to the guy who won, which you can see at http://gist.github.com/502083
# (though he included a very nice 1.9 only solution)
def skip_tracks( ary , i )
i %= ary.size
ary.replace ary[i..-1]+ary[0...i]
end
@JoshCheek
JoshCheek / software-engineering-in-class-project.rb
Created September 9, 2010 10:46
in class program done in a group to practice software engineering
# http://gist.github.com/571709
# Okay, after class, I cleaned it up just a small amount, and added bigdecimal
# Other than that, this was written in class by team Riskies, if you can't tell, our team was pretty much the best.
require 'rubygems'
require 'sinatra'
require 'bigdecimal' # use big decimals, because IEEE floats are imprecise, and we are working with money
class String
def to_bd
@JoshCheek
JoshCheek / int8_t-and-uint8_t.c
Created October 2, 2010 08:27
use uint8_t for byte, rather than unsigned char
#include <stdint.h>
#include <stdio.h>
int main()
{
int i;
// signed
printf("int8_t, bytes: %ld, signed: true\n",sizeof(int8_t));
for( i = -64*4 ; i < -64*3 ; ++i ) {
<!-- It is probably easier to read if you initialize item_images to be an empty hash -->
<% @item.item_images ||= Hash.new %>
<% @item.item_images.each do |key, image| %>
<img src="<%= image.path %>" width="397" <% if key != 0 %>style="display:none"<% end %> />
<% end %>
<!-- Or return a default value for when it is nil -->
<% (@item.item_images || Hash.new).each do |key, image| %>
<img src="<%= image.path %>" width="397" <% if key != 0 %>style="display:none"<% end %> />
@JoshCheek
JoshCheek / analysis.rb
Created October 25, 2010 08:24
analyze correlation between homicide and atheism
#!/usr/bin/env ruby -Ku
# take countries by atheism http://en.wikipedia.org/wiki/Demographics_of_atheism
# compare to countries by homicide rate http://en.wikipedia.org/wiki/List_of_countries_by_intentional_homicide_rate
# calculations and analysis down below
countries = {
"Sweden"=>{:atheism=>85, :crime=>1.17},
"Denmark"=>{:atheism=>80, :crime=>1.11},
@JoshCheek
JoshCheek / gist:656788
Created October 31, 2010 16:24
iteration benchmarks
$ for ver in `rvm list strings` ; do rvm use $ver ; ruby bm.rb ; echo ; echo ; done
Using /Users/josh/.rvm/gems/jruby-1.5.2
user system total real
for loop 1.435000 0.000000 1.435000 ( 1.435000)
while loop 1.034000 0.000000 1.034000 ( 1.034000)
times loop 1.126000 0.000000 1.126000 ( 1.126000)
Using /Users/josh/.rvm/gems/jruby-1.5.3
user system total real
@JoshCheek
JoshCheek / watir-example.rb
Created November 3, 2010 22:20
lightning talk idea
# fx must be started as follows
# /Applications/Firefox.app/Contents/MacOS/firefox-bin -jssh
# watir example
require 'firewatir'
fx = FireWatir::Firefox.new
fx.goto 'pastie.org'
text = fx.text_field :id , 'paste_body'
text.set "hello, world!"
@JoshCheek
JoshCheek / ideas.textile
Created November 8, 2010 19:21
Next Lightning Talk ideas

http://tinyurl.com/josh-lightning-talks

  • Present trip to RDRC
  • How to contribute to F/OSS
  • Ruby method overloading
  • Chem timer
  • Land of Lisp book review
  • Metaprogramming Ruby book review
  • Cucumber Watir example
@JoshCheek
JoshCheek / method.c
Created November 11, 2010 15:53
Illustrates how I think of Ruby's methods
#include <stdio.h>
#include <string.h>
typedef struct {
char* name;
int (*pointer)( int arg );
} Method;
typedef struct {
Method* methods;