Skip to content

Instantly share code, notes, and snippets.

@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')
#testing the speed of creating a new object via the association with mongoid
c = Club.first
####### 43 seconds #######
begin
500.times do |i|
c.people.create(:name => 'Jim')
end
end
#two questions -- why does .count not return the narrowed down result set size, and why does .where seem to alter variable a?
a = Star.where(:brightness => 0)
=> #<Mongoid::Criteria:0xb6af2948 @documents=[], @options={}, @selector={:brightness=>0}, @klass=Star>
a.size
=> 1430
a.count
=> 1430
@jraines
jraines / gitworkflow.md
Created April 26, 2011 18:00
Git workflow

Before starting work on a feature, check out a topic branch

git checkout -b topic

If the branch is already in progress and already exists on the remote repo, check it out as a tracking branch

git checkout --track -b topic origin/topic

Push the branch to your remote repo so others can work on it