Skip to content

Instantly share code, notes, and snippets.

View subelsky's full-sized avatar
🧘‍♂️

Mike Subelsky subelsky

🧘‍♂️
View GitHub Profile
@subelsky
subelsky / large_redshift_tables.sql
Created April 18, 2014 17:39
Quick SQL command to find large tables in redshift
-- based on http://stackoverflow.com/questions/21767780/how-to-find-size-of-database-schema-table-in-redshift
SELECT name AS table_name, ROUND((COUNT(*) / 1024.0),2) as "Size in Gigabytes"
FROM stv_blocklist
INNER JOIN
(SELECT DISTINCT id, name FROM stv_tbl_perm) names
ON names.id = stv_blocklist.tbl
GROUP BY name
ORDER BY "Size in Gigabytes" DESC
#!/usr/bin/env ruby
require "rubygems"
require "mechanize"
require "domain_name"
m = Mechanize.new
puts "<ul>"
DATA.each_line do |line|
@subelsky
subelsky / deploy.rake
Created November 27, 2013 14:28
basic heroku "rake deploy" task
namespace :deploy do
task :default => [:production]
desc "check if git is clean"
task :check => "assets:check" do
unless system("git diff --exit-code")
puts "Git not clean. Aborting."
`growlnotify -m 'deployment failed'; say 'deployment failed'`
abort
end
@subelsky
subelsky / aliases.sh
Created October 17, 2013 14:05
Useful aliases for Ruby and Rails development and git maintenance
alias a='ack'
alias a?='alias | grep -i'
alias adx='rake db:drop && rake db:create && heroku pg:transfer --from black --to postgres://postgres@localhost/staq_development --confirm staqweb --app staqweb && rails r "User.all.each { |u| u.update_attribute(:password,%q(password)) }" && rake db:test:prepare'
alias b='bundle'
alias bb='bundle install --binstubs=.bundle/bin --path=.bundle/gems && bundle package --all && reload ; sd'
alias bc='bin/console'
alias be='bundle exec'
alias bea='bundle exec annotate'
alias bu='bundle update'
alias bus='bundle update staq_extraction'
@subelsky
subelsky / com.staq.pound.plist
Created May 28, 2013 14:26
launchd plist to get Pound running at startup on OS X
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.staq.pound</string>
<key>ProgramArguments</key>
<array>
<string>sudo</string>
<string>/usr/local/sbin/pound</string>
@subelsky
subelsky / pound.txt
Created May 28, 2013 14:24
simple Pound server configuration to terminate SSL connections and forward to a Rack app
Alive 10
# http://lvh.me
ListenHTTP
Address 127.0.0.1
Port 80
Service
BackEnd
Address 127.0.0.1
@subelsky
subelsky / in_and_out.gitconfig
Last active December 16, 2015 22:39
how to add mercurial-style "in" and "out" commands to git, thanks @bkemper for showing me these
# I learned this from @bkemper, very useful to show what's in a commit about to be pushed to the remote repo
# and what's in the commits that are about to be pulled from the remote repo
[alias]
in = "!f() { [[ -z \"$1\" ]] && B='master' || B=\"$1\"; git log $B..origin/$B; }; f"
out = "!f() { [[ -z \"$1\" ]] && B='master' || B=\"$1\"; git log origin/$B..$B; }; f"
@subelsky
subelsky / asset.rake
Created March 3, 2013 21:48
Quick rake task to check if assets need to pre-compiled before deployment (since I don't like precompiling during deployment)
namespace :assets do
task :check do
root_dir = File.join(File.dirname(__FILE__),"..","..")
assets_last_modified_at = Dir["#{root_dir}/app/assets/**/**"].map { |p| File.mtime(p) }.sort.last
assets_last_compiled_at = Dir["#{root_dir}/public/assets/**/**"].map { |p| File.mtime(p) }.sort.last
if assets_last_modified_at > assets_last_compiled_at
fail "Assets need to precompiled; last asset modified at #{assets_last_modified_at}"
end
end
@subelsky
subelsky / puma_rails_heroku.rb
Created October 31, 2012 13:51
Setting up Puma and Rails on Heroku
# Gemfile
gem "puma"
# Procfile
web: bundle exec puma -p $PORT -e $RACK_ENV -C config/puma.rb
# add to config block config/environments/production.rb
config.threadsafe!
# get rid of NewRelic after_fork code, if you were doing this:
@subelsky
subelsky / dependency_injection_container.rb
Created September 10, 2012 14:28
Code examples for Ruby Dependencies, Notifications, and Adjustments (Ruby DNA)
require "dim"
AppContainer = Dim::Container.new
AppContainer.register(:env) { ENV['ADWORK_ENV'] || "development" }
AppContainer.register(:production?) { |c| c.env == 'production' }
AppContainer.register(:development?) { |c| c.env == 'development' }
AppContainer.register(:test?) { |c| c.env == 'test' }
AppContainer.register(:root) { File.expand_path(File.dirname(__FILE__)+"/../..") }
AppContainer.register(:logger) do |c|