Skip to content

Instantly share code, notes, and snippets.

Avatar

Chris Bielinski chrisb

View GitHub Profile
@chrisb
chrisb / delayed_job.rb
Created Apr 25, 2012
Log DJ ActiveRecord activity to a separate log file
View delayed_job.rb
Delayed::Worker.logger = ActiveSupport::BufferedLogger.new("log/#{Rails.env}_delayed_jobs.log", Rails.logger.level)
Delayed::Worker.logger.auto_flushing = 1
if caller.last =~ /.*\/script\/delayed_job:\d+$/
Rails.logger = Delayed::Worker.logger
ActiveRecord::Base.logger = Delayed::Worker.logger
end
View gist:2026670
<html>
<head>
<title>my title</title>
</head>
<body>
<script>
document.body.style.background = 'lightgreen';
document.write("<div style='font-family:Arial,sans-serif;font-size:14pt;font-weight:bold;'>Hello, world! Isn't life great?</div>");
</script>
<noscript>
View gist:1714454
require 'sinatra'
require 'rubygems'
require 'open-uri'
require 'nokogiri'
get '/' do
doc = Nokogiri::HTML(open("http://www.google.com"))
balls = []
doc.css('a').each do |node|
View gist:1299837
def current_language
# if a "lang" URL parameter is specified, force it
return params[:lang] if params[:lang].present?
# if the user is logged in, use their language preference stored in the DB
return current_user.language if logged_in?
# if the user has manually selected a language, return that
return cookies[:language_code] if cookies[:language_code]
View rapper.rb
class Rapper
attr_accessor :name
def initialize(n)
self.name = n
end
def rap(words)
puts "Yo yo yo, my name is #{self.name}"
puts words
end
end
@chrisb
chrisb / hash_extension.rb
Created Dec 14, 2010
Hash extension for safe access to possibly undefined elements
View hash_extension.rb
class Hash
def value_at(*keys)
begin
memo = self.dup
keys.each { |key| memo = memo[key] }
memo
rescue
nil
end
end