Skip to content

Instantly share code, notes, and snippets.

View alexgenco's full-sized avatar

Alex Genco alexgenco

View GitHub Profile
@alexgenco
alexgenco / .rspec
Last active March 27, 2018 20:04
rspec-core 2530
-r spec_helper
--default-path .

Keybase proof

I hereby claim:

  • I am alexgenco on github.
  • I am alexgenco (https://keybase.io/alexgenco) on keybase.
  • I have a public key ASB8GXLy-bCW-DmcFzHdkoW-IYU8euAZp-IKbeYSDEAFtQo

To claim this, I am signing this object:

@alexgenco
alexgenco / magic.rb
Created September 12, 2013 23:54
Active Support JSON encoding magic (AKA, "State: you're doing it wrong")
json1 = {:one => nil}.as_json # => {"one"=>"null"}
json2 = {"one" => "null"} # => {"one"=>"null"}
json1 == json2 # => true
Yajl::Encoder.encode(json1) # => "{\"one\":\"null\"}"
Yajl::Encoder.encode(json2) # => "{\"one\":\"null\"}"
ActiveSupport::JSON.encode(json2) # => "{\"one\":\"null\"}"
ActiveSupport::JSON.encode(json1) # => "{\"one\":null}"
@alexgenco
alexgenco / sort_samples.rb
Created August 28, 2012 04:32
Sort a bunch of drum machine sound files into categories like "snare", "kick", "hihat", etc.
#!/usr/bin/env ruby
print "this will rescursively rearrange all these directories. u sure? [Yn] "
response = gets.strip
abort("k.") unless response =~ /y/i
require 'fileutils'
$in_dirs = Dir["./*/"]
@alexgenco
alexgenco / pen36.rb
Created July 25, 2011 19:13
Project Euler #36 in Ruby
#!/usr/bin/env ruby
# Project Euler 36
#
# The problems asks for the sum of all numbers below a million that
# are palindromes in base 10 and base 2. I solved it by opening up
# the Fixnum class and adding palindrome methods.
#
# pnext returns the next palindrome:
# 121.pnext # => 131
@alexgenco
alexgenco / pen8.py
Created June 15, 2011 04:39
Project Euler #8 in Python
# the problem asks for the largest product of 5 consecutive numbers in a 1000 digit number.
# something tells me this could be even more succinct, maybe with just one list comprehension
number = [ int(x) for x in list("73167 ... 63450") ]
print max([ number[i] * number[i+1] * number[i+2] * number[i+3] * number[i+4] for i in range(len(number)-4) ])