Skip to content

Instantly share code, notes, and snippets.

View dliggat's full-sized avatar

Dave Liggat dliggat

View GitHub Profile
@dliggat
dliggat / mixpanel_export.rb
Last active January 14, 2017 14:41
Export data from Mixpanel
#!/usr/bin/env ruby
require 'active_support/time'
require 'digest'
API_KEY = 'YOUR KEY'
API_SECRET = 'YOUR SECRET'
args = {
'from_date' => Date.new(2014,9,1).iso8601,
@dliggat
dliggat / states.md
Last active October 28, 2016 20:07
US States I've Visited
  • Alabama
  • Alaska
  • Arizona
  • Arkansas
  • California
  • Colorado
  • Connecticut
  • Delaware
  • Florida
  • Georgia
@dliggat
dliggat / ssh.config
Last active October 18, 2016 19:23
SSH into a private subnet via a bastion host
Host buildserver # bastion
HostName 50.123.123.123
User ec2-user
ForwardAgent yes
IdentityFile /Users/dliggat/.ssh/key.pem
Host buildagent # tunnel ssh through a bastion
HostName 10.0.0.100
User ec2-user
IdentityFile /Users/dliggat/.ssh/key.pem
@dliggat
dliggat / script.sh
Created January 10, 2014 14:40
Count the length of genome strings in the fastas directory
#!/bin/bash
# the_fastas=`ls fastas | sort --reverse`
the_fastas=`ls fastas`
total=0
for file in $the_fastas; do
size=`cat "fastas/$file" | grep -v '>' | tr -d "\n" | wc -c`
echo "The file is $file with a size of $size"
total=$((total+size))
done
@dliggat
dliggat / parenty.rb
Created October 21, 2013 19:29
How to use ActiveSupport's class_attribute to get sane, overridable class attributes in Ruby.
class Parenty
class_attribute :foo
self.foo = 123
def self.printy
"Hello #{self.foo}"
end
end
class Childy < Parenty
@dliggat
dliggat / birthday.rb
Created October 13, 2013 15:58
Simulating the birthday paradox.
#!/usr/bin/env ruby
require 'optparse'
def parse_options
options = { }
OptionParser.new { |opts|
opts.banner = "Usage: #{__FILE__} --group-size G --trial-count T"
opts.on('-g', '--group-size size', 'Size of the group') { |v| options[:group_size] = v }
opts.on('-t', '--trial-count count', 'How many trials to run') { |v| options[:trial_count] = v }
@dliggat
dliggat / permutation.rb
Last active December 25, 2015 03:09
Generate sequential permutations
#!/usr/bin/env ruby
length = 6
chars = [ 'a'..'z', 'A'..'Z', 0..9 ].map(&:to_a).flatten
sequencer = chars.repeated_permutation length
loop { puts sequencer.next.join '' }
@dliggat
dliggat / gist:5990988
Created July 13, 2013 14:55
A small bash function to consistently name 'paperless' documents.
# A consistent title for 'paperless' documents.
# Usage:
# $ title Apple ipod Receipt
# $ [2013-07-08 => apple ipod receipt] copied to clipboard.
# Then paste directly into Evernote, etc.
function title {
title_str=`date '+%Y-%m-%d'`
title_str="$title_str =>"
while [ $1 ]
do
0 * * * * echo `date` Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam diam elit, pellentesque eget mattis vitae, sodales quis quam. Aenean et bibendum felis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Quisque sed metus odio. Cras fermentum tincidunt gravida. Nullam tincidunt, quam at pretium adipiscing, leo lacus condimentum lorem, vitae euismod nisi erat ut dui. Pellentesque malesuada elementum nisl ut sagittis. Nulla sit amet odio leo. Phasellus consectetur lorem sed justo mattis cursus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. >> /tmp/foobar
@dliggat
dliggat / production.rake
Created January 8, 2015 22:54
Dump a postgresql production database excluding migrations; and restore locally
namespace :production do
task sync: :environment do |t, args|
user_at_host = 'ubuntu@aws-host.com'
user_keypair = '-i ~/.ec2/gsg-keypair'
filename = Time.now.strftime "production_dump_%Y-%m-%d_%H-%M-%S.psql"
dump_path = "/tmp/#{filename}"
project = 'project'
# Dumping the table (excluding schema_migrations) on the server.
dump_command = ["pg_dump --exclude-table=schema_migrations",