Skip to content

Instantly share code, notes, and snippets.

View tomchapin's full-sized avatar

Tom Chapin tomchapin

View GitHub Profile
@tomchapin
tomchapin / mandelbrot.sql
Last active August 29, 2015 14:25 — forked from rupey/mandelbrot.sql
Mandelbrot plot in postgres
WITH RECURSIVE
x(i) AS ( VALUES (0)
UNION ALL SELECT i + 1
FROM x
WHERE i < 101),
Z(Ix, Iy, Cx, Cy, X, Y, I) AS (
SELECT
Ix,
Iy,
X :: FLOAT,
@tomchapin
tomchapin / player_selector.rb
Created April 12, 2013 16:59
A quick ruby script that takes a series of player names as command line arguments and pairs them up with each other in random fashion. Example usage: > ruby player_selector.rb Bob John Jim Billy George
require 'active_support/core_ext/string/inflections'
require 'colorize'
players = ARGV.clone
raise 'You must specify players (separated by spaces) as parameters.' and exit(1) unless players.count > 0
until players.count == 0
player1, player2 = players.shuffle!.slice!(0,2)
player2 ||= "Bot(AI)"
# If the source arrays don't have nil in them, you only need to extend the first array with nils, zip will automatically pad the others with nil. This also means you get to use compact to clean the extra entries out which is hopefully more efficient than explicit loops
def interleave(a,*args)
max_length = args.map(&:size).max
padding = [nil]*[max_length-a.size, 0].max
(a+padding).zip(*args).flatten.compact
end
# Here is a slightly more complicated version that works if the arrays do contain nil
@tomchapin
tomchapin / .railsrc
Last active December 17, 2015 03:09 — forked from jwaldrip/.railsrc
--database=postgresql
--skip-test-unit
--skip-bundle
--template=https://gist.github.com/tomchapin/5541218/raw/rails-template.rb
@tomchapin
tomchapin / gist:5666208
Created May 28, 2013 21:15
Session Debugger (put in application_controller.rb). Courtesy of Jason Waldrip.
def session_with_debug
SessionDebugger.new(session_without_debug)
end
alias_method_chain :session, :debug
class SessionDebugger < SimpleDelegator
def []=(key, val)
puts "#{caller.first} SET session:#{key} TO #{val.inspect}"
--database=postgresql
--skip-test-unit
--skip-bundle
--template=https://gist.github.com/jwaldrip/5538342/raw/rails-template.rb

Git Cheat Sheet

Commands

Getting Started

git init

or

git clone url

What I Wish I'd Known About Equity Before Joining A Unicorn

Disclaimer: This piece is written anonymously. The names of a few particular companies are mentioned, but as common examples only.

This is a short write-up on things that I wish I'd known and considered before joining a private company (aka startup, aka unicorn in some cases). I'm not trying to make the case that you should never join a private company, but the power imbalance between founder and employee is extreme, and that potential candidates would

Keybase proof

I hereby claim:

  • I am tomchapin on github.
  • I am tomchapin83 (https://keybase.io/tomchapin83) on keybase.
  • I have a public key ASAiFqeTQIRMK4YEVyUWKfuF7uyZw1cFrhFRNJwn5yW7CAo

To claim this, I am signing this object:

@tomchapin
tomchapin / postgres_queries_and_commands.sql
Created September 6, 2018 02:04 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'