Skip to content

Instantly share code, notes, and snippets.

@mikelikesbikes
mikelikesbikes / path.sh
Last active December 21, 2015 05:39
File counts for directories in your path
arr=`echo $PATH | tr ':' '\n'`;
for path in ${arr[*]}; do
printf "%5s %s\n" `ls $path | wc -l` $path
done
/* Here is your chance to take over Socrates!
Spend 10 minutes on each of the following hacks to the socrates website.
Enter them in the console to make sure it works and then save
your results here.
Choose a new pair for each. Add your names to the section you complete.
*/
@mikelikesbikes
mikelikesbikes / input.txt
Last active December 12, 2015 08:29
My solution to XKCD #287 http://xkcd.com/287/
$15.05
mixed fruit,$2.15
french fries,$2.75
side salad,$3.35
hot wings,$3.55
mozzarella sticks,$4.20
sampler plate,$5.80
@mikelikesbikes
mikelikesbikes / argv.rb
Created November 13, 2012 15:52
ARGV/OptionParser destruction
require 'optparse'
require 'ostruct'
options = OpenStruct.new
parser = OptionParser.new do |opts|
opts.on("-f", "--force", "Force something to happen") do |force|
options.force = force
end
end
@mikelikesbikes
mikelikesbikes / sf_id_converter.rb
Created October 29, 2012 22:18
Converts 15 character Salesforce IDs to 18 character Salesforce IDs (adds checksum)
CHECKSUM_CHARS = ((?A..?Z).to_a + (0..5).to_a).join
# String -> String
def id_with_checksum(sfid)
# protection from bad people who misuse things
return sfid if sfid.length == 18
raise ArgumentError.new("sfid must be 15 characters") unless sfid.length == 15
# The meat.
suffix = sfid.chars \ # String -> [String]
require 'benchmark'
require 'hamster'
require 'deps/clojure-1.4.0.jar'
Benchmark.bm do |bm|
def fill(hash)
(0..10000).reduce(hash) do |h, i|
if h.class == Java::ClojureLang::PersistentHashMap
h.assoc(i, 1)
elsif h.respond_to?(:put)
brew tap homebrew/dupes
brew install apple-gcc42
@mikelikesbikes
mikelikesbikes / fib_spec.rb
Created June 13, 2012 12:56
Dynamic Rspec examples
describe "fibonacci" do
[
[0, 0],
[1, 1],
[2, 1],
[3, 2],
[4, 3],
[5, 5],
[6, 8]
].each do |index, value|
;; http://stackoverflow.com/questions/1590716/clojure-prime-numbers-lazy-sequence
(def primes
(let [primes (atom [])]
(for [n (iterate inc 2)
:when (not-any? #(zero? (rem n %))
(filter #(<= % (Math/sqrt n))
@primes))]
(do (swap! primes conj n)
n))))
@mikelikesbikes
mikelikesbikes / frequency_benchmarks.rb
Created April 18, 2012 05:08
comparing frequency built using different enumerable methods
require 'benchmark'
Enumerable.class_eval do
def frequency_group_by
group_by{|x| x}.map { |x, xs| [x, xs.length] }
end
def frequency_each
h = Hash.new(0)