This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with recursive category_ancestors (id, parent_id, name) as ( | |
select id, parent_id, name | |
from categories where id = 123 | |
union | |
select parent.id, parent.parent_id, parent.name | |
from categories parent | |
inner join category_ancestors on parent.id = category_ancestors.parent_id | |
) | |
select * from category_ancestors; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"bold_folder_labels": true, | |
"color_scheme": "Packages/Color Scheme - Default/Github.tmTheme", | |
"font_size": 13.0, | |
"highlight_line": true, | |
"highlight_modified_tabs": true, | |
"line_padding_bottom": 1, | |
"line_padding_top": 1, | |
"scroll_past_end": true, | |
"show_full_path": true, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'pg' | |
require 'eventmachine' | |
module Subscriber | |
def initialize(pg) | |
@pg = pg | |
end | |
def notify_readable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db_config = config.database_configuration[Rails.env] | |
scheme = db_config['adapter'] | |
userinfo = [db_config['username'], db_config['password']].compact.join(':') | |
host = db_config['host'] || 'localhost' | |
port = db_config['port'] || 5432 | |
database = db_config['database'] | |
ENV['QC_DATABASE_URL'] = ENV['DATABASE_URL'] = URI::Generic.new(scheme, userinfo, host, port, nil, "/#{database}", nil, nil, nil).to_s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select | |
psut.schemaname, | |
pc.relname, | |
pg_size_pretty(pg_relation_size(pc.relname::varchar)) relsize_pret, | |
pg_size_pretty(pg_total_relation_size(pc.relname::varchar)) total_relsize_pret, | |
pg_relation_size(pc.relname::varchar) relsize, | |
pg_total_relation_size(pc.relname::varchar) total_relsize, | |
pc.reltuples::integer, | |
pc.relpages, | |
coalesce(round((8000 / (nullif(pc.reltuples, 0) / nullif(pc.relpages, 0)))), 0) avg_tuplesize, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module RSpecHelpers | |
module InstanceMethods | |
def sign_in(user=nil) | |
user ||= User.make | |
fill_in 'user[email]', :with => user.email | |
fill_in 'user[password]', :with => user.password | |
click_button 'Sign in' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
filepath="/data/postgresql/9.1/main-backups" | |
cd $filepath | |
for database in `ls $filepath/daily`; do | |
filename=`date +"$filepath/daily/$database/$database-daily-%w-%a.dmp" | tr '[:upper:]' '[:lower:]'` | |
if [ -e $filename ]; then |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ko.extenders['typecast'] = function(target, type) { | |
target.subscribe(function(newValue) { | |
newValue = type(newValue); | |
// Setting subscription to NaN or undefined will start a never-ending loop. | |
if (!_.isNaN(newValue) && !_.isUndefined(newValue)) { | |
target(type(newValue)); | |
} | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# regex | |
regex = /(\((\d+),(\d+),(\d+),(t|f)\))/ | |
# multiple | |
tuples = "{\"(309686,248320,15912,t)\",\"(309688,248320,24928,f)\",\"(309691,248320,49041,f)\"}" | |
tuples.scan(regex) | |
[["(309686,248320,15912,t)", "309686", "248320", "15912", "t"], | |
["(309688,248320,24928,f)", "309688", "248320", "24928", "f"], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Api | |
module Authenticatable | |
class Unauthorized < Exception; end | |
def self.included(base) | |
base.send :before_filter, :verify_timestamp | |
base.send :before_filter, :verify_token | |
base.send :before_filter, :verify_signature | |
base.send :helper_method, :current_credential | |
end |