Skip to content

Instantly share code, notes, and snippets.

@AJFaraday
AJFaraday / gist:1139297
Created August 11, 2011 09:52
New rails error
>> rake db:migrate
WARNING: Global access to Rake DSL methods is deprecated. Please include
... Rake::DSL into classes and modules which use the Rake DSL methods.
WARNING: DSL method ResolutionTracker::Application#task called at /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/application.rb:215:in `initialize_tasks'
@AJFaraday
AJFaraday / gist:1992470
Created March 7, 2012 10:42
Ascii screensaver (draft 1)
a = []
bool = true
loop do
puts a.to_s
bool ? a.concat(['a']) : a.delete_at(0)
sleep 0.1
if rand > 0.95
bool ? bool = false : bool = true
end
end
@AJFaraday
AJFaraday / gist:2226880
Created March 28, 2012 14:59
Why RPM is working my last nerve
[root@localhost rpm]# rpm -i RPMS/noarch/41_docs-0.noarch.rpm
package 41_docs-0.noarch.rpm is already installed
[root@localhost rpm]# rpm -e RPMS/noarch/41_docs-0.noarch.rpm
package RPMS/noarch/41_docs-0.noarch.rpm is not installed
@AJFaraday
AJFaraday / gist:2377670
Created April 13, 2012 15:25
rake overflow mystery
$ rake db:migrate --trace
(in /home/andrew/BioRails-Enterprise)
(in /home/andrew/BioRails-Enterprise)
(in /home/andrew/BioRails-Enterprise)
(in /home/andrew/BioRails-Enterprise)
(in /home/andrew/BioRails-Enterprise)
(in /home/andrew/BioRails-Enterprise)
(in /home/andrew/BioRails-Enterprise)
(in /home/andrew/BioRails-Enterprise)
(in /home/andrew/BioRails-Enterprise)
@AJFaraday
AJFaraday / data_element.rb
Created April 25, 2012 14:37
magic method fail
named_scope :searchable, :conditions => ['parent_id is null'], :order => 'lower(name) ASC'
def self.magic
self.with_scope(:searchable) do
puts count
end
puts count
end
def scoped_model
if scope_name
self.model.send(scope_name)
else
self.model
end
end
def descendant_leaves
result = []
result << children
until result.flatten!.all?{|x| x.leaf?}
result.each do |location|
unless location.leaf?
result << location.children
result.delete(location)
end
end
require 'rubygems'
require 'tweetstream'
TWITTER_USERNAME = 'XXXXX'
TWITTER_PASSWORD = 'XXXXX'
TweetStream::Client.new({:username => TWITTER_USERNAME, :password => TWITTER_PASSWORD}).sample do |status|
puts "[#{status.user.screen_name}] #{status.text}"
end
require 'rubygems'
require 'tweetstream'
TWITTER_USERNAME = 'XXXXXXX'
TWITTER_PASSWORD = 'XXXXXXXX'
ts = TweetStream.configure do |config|
config.username = 'XXXXXX'
def test_search_json
post :search, :option => 'all', :text => 'task', :format => :json
assert_response :success
json = JSON.parse(@respnose.body)
assert_equal 'task', json['text']
assert_equal 1, json['hit_list'].count
end