Skip to content

Instantly share code, notes, and snippets.

@cyx
cyx / gist:12614
Created September 24, 2008 17:20
class AddProjectIdToVotes < ActiveRecord::Migration
def self.up
# add_column :votes, :project_id, :integer
DbCluster.each do |c|
puts "Executing in #{c.connection_name}"
Line::Version.find(:all).each do |line_version|
Vote.find(:all, :conditions => { :voteable_type => 'Line::Version', :voteable_id => line_version.id }).each do |vote|
if line_version.project_id
@cyx
cyx / gist:13747
Created September 30, 2008 05:26
!= check_box_tag 'hoy', 'hoy2', false, :class => 'rtoggler', :title => '#testing'
#testing.hide
Testing
class BlackHoleStore
def logger
Rails.logger
end
def fetch( *args )
yield
end
def read( *args )
/usr/local/lib/ruby/gems/1.9.1/gems/rufus-tokyo-0.1.12/lib/rufus/tokyo/cabinet/table.rb:606: [BUG] Segmentation fault
ruby 1.9.1p0 (2009-01-30 revision 21907) [x86_64-linux]
-- control frame ----------
c:0047 p:---- s:0150 b:0150 l:000149 d:000149 CFUNC :tclistnum
c:0046 p:0019 s:0146 b:0146 l:000145 d:000145 METHOD /usr/local/lib/ruby/gems/1.9.1/gems/rufus-tokyo-0.1.12/lib/rufus/tokyo/cabinet/table.rb:606
c:0045 p:0015 s:0143 b:0142 l:000141 d:000141 METHOD /usr/local/lib/ruby/gems/1.9.1/gems/rufus-tokyo-0.1.12/lib/rufus/tokyo/cabinet/table.rb:615
c:0044 p:---- s:0139 b:0139 l:000138 d:000138 FINISH
c:0043 p:---- s:0137 b:0137 l:000136 d:000136 CFUNC :collect
c:0042 p:0011 s:0134 b:0134 l:000133 d:000133 METHOD /usr/local/lib/ruby/gems/1.9.1/gems/rufus-tokyo-0.1.12/lib/rufus/tokyo/cabinet/table.rb:631
class HomeController < ApplicationController
def index
if (@target_url = params["url"]) && !@target_url.blank?
@target_url = @target_url =~ %r{^http://} ? @target_url : "http://#{@target_url}"
filter_if_length_less_than = 40
@page = open(@target_url).read
doc = Nokogiri::HTML.parse(@page)
content = doc.search("h1,p,.comment")
content = content.reject { |node| node.text.gsub(/\W/,'').strip.length < filter_if_length_less_than }
content = content.reject { |node| (%w[noscript li] & node.ancestors.map { |e| e.name }).length > 0 }
@cyx
cyx / gist:219813
Created October 27, 2009 18:46 — forked from tpitale/gist:162954
#! /bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/mongodb/bin
DAEMON=/opt/mongodb/bin/mongod
PIDFILE=/var/log/mongodb/mongodb.pid
LOGFILE=/var/log/mongodb/mongod.log
NAME=mongodb
DESC=mongodb
test -x $DAEMON || exit 0
module Suggestions
def self.included( base )
base.extend ClassMethods
end
module ClassMethods
# USAGE:
#
# class Doctor
# # this model should have the typical Sunspot.setup clause somewhere else
class User
module DeprecatedPasswordCheck
def valid_password?( attempted_password, check_against_database = check_passwords_against_database? )
if valid_legacy_password?( attempted_password )
return true
else
super
end
end
require 'rubygems'
require 'action_controller'
require 'action_controller/test_process'
def upload( path, mime )
ActionController::TestUploadedFile.new( path, mime )
end
event = Event.find(100)
require 'open-uri'
require 'tempfile'
class Downloadable
# The filename, *not* including the path, of the "uploaded" file
attr_reader :original_filename
# The content type of the "uploaded" file
attr_accessor :content_type