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 'active_record' | |
require 'parallel' | |
ActiveRecord::Base.establish_connection(adapter: 'postgresql', pool: 25, username: 'postgres', host: 'localhost', database: 'postgres') | |
ActiveRecord::Base.connection.execute "DROP DATABASE IF EXISTS segfault" | |
ActiveRecord::Base.connection.execute "CREATE DATABASE segfault" | |
ActiveRecord::Base.establish_connection(adapter: 'postgresql', pool: 25, username: 'postgres', host: 'localhost', database: 'segfault') | |
ActiveRecord::Base.connection.execute <<-SQL | |
CREATE TABLE test_data( | |
tracker_id integer not null, | |
created_at timestamp, |
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
CREATE TABLE foo( | |
id integer | |
); | |
CREATE FUNCTION foo_trigger() RETURNS trigger LANGUAGE plpgsql AS $_$ | |
DECLARE | |
r foo%rowtype; | |
BEGIN | |
SELECT NEW.* INTO r; | |
RETURN r; |
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
# This must be run from master | |
git checkout master | |
# Update our list of remotes | |
git fetch | |
git remote prune origin | |
# Remove local fully merged branches | |
git branch --merged master | grep -v 'master$' | xargs git branch -d | |
# Show remote fully merged branches | |
echo "The following remote branches are fully merged and will be removed:" | |
git branch -r --merged master | sed 's/ *origin\///' | grep -v 'master$' |
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
# If your workers are inactive for a long period of time, they'll lose | |
# their MySQL connection. | |
# | |
# This hack ensures we re-connect whenever a connection is | |
# lost. Because, really. why not? | |
# | |
# Stick this in RAILS_ROOT/config/initializers/connection_fix.rb (or somewhere similar) | |
# | |
# From: | |
# http://coderrr.wordpress.com/2009/01/08/activerecord-threading-issues-and-resolutions/ |
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" |
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
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
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
-- 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
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' |
OlderNewer