Skip to content

Instantly share code, notes, and snippets.

[GEMS]/activesupport-2.2.2/lib/active_support/json/encoding.rb:28:raise_on_circular_reference
[GEMS]/activesupport-2.2.2/lib/active_support/json/encoding.rb:20:encode
[GEMS]/activesupport-2.2.2/lib/active_support/json/encoders/hash.rb:42:to_json
[GEMS]/activesupport-2.2.2/lib/active_support/json/encoders/hash.rb:41:map
[GEMS]/activesupport-2.2.2/lib/active_support/json/encoders/hash.rb:41:to_json
[GEMS]/activesupport-2.2.2/lib/active_support/core_ext/object/misc.rb:39:returning
[GEMS]/activesupport-2.2.2/lib/active_support/json/encoders/hash.rb:40:to_json
[GEMS]/activesupport-2.2.2/lib/active_support/json/encoding.rb:21:send
[GEMS]/activesupport-2.2.2/lib/active_support/json/encoding.rb:21:encode
[GEMS]/activesupport-2.2.2/lib/active_support/json/encoding.rb:31:raise_on_circular_reference
class Float
def to_percent
(self*100).to_s.gsub(/(.\.)(\d\d).*/,'\1\2')
end
end
$stdout.sync = true
def spinner(i)
return(['\\','|','/','-'][i%4])
end
# Lo-fi client for the Facebook API. E.g.:
#
# fb = FacebookClient.new(:api_key => 'api-key', :secret => 'secret')
# fb.call 'users.getInfo', :session_key => 'session-key', :uids => 'user-id', :fields => 'birthday'
#
class FacebookClient
def initialize(default_params={})
@default_params = default_params.reverse_merge({
:rest_server => 'http://api.new.facebook.com/restserver.php',
:format => 'JSON',
# first arg is goal time in either seconds or ##:##
# second arg is distance in meters (optional)
# EXAMPLE ruby running_pace.rb 15:30 5000
class Float
def seconds_to_minutes
"#{self.to_i/60}:#{(self.to_f%60.0).rjust}"
end
def rjust
# oauth gem 0.3.5 send oob as the oauth_callback parameter which forces twitter into desktop mode
# this patches oauth gem to send a blank value instead
module OAuth
if defined?(OUT_OF_BAND)
self.send('remove_const','OUT_OF_BAND')
OUT_OF_BAND = ""
end
end
# To demo in irb:
# load 'spinner.rb' ; include Spinner ; spinner_demo
#
# To use, include this module in a class and then wrap something in with_spinner
# It has two params, both optional. See spinner_demo for usage examples.
module Spinner
def with_spinner total=nil, message="Working...", &blk
current=0
shown=buildstr(message,current,total)
@jotto
jotto / live_stats.rb
Created November 16, 2009 04:59
Drop this middleware into your app and get a nice graph of your last referrers
# ** how to call from rails app **
# put this file in the lib directory
# REQUIRES a central Cache store across all your webservers (i.e. mem_cache_store)
# paste the following inside the Rails initializer block in environment.rb
# config.middleware.use "LiveStats"
# create the following controller action
# def live
# html = Rails.cache.fetch("live_stats", :expires_in => 30.seconds) do
# ls = LiveStats.new
# ls.chart+"<br />"+ls.referrer_chart+"<br />"+"<pre>"+ls.referrer_histogram.to_yaml+"</pre>"
<IfModule mpm_prefork_module>
StartServers 10
MinSpareServers 10
MaxSpareServers 80
MaxClients 230
MaxRequestsPerChild 3000
</IfModule>
class SomeJob
def perform
do_some_stuff
Delayed::Job.enqueue(SomeJob.new, 0, 1.minute.from_now)
end
# you'd obviously have more settings somewhere
set :scm, :git
set :repository, "git@github.com:defunkt/github.git"
set :branch, "origin/master"
set :migrate_target, :current
set(:latest_release) { fetch(:current_path) }
set(:release_path) { fetch(:current_path) }
set(:current_release) { fetch(:current_path) }