Skip to content

Instantly share code, notes, and snippets.

class Elevator
def initialize(floor)
@floor = floor
end
attr_accessor :floor
def greet
for i in 0..floor
if i == 0
puts "Basement."
@jraines
jraines / gist:567e1da3645725664288
Created July 15, 2015 19:46
Top 10 Ruby Enumerable methods
@jraines
jraines / gist:67462aa9419d9b55db27
Last active August 29, 2015 14:27
combinations_problem
You have a set A of n integers.
For every i ∈ A,
i may or may not also belong to a replacement set B, which may be the empty set,
where any k ∈ B can replace i in the original set.
Each replacement set B can be of any size.
Is there a way (especially an efficient way) to generate
all combinations of size n (call it A') where:
@jraines
jraines / feedsummary.rb
Created January 11, 2009 04:31
Feed summarizer
# All code in this gist is public domain and freely available for use and alteration without attribution
require 'rubygems'
require 'simple-rss'
require 'rss'
require 'open-uri'
feed = 'http://www.tweetlinkmonster.com/feed/jraines.atom'
rss = SimpleRSS.parse(open(feed))
@jraines
jraines / gist:68567
Created February 22, 2009 18:53
Basic ferret example
require 'rubygems'
require 'ferret'
# Create the full-text search index
jobs = Job.find(:all, :conditions => ["displayed = 'yes'"])
index = Index::Index.new(:path => 'search_index', :create => true)
jobs.each do |job|
index << {:id => job.id, :description => job.description}
:javascript
// wait for the DOM to be loaded
$(document).ready(function() {
var options = {
target: '#output'
};
// bind 'myForm' and provide a simple callback function
$('#myForm').ajaxForm(options);
});
//embed code for a YouTube JSAPI player
swfobject.embedSWF("#{@videos.first.url}&enablejsapi=1&playerapiid=ytplayer", "ytapiplayer", "320", "265", "8", null, null, params, atts);
## Explanatory screencast: http://www.youtube.com/jraines002#p/u/0/Vj5LjE4kuLM
<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs title="My Gadget" height="30">
<Require feature="wave" />
<Require feature="locked-domain" />
<Require feature="dynamic-height" />
</ModulePrefs>
<Content type="html">
#class User
has_many :workouts, :through => :checkins
has_many :coached_workouts, :class_name = "Workout", :foreign_key => "coach_id"
#class Workout
belongs_to :coach, class_name = "User"
#add coach_id column to workout table
-unless current_user.workouts.member?(workout)
=link_to image_tag('checkin.png'), checkin_url(:workout_id => workout.id, :user_id => current_user.id)
-else
=image_tag('done.png')