Skip to content

Instantly share code, notes, and snippets.

def run_pg_fouine():
info = host_info[env.host_string]
db_name = info.tags.get('Name')
sudo('perl -pi -e "s/log_min_duration_statement = .*/log_min_duration_statement = 0/" /etc/postgresql/9.*/main/postgresql.conf')
sudo('/etc/init.d/postgresql reload')
time.sleep(30)
sudo('perl -pi -e "s/log_min_duration_statement = .*/log_min_duration_statement = 500/" /etc/postgresql/9.*/main/postgresql.conf')
sudo('/etc/init.d/postgresql reload')
run('tail -n 100000 /var/log/postgresql/postgresql-9.*-main.log > /tmp/pgfouine.txt')
run('gzip -f /tmp/pgfouine.txt')
@cyx
cyx / hack.sh
Created March 31, 2012 12:30 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
#!/bin/sh
set -u
set -e
# Example init script, this can be used with nginx, too,
# since nginx and unicorn accept the same signals
# Feel free to change any of the following variables for your app:
APP_ROOT=/k/app_name/current
PID=/var/run/unicorn/unicorn.pid
ENV=production
@cyx
cyx / xhr.rb
Created October 30, 2011 08:28 — forked from lucasmazza/xhr.rb
Using xhr with rspec + rack/test
module XhrHelpers
def xhr(path, params = {})
verb = params.delete(:as) || :get
send(verb,path, params, "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest")
end
alias_method :ajax, :xhr
end
RSpec.configuration.include XhrHelpers, :type => :controller
@cyx
cyx / example.html
Created September 22, 2011 06:07 — forked from joelnet/example.html
Unobtrusive Knockout support library for jQuery
Choose a ticket class: <select id="tickets"></select>
<p id="ticketOutput"></p>
<script id="ticketTemplate" type="text/x-jquery-tmpl">
{{if chosenTicket}}
You have chosen <b>${ chosenTicket().name }</b>
($${ chosenTicket().price })
<button data-bind="click: resetTicket">Clear</button>
{{/if}}
@cyx
cyx / dbtasks.rb
Created August 25, 2011 15:02 — forked from tizoc/dbtasks.rb
desc "migrate", "Runs Sequel migrations"
def migrate(version=nil, database_url=DATABASE_URL)
require 'sequel'
Sequel.extension :migration
db = Sequel.connect(database_url, :test => true)
puts 'Running migrations...'
Sequel::Migrator.apply(db, 'db/migrate', version && version.to_i)
dump_schema
def mote(template, params = {})
variables = mote_process_variables(mote_cache, template, params)
mote_cache[template] ||= Mote.parse(template, self, variables)
mote_cache[template][params]
end
def mote_file(filename, params = {})
variables = mote_process_variables(mote_files, filename, params)
mote_files[filename] ||= Mote.parse(File.read(filename), self, variables)
mote_files[filename][params]
@cyx
cyx / tpl.rb
Created August 18, 2011 04:30 — forked from tizoc/tpl.rb
# -*- coding: utf-8 -*-
module Tpl
def self.new_proc(template, variables = [])
render_definition = "Proc.new do |__v, __o|\n __v ||= {}; __o ||= ''\n"
compile(template, variables, render_definition)
render_definition << "__o\nend"
eval(render_definition)
end
@cyx
cyx / zuc.rb
Created August 17, 2011 20:05 — forked from vangberg/zuc.rb
def path matcher
lambda {|req|
return unless match = req.env["PATH_INFO"].match(/^\/(#{matcher})(\/|$)/)
path = match.captures[0]
req.env["SCRIPT_NAME"] += "/#{path}"
req.env["PATH_INFO"] = "/#{match.post_match}"
}
end
def daemonize(name = File.basename($0), options = {})
pid_path = options[:pid_path] || File.expand_path("tmp/pids/#{name}.pid")
# If the pid file exists, check that the process is actually still running.
begin
if File.exists?(pid_path) && Process.kill(0, File.read(pid_path).to_i)
$stderr.puts "Already running."
exit 1
end
rescue Errno::ESRCH