Skip to content

Instantly share code, notes, and snippets.

View dstrelau's full-sized avatar

Dean Strelau dstrelau

View GitHub Profile
Rails::Initializer.run do |config|
# Read from config/memcached.yml to setup Memcache instance
# Individual caching mechanisms are enabled in environment specific configs
require 'memcache'
mservers = if (File.exist?(mconfig = Rails.root+'config'+'memcached.yml'))
YAML.load_file(mconfig)[RAILS_ENV].delete('servers')
end
MemCacheConnection = MemCache.new(mservers || 'localhost:11211', :namespace => "_myapp")
end
@dstrelau
dstrelau / tnt.rb
Created December 21, 2009 15:19 — forked from rodreegez/tnt.rb
#!/usr/bin/env ruby
require 'rubygems'
require 'thor'
require 'twitter'
class TNT < Thor
map "MESSAGE" => :post
desc "post \"message\"", "Post a message to Twitter"
Bluepill.define_process_condition(:running_time) do
def initialize(options = {})
@below = options[:below]
end
def run(pid)
started = `ps -p #{pid} -o command`.match(/since (\d+)/)[1].to_i
Time.now - Time.at(started)
rescue
0
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
})();
namespace :deploy do
namespace :crontab do
def update_cmd_for(role)
load_file = "config/whenever/#{fetch(:environment)}.#{role}.rb"
[ "cd #{fetch(:current_path)} &&",
"if [ -f #{load_file} ] ; then",
"bin/whenever",
"--update-crontab #{fetch(:application)}.#{fetch(:environment)}.#{role}",
"--load-file #{load_file}",
mysql> EXPLAIN SELECT count(DISTINCT `competition_entries`.id) AS count_all FROM `competition_entries` LEFT OUTER JOIN `videos` ON `videos`.attachable_id = `competition_entries`.id AND `videos`.attachable_type = 'CompetitionEntry' LEFT OUTER JOIN `moderations` ON `moderations`.moderated_id = `competition_entries`.id AND `moderations`.moderated_type = 'CompetitionEntry' LEFT OUTER JOIN `users` ON `users`.id = `competition_entries`.user_id INNER JOIN `images` ON `images`.attachable_id = `competition_entries`.id AND `images`.attachable_type = 'CompetitionEntry' WHERE (moderations.state = 0) ;
+----+-------------+---------------------+--------+-----------------------------------------------------------------------+-----------------------------------+---------+--------------------------------------------------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref
I'm trying to run the chef::bootstrap_server recipe from the
HEAD of '09beta' branch of opscode/cookbooks and seeing
weirdness with attribute lookup.
chef v0.9.0.b02 via `chef-solo -j dna.json -c solo.rb`
# chef-client - Chef Configuration Management Client
#
# Chef Client provides the Chef configuration management daemon
description "Chef Client"
start on filesystem
stop on runlevel S
respawn
@dstrelau
dstrelau / attributes.rb
Created June 25, 2010 21:30
chef-client -c client.rb -j dna.json
# see http://github.com/opscode/cookbooks/blob/master/chef/attributes/default.rb
@dstrelau
dstrelau / gist:474940
Created July 14, 2010 02:40
split multi-page PDFs into multiple files (OS X)
#!/usr/bin/python
"""
Splits an input pdf file into many files, one per page
"""
import sys
import os
from CoreGraphics import *