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
get https://github.com/gregs1104/pgtune | |
see http://www.postgresql.org/docs/8.4/static/kernel-resources.html for reasonable kernel conf | |
play around with kernel settings without restart | |
sudo sysctl -w kern.sysv.shmmax=4409466880 #4GB must be a multiplier of 4096 | |
kern.sysv.shmmax: 4194304 -> 1073741824 | |
shmall must be shmax / pagesize | |
get pagesize with |
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 (SELECT hstore(array_agg(v), array_agg(c::text)) FROM ( | |
SELECT v, COUNT(*) as c from unnest(array_agg(country)) v GROUP BY v) t | |
) countries FROM test; | |
-- => "de"=>"10669", "en"=>"21542", "fr"=>"21573", "it"=>"10783", "us"=>"21774" |
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 ActiveRecord | |
module NullObject #:nodoc: | |
module InstanceMethods | |
# should quark like a nil | |
def nil? | |
true | |
end | |
def present? | |
false |
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 hstore(array_agg(v), array_agg(c::text)) FROM ( | |
SELECT v, COUNT(*) as c ,1 as agg from unnest(ARRAY['foo','bar','baz','foo']) v GROUP BY v) t | |
GROUP BY agg | |
--> "bar"=>"1", "baz"=>"1", "foo"=>"2" |
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 idstat.relname AS table_name, | |
indexrelname AS index_name, | |
idstat.idx_scan AS times_used, | |
pg_size_pretty(pg_relation_size(idstat.relname::regclass)) AS table_size, pg_size_pretty(pg_relation_size(indexrelname::regclass)) AS index_size, | |
n_tup_upd + n_tup_ins + n_tup_del as num_writes, | |
indexdef AS definition | |
FROM pg_stat_user_indexes AS idstat JOIN pg_indexes ON indexrelname = indexname | |
JOIN pg_stat_user_tables AS tabstat ON idstat.relname = tabstat.relname | |
WHERE idstat.idx_scan < 200 | |
AND indexdef !~* 'unique' |
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
-- Postgres makes it difficult four you to shoot yourselves in the foot | |
-- So it is not allowed to delete template databases | |
UPDATE pg_database SET datistemplate = FALSE where datname = 'template1'; | |
DROP DATABASE template1; | |
CREATE DATABASE template1 WITH template = template0 encoding = 'utf8'; | |
UPDATE pg_database SET datistemplate = TRUE where datname = 'template1'; |
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
class Array | |
# [1,2,3].add [1,2,3] => [2, 4, 6] | |
def add (other) | |
self.zip(other).map{|a| a.inject(0){|s,n| s+=n || 0;s }} | |
end | |
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
require "benchmark" | |
class Cracker | |
class << self | |
## runs the code retuning sek runtime | |
def run(test) | |
Benchmark.realtime{`./crackme #{test}`} | |
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
cat /var/log/mail.log | grep "status=sent" | awk '{print $7}' | awk '{ sub(/^to=</, ""); print }' | awk '{ sub(/>,$/, ""); print }' |
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
-- ~/Library/Application\ Support/iTerm/Scripts/setup_rails.scpt | |
-- Thanks to http://www.worldgoneweb.com/2011/iterm2-advanced-features/#comment-20560 | |
-- http://www.iterm2.com/#/section/documentation/scripting | |
tell application "iTerm" | |
activate | |
set myterm to (make new terminal) | |
set cd_to_my_project_path to ("cd ~/Projekte/my_awesome_project") | |
-- you can altenativly tell the first terminal | |
tell the first terminal | |
launch session "Panes" |