Skip to content

Instantly share code, notes, and snippets.

@defunkt
defunkt / connection_fix.rb
Created November 19, 2009 20:00
MySQL server has gone away fix
# If your workers are inactive for a long period of time, they'll lose
# their MySQL connection.
#
# This hack ensures we re-connect whenever a connection is
# lost. Because, really. why not?
#
# Stick this in RAILS_ROOT/config/initializers/connection_fix.rb (or somewhere similar)
#
# From:
# http://coderrr.wordpress.com/2009/01/08/activerecord-threading-issues-and-resolutions/
@defunkt
defunkt / gemspec
Created March 9, 2010 01:41
Quickly create a gemspec.
#!/usr/bin/env ruby
# Usage: gemspec [-s] GEMNAME
#
# Prints a basic gemspec for GEMNAME based on your git-config info.
# If -s is passed, saves it as a GEMNAME.gemspec in the current
# directory. Otherwise prints to standard output.
#
# Once you check this gemspec into your project, releasing a new gem
# is dead simple:
#
@nruth
nruth / cookie_steps.rb
Created July 21, 2010 17:16
Testing login "remember me" feature with Capybara (rack::test or selenium) - deleting the session cookie (only)
class CucumberExternalResqueWorker
DEFAULT_STARTUP_TIMEOUT = 1.minute
COUNTER_KEY = "cucumber:counter"
class << self
attr_accessor :pid, :startup_timeout
def start
# Call from a Cucumber support file so it is run on startup
return unless Rails.env.cucumber?
@karmi
karmi / percolated-twitter.rb
Created June 14, 2011 18:17
Reversed or “Real Time” Search in ElasticSearch
# Reversed or “Real Time” Search in ElasticSearch
# ====================================================================================
# You may have come across the term “realtime search” lately
# (eg. [here](http://engineering.socialcast.com/2011/05/realtime-search-solr-vs-elasticsearch/))
# and wondered what all the fuss is about.
#
# Well, the usual workflow with search engines goes like this:
#
# 1. You index some documents.
@imarzi
imarzi / octopus.rb
Created June 30, 2011 20:01
octopus gist
require 'rubygems'
require 'goliath'
require 'em-synchrony'
require 'em-synchrony/em-http'
class Octopus < Goliath::API
use Goliath::Rack::Params
use Goliath::Rack::Heartbeat
use Goliath::Rack::Validation::RequestMethod, %w(GET POST HEAD)
@kijuky
kijuky / komachi.groovy
Created September 18, 2011 16:37
佐賀Groovy勉強会 - 演習1:小町算
import groovyx.gpars.GParsPool
GParsPool.withPool {
def array = ["+", "-", "*", "/"]
def combi = GroovyCollections.combinations((1..2).collectParallel{ array }) // arrayから2つ選びだす順列
println combi //=> [[1, 1], [2, 1], [3, 1], [1, 2], [2, 2], [3, 2], [1, 3], [2, 3], [3, 3]]
combi.each {
def s = "1"
def i = 2
@shangaslammi
shangaslammi / webspider.hs
Created October 4, 2011 08:25
Haskell Web Spider example
import Control.Exception
import Control.Monad
import Control.Monad.IO.Class
import Data.ByteString.Lazy (ByteString)
import Data.ByteString.Lazy.UTF8 (toString)
import Data.Function
import Data.Enumerator
import Data.List
import Data.Maybe
@forresty
forresty / video-list.txt
Created October 16, 2011 14:35
Stanford ML Class Video Links
http://s3.amazonaws.com/stanford_videos/cs229/videos/01.1-Introduction-Welcome.mp4
http://s3.amazonaws.com/stanford_videos/cs229/videos/01.b-Introduction-WhatIsMachineLearning.mp4
http://s3.amazonaws.com/stanford_videos/cs229/videos/01.3-Introduction-SupervisedLearning.mp4
http://s3.amazonaws.com/stanford_videos/cs229/videos/01.d-Introduction-UnsupervisedLearning.mp4
http://s3.amazonaws.com/stanford_videos/cs229/videos/02.1-LinearRegressionWithOneVariable-ModelRepresentation.mp4
http://s3.amazonaws.com/stanford_videos/cs229/videos/02.2-LinearRegressionWithOneVariable-CostFunction.mp4
http://s3.amazonaws.com/stanford_videos/cs229/videos/02.3-LinearRegressionWithOneVariable-CostFunctionIntuitionI.mp4
http://s3.amazonaws.com/stanford_videos/cs229/videos/02.4-LinearRegressionWithOneVariable-CostFunctionIntuitionII.mp4
http://s3.amazonaws.com/stanford_videos/cs229/videos/02.5-LinearRegressionWithOneVariable-GradientDescent.mp4
http://s3.amazonaws.com/stanford_videos/cs229/videos/02.6-LinearRegressionWithOneVariabl
@mynameisrufus
mynameisrufus / .gitignore
Created November 17, 2011 06:09
Double-forking Unix daemon
tmp
log
doc
daemon
*.swp