Skip to content

Instantly share code, notes, and snippets.

@kuntoaji
kuntoaji / hashtag_counter.rb
Created September 21, 2010 07:15
Ruby script to count a twitter hashtag and save the result and last_tweet_id to hashtag_counter_result.txt and last_tweet_id.tx
#!/usr/bin/env ruby
# Twitter Hashtag Counter
#
# Script to count a twitter hashtag and save the result and last_tweet_id to
# hashtag_counter_result.txt and last_tweet_id.txt
#
# Requirements: twitter gem.
# To install twitter gem: [sudo] gem install twitter
require 'rubygems'
@geoffb
geoffb / impact_suspend.js
Created January 12, 2011 00:44
ImpactJS: Suspend/Resume on blur/focus
window.addEventListener("blur", function () {
if (ig.system) {
ig.music.stop();
ig.system.stopRunLoop();
}
}, false);
window.addEventListener("focus", function () {
if (ig.system) {
ig.music.play();
@mikegehard
mikegehard / Setting longer HTTP timeout in capybara
Created April 15, 2011 19:20
Setting longer HTTP timeout in capybara
# We need this to fix the random timeout error that we were seeing in CI.
# May be related to: http://code.google.com/p/selenium/issues/detail?id=1439
Capybara.register_driver :selenium_with_long_timeout do |app|
client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 120
Capybara::Driver::Selenium.new(app, :browser => :firefox, :http_client => client)
end
Capybara.javascript_driver = :selenium_with_long_timeout
@Marchino
Marchino / I18n_routing_common.rb
Created May 3, 2011 22:23
How I made I18n_routing working with Devise. Couldn't translate routing scopes in any way, so I added a little workaround to the gem and...
# I18n_routing/lib/I18n_routing_common.rb
# Return the correct translation for given values
def self.translation_for(name, type = :resources, option = nil)
# First, if an option is given, try to get the translation in the routes scope
if option
default = "{option}Noi18nRoutingTranslation"
t = I18n.t(option, :scope => "routes.#{name}.#{type}", :default => default)
return (t == default ? nil : t)
else
@hoverlover
hoverlover / active_admin_heroku.rb
Created June 7, 2011 16:35
Rails initializer for using ActiveAdmin with Sass on Heroku
if Rails.env.production?
require 'fileutils'
FileUtils.mkdir_p(Rails.root.join("tmp", "stylesheets", "admin"))
template_path_one = "#{Gem.loaded_specs['activeadmin'].full_gem_path}/app/assets/stylesheets"
template_path_two = "#{Gem.loaded_specs['activeadmin'].full_gem_path}/lib/active_admin/sass"
old_compile_path = "#{Rails.root}/public/stylesheets/admin"
new_compile_path = "#{Rails.root}/tmp/stylesheets/admin"
Sass::Plugin::remove_template_location template_path_one
@dhh
dhh / gist:1014971
Created June 8, 2011 18:09
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
@defunkt
defunkt / gitio
Created September 11, 2011 08:11
Turn a github.com URL into a git.io URL.
#!/usr/bin/env ruby
# Usage: gitio URL [CODE]
#
# Turns a github.com URL
# into a git.io URL
#
# Copies the git.io URL to your clipboard.
url = ARGV[0]
code = ARGV[1]
@rorcraft
rorcraft / Base File.sublime-settings
Last active September 27, 2015 18:38 — forked from jaredatron/Base File.sublime-settings
Default (OSX).sublime-keymap
{
"color_scheme": "Packages/Color Scheme - Default/Sunburst.tmTheme",
"detect_indentation": false,
"ensure_newline_at_eof_on_save": true,
"font_face": "Menlo",
"font_size": 11.0,
"ignored_packages":
[
"Vintage"
],
@moklett
moklett / address_spec.rb
Created March 8, 2012 02:33
Toying around with an RSpec DSL for permutations. My real use case is more complex than this example - the large numbers of inputs and outputs makes it more concise to "demonstrate" correctness and expectations than to "spec" it out with traditional, one
describe Address do
permute "validations" do
cases [
[:address, :address_2, :city, :state, :zip, :country, :valid, :errors_on],
[ nil, nil, nil, nil, nil, nil, false, ['address', 'city', 'state', 'zip', 'country']],
['123 Main St', 'Apt 100', 'Pleasantville', 'NC', '12345', 'US', true, []],
['123 Main St' 'Apt 100', 'Pleasantville' 'NC' '12345' nil, false ['country']]
['123 Main St' 'Apt 100', 'Pleasantville' 'NC' '12345' 'U', false ['country']]
['123 Main St' 'Apt 100', 'Pleasantville' 'NC' '12345' 'USA', false ['country']]
]
@Bodacious
Bodacious / Explanation.md
Created May 11, 2012 08:53
RubyMotion method name explanation...

RubyMotion comes with some syntax idioms that are not strictly idiomatic Ruby.

For example, in an iOS app we'd often see these two methods defined in a subclass of UITableViewController

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
      // callback code for selecting table rows goes here...