Skip to content

Instantly share code, notes, and snippets.

View komagata's full-sized avatar

Masaki Komagata komagata

View GitHub Profile
@apeckham
apeckham / capybara_helper.rb
Created April 7, 2010 17:41
capybara + rails + selenium + test::unit + jammit
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
require 'capybara/rails'
Jammit.load_configuration(Jammit::DEFAULT_CONFIG_PATH)
Jammit.packager.force = true
Jammit.packager.precache_all
class CapybaraTest < ActionController::IntegrationTest
fixtures :all
@vvalgis
vvalgis / Capistrano tasks for starting unicorn.rb
Created May 7, 2010 08:13
Capistrano tasks for starting unicorn
set :rails_env, :production
set :unicorn_binary, "/usr/bin/unicorn"
set :unicorn_config, "#{current_path}/config/unicorn.rb"
set :unicorn_pid, "#{current_path}/tmp/pids/unicorn.pid"
namespace :deploy do
task :start, :roles => :app, :except => { :no_release => true } do
run "cd #{current_path} && #{try_sudo} #{unicorn_binary} -c #{unicorn_config} -E #{rails_env} -D"
end
task :stop, :roles => :app, :except => { :no_release => true } do
// ==UserScript==
// @name AutoMujiSort
// @namespace http://www.milk1000.cc/
// @include http://www.muji.net/store/cmdty/section/*
// ==/UserScript==
(function() {
var OLD_PATTERN = { sort: 4, count: 12 };
var NEW_PATTERN = { sort: 0, count: 150 };
# In your test_helper.rb
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || retrieve_connection
end
end
#!ruby
# -*- coding: utf-8 -*-
require 'open-uri'
puts open('http://holiday.fjord.jp/').read.match(%r!<div class="next-holiday">\s*?(\d+月\d+日)\s*?<span>(.*?)</span>!)[1,2].join(' ')
@mathiasbynens
mathiasbynens / appify
Created November 12, 2010 13:46 — forked from subtleGradient/appify
appify — create the simplest possible Mac app from a shell script
#!/bin/bash
if [ "$1" = "-h" -o "$1" = "--help" -o -z "$1" ]; then cat <<EOF
appify v3.0.1 for Mac OS X - http://mths.be/appify
Creates the simplest possible Mac app from a shell script.
Appify takes a shell script as its first argument:
`basename "$0"` my-script.sh
@juno
juno / heroku-api-client-example.rb
Created December 2, 2010 06:09
Example implement for heroku info APP_NAME. Requires rest-client and nokogiri.
require 'rest_client'
require 'nokogiri'
resource = RestClient::Resource.new('https://api.heroku.com', 'USERNAME', 'PASSWORD')
args = [:get, nil, {
'X-Heroku-API-Version' => '2',
'User-Agent' => 'my heroku client/1.0',
'X-Ruby-Version' => RUBY_VERSION,
'X-Ruby-Platform' => RUBY_PLATFORM
}].compact
@mataki
mataki / heroku_autoscalling.rb
Created December 2, 2010 06:33
Auto scalling dynos on heroku using NewRelic
=begin
Need to install gems heroku, newrelic_rpm
$ gem install heroku newrelic_rpm
Set your apps setting
app_name : heroku's app_name of auto scaling
license_key : NewRelic api key. You can get heroku's NewRelic admin console. "App setting" and "Agent configuration"
execute with cron every minutes
$ ruby ./adjust_dynos_with_newrelic.rb
@fnichol
fnichol / README.md
Created March 12, 2011 20:52
Download a cacert.pem for RailsInstaller

Why?

There is a long standing issue in Ruby where the net/http library by default does not check the validity of an SSL certificate during a TLS handshake. Rather than deal with the underlying problem (a missing certificate authority, a self-signed certificate, etc.) one tends to see bad hacks everywhere. This can lead to problems down the road.

From what I can see the OpenSSL library that Rails Installer delivers has no certificate authorities defined. So, let's go fetch some from the curl website. And since this is for ruby, why don't we download and install the file with a ruby script?

Installation

The Ruby Way! (Fun)

@mattwynne
mattwynne / gist:1228927
Created September 20, 2011 11:52
eventually helper method for making assertions against asynchronous systems
# usage:
# it "should return a result of 5" do
# eventually { long_running_thing.result.should eq(5) }
# end
module AsyncHelper
def eventually(:options = {})
timeout = options[:timeout] || 2
interval = options[:interval] || 0.1
time_limit = Time.now + timeout
loop do