Skip to content

Instantly share code, notes, and snippets.

namespace :db do
task :load_config => :rails_env do
require 'active_record'
ActiveRecord::Base.configurations = Rails::Configuration.new.database_configuration
end
desc "Create Sample Data for the application"
task(:truncate => :load_config) do
begin
config = ActiveRecord::Base.configurations[RAILS_ENV]
require 'rubygems'
require 'sequel'
require 'fileutils'
require 'yaml'
# NOTE: This converter requires Sequel and the MySQL gems.
# The MySQL gem can be difficult to install on OS X. Once you have MySQL
# installed, running the following commands should work:
# $ sudo gem install sequel
# $ sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
#!/bin/sh
export PATH=/bin:/usr/bin:/sbin:/usr/sbin
usage=$(
cat <<EOF
$0 [OPTIONS] start/stop
-s set speed default 256Kbit/s
-p set port default 3000
-d set delay default 350ms
def l(filename)
if rails?(2)
load RAILS_ROOT + '/tmp/' + "#{filename}.rb"
else
load Rails.root.join("tmp/#{filename}.rb")
end
end
# activerecord logging methods
# very useful for digging into
# queries
require 'logger'
require 'activerecord' if rails?(2)
require 'hirb'
Hirb.enable
def enable_logger
require 'rubygems'
require 'wirble'
require 'thread'
Wirble.init
def rails?(*args)
version=args.first
v2 = ($0 == 'irb' && ENV['RAILS_ENV'])
@j-manu
j-manu / app.rb
Created November 30, 2011 21:38 — forked from cpatni/app.rb
unique calculation using redis
require 'sinatra'
require 'redis'
require 'json'
require 'date'
class String
def &(str)
result = ''
result.force_encoding("BINARY")
doc = Nokogiri::HTML(doc,nil,'UTF-8')
doc.search('script').remove
doc.search('meta').remove
doc.search('style').remove
doc.search('link').remove
doc.search('base').remove
doc.search('iframe').remove
doc.search('embed').remove
doc.search('object').remove
doc.css("a.blippr-inline-smiley").remove
@j-manu
j-manu / workers.rake
Created December 4, 2011 07:09 — forked from karmi/workers.rake
Rake taks to launch multiple Resque workers in development/production with simple management included
# Rake task to launch multiple Resque workers in development/production with simple management included
require 'resque/tasks' # Require Resque tasks
namespace :workers do
# = $ rake workers:start
#
# Launch multiple Resque workers with the Rails environment loaded,
# so they have access to your models, etc.
@j-manu
j-manu / fixes.md
Created December 4, 2011 16:30 — forked from thbar/fixes.md
Getting rid of nokogiri segfaults

This readme is a mixture of everything I read on SO+nokogiri wiki, which ultimately worked out for me.

Here are the steps which worked for me to get rid of segfaults with Nokogiri 1.4.4, on both Lion and Snow Leopard, with Ruby 1.8.7 (patchlevel 334 and +).

First diagnose which version of libxml2 you're using:

bundle exec nokogiri -v

If you have 2.7.3 listed somewhere, you're in bad waters (known to segfault). Install this: