Skip to content

Instantly share code, notes, and snippets.

View dliggat's full-sized avatar

Dave Liggat dliggat

View GitHub Profile
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 / 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
@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 / 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 / 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 / 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 / bandwidth_crontab.sh
Last active August 29, 2015 13:55
Crontab to test bandwidth speed: 4 times a day
# Note 1: Necessary to reproduce $PATH so that the boxen location for wget is picked up by the cron daemon.
# Note 2: Pick an appropriate output location - currently this is set to a logging directory in Dropbox
PATH=/opt/boxen/nodenv/shims:/opt/boxen/nodenv/bin:bin:/opt/boxen/rbenv/shims:/opt/boxen/rbenv/bin:/opt/boxen/rbenv/plugins/ruby-build/bin:/opt/boxen/bin:/opt/boxen/homebrew/bin:/opt/boxen/homebrew/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin
0 8,13,18,23 * * * wget --output-document=/dev/null --report-speed=bits http://speedtest.wdc01.softlayer.com/downloads/test10.zip 2>&1 | grep ') -' >> /Users/$USER/Dropbox/Logging/`hostname`-bandwidth.log
@dliggat
dliggat / rgba_to_hex.rb
Last active August 29, 2015 13:56
Convert RGBA to transparency + hex
vals = "255,0,0,0.8".split(',')
transparency = vals.pop.to_f
hex = "#%02x%02x%02x" % vals.map(&:to_i)
@dliggat
dliggat / photo_bin.rb
Created March 21, 2014 01:18
A ruby script to bin photos by year-month directories (assumes jpgs are in a standard ISO8601ish format; e.g. 2014-01-10_13-23-22.jpg).
#!/usr/bin/env ruby
require 'date'
require 'fileutils'
raise ArgumentError.new "Usage: #{$0} directory" unless ARGV.count == 1
root_dir = File.expand_path ARGV.first
Dir.glob "#{root_dir}/*.jpg" do |file|
@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