Skip to content

Instantly share code, notes, and snippets.

require 'rubygems'
require 'eventmachine'
class Handler
include EventMachine::Deferrable
def takes_long_time(seconds = 5)
sleep(seconds)
puts "Awoke after #{seconds} seconds."
succeed(seconds)
@mrrooijen
mrrooijen / Capistrano-Deployment-Recipe.rb
Created July 29, 2009 09:34
a "base" Capistrano Rails Deployment Recipe. Use it to deploy your Rails application. It is also easily expandable. So feel free to grab this Recipe and add your own tasks/customization!
# Guide
# Configure the essential configurations below and do the following:
#
# Repository Creation:
# cap deploy:repository:create
# git add .
# git commit -am "initial commit"
# git push origin master
#
# Initial Deployment:
var fs = require('fs'),
sys = require('sys'),
http = require('http');
http.createServer(function (req, res) {
checkBalanceFile(req, res);
}).listen(8000);
function checkBalanceFile(req, res) {
fs.stat("balance", function(err) {
@rud
rud / watchr-runner.rb
Created February 8, 2010 14:17
watchr for rspec
if __FILE__ == $0
puts "Run with: watchr #{__FILE__}. \n\nRequired gems: watchr rev"
exit 1
end
# --------------------------------------------------
# Convenience Methods
# --------------------------------------------------
def run(cmd)
puts(cmd)
@solnic
solnic / mysql_and_mongodb_example.rb
Created March 3, 2010 11:11
This code uses dm-core from snusnu's active_support branch and dm-mongo-adapter from master
require 'rubygems'
require 'dm-core'
DataMapper.setup(:default, "mysql://localhost/examples")
DataMapper.setup(:logs, "mongo://localhost/examples")
class LoggedEvent
include DataMapper::Mongo::Resource
def self.default_repository_name; :logs; end
class LoggedEvent
include DataMapper::Mongo::Resource
property :id, ObjectID
property :type, Discriminator
property :message, String
property :custom_attributes, Hash
property :created_at, DateTime
end
@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@toland
toland / blowfish.rb
Created July 13, 2010 16:47
Simple Ruby module for encrypting text with Blowfish
require 'openssl'
module Blowfish
def self.cipher(mode, key, data)
cipher = OpenSSL::Cipher::Cipher.new('bf-cbc').send(mode)
cipher.key = Digest::SHA256.digest(key)
cipher.update(data) << cipher.final
end
def self.encrypt(key, data)
@luciferous
luciferous / README
Created September 6, 2010 22:55
Sudoku solver in Ruby
A very simple Sudoku puzzle solver written in Ruby. This script is free every
way you look at it.
## Example usage
$ cat puzzle
15 2
7 8459
8 4795 6
5 6
@putermancer
putermancer / gist:591964
Created September 22, 2010 16:01
Set up a local solr instance on mac
# Setting up a local solr instance on a mac
# install solr with homebrew
brew install solr
# create the base solr index directory
mkdir -p /data/solr
# make sure you can write to the solr logs
sudo chown -R `whoami` /usr/local/Cellar/solr/