Skip to content

Instantly share code, notes, and snippets.

View apetrov's full-sized avatar

Alexander Petrov apetrov

View GitHub Profile
@apetrov
apetrov / -
Created January 29, 2015 08:02
\set QUIET ON
\set PROMPT1 '%[%033[33;1m%]%x%[%033[0m%]%[%033[1m%]%/%[%033[0m%]%R%# '
\set PAGER OFF
\pset format wrapped
\set show_slow_queries
\pset linestyle unicode
\x auto
\pset null 'NULL'
\set HISTFILE ~/.psql_history- :HOST - :DBNAME
\set HISTSIZE 2000
select * from (
select expenses.*, revenue.sum, 100 * (revenue.count + 1)/ (expenses.count + 1) as ctr, (revenue.sum - expenses.sum) as profit from (
select
campaign_id,
site_id,
count(id),
sum(bid)/1000 as sum
from winning_bids
where created_at > now() - interval '1 hour'
group by campaign_id,site_id
@apetrov
apetrov / -
Created October 6, 2014 21:30
SiteEffectiveRates = Struct.new(:parent_id, :domain, :pricing, :data)
def map_sites(sites, result_set)
sites.map do |t|
result_set[t.id].map do |pricing, data|
SiteEffectiveRates.new(t.parent_id, t.host_from_url, pricing.to_sym, data )
end
end.flatten
end
(print "foo" )
(sort [1 2 4 3])
(print { 1 2 3 4 })
(-> { :foo 1 } :foo)
(.toString (.append (StringBuilder.) "foo"))
(->> (StringBuilder. ) (.append "foo") (.toString) )
assign successor
55347
assign successor
55348
assign successor
55349
assign successor
55350
assign successor
55351
@apetrov
apetrov / gist:1789888
Created February 10, 2012 14:22
Recipes
Gem list - to installable script
replace \((\d\.\d+\.\d+)\) with --version=$1
Remove blank lines
pbpaste | grep -v "^$" | pbcopy
html2haml
pbpaste | html2haml | pbcopy
format json
ActiveRecord::Base.sqlserver_connection({"mode"=>"ODBC", "adapter"=>"sqlserver", "dsn"=>"DRIVER=/usr/local/lib/libtdsodbc.so;TDS_Version=8.0;SERVER=173.15.160.129;DATABASE=TMWSuite_LIVE;Port=1433;uid=tracell;pwd=XXXX;"})
Config:
adapter: sqlserver
mode: ODBC
dsn: 'DRIVER=/usr/lib/libtdsodbc.so;TDS_Version=8.0;SERVER=XXXX;DATABASE=XXXX;Port=1433;uid=XXXX;pwd=XXXX;'
Linux:
sudo gem install dbd-odbc --no-ri --no-rdoc
# For complete deployment instructions, see the following support guide:
# http://www.engineyard.com/support/guides/deploying_your_application_with_capistrano
require "eycap/recipes"
# =================================================================================================
# ENGINE YARD REQUIRED VARIABLES
# =================================================================================================
# You must always specify the application and repository for every recipe. The repository must be
# the URL of the repository you want this recipe to correspond to. The :deploy_to variable must be