Skip to content

Instantly share code, notes, and snippets.

@eric1234
eric1234 / README.md
Last active August 29, 2015 13:58
Automatically translated snake_case method calls into their CamelCase equal

A module to automatically translate snake_case method calls into CamelCase method calls. For example:

class MyObject
  include Snakeable
  
  def FooBar
    "baz"
  end

end

@eric1234
eric1234 / gem_cache.rb
Created May 2, 2014 17:34
Gem.cache polyfill - For running REALLY old Rails applications (1.2.x) under newer versions of RubyGems.
# I put this right after rubygems is loaded in my boot.rb file
def Gem.cache
cache = Object.new
def cache.search name, *requirements
Gem::Specification.find_all_by_name name, *requirements
end
def cache.find *args, &blk
Gem::Specification.all.find *args, &blk
end
@eric1234
eric1234 / 1.9.2-p320.patch
Last active August 29, 2015 14:02 — forked from thescouser89/1.8.7-rbenv.patch
Like the original 1.8.7 patch but for 1.9.2-p320
--- ext/openssl/ossl_pkey_ec.c
+++ ext/openssl/ossl_pkey_ec.c
@@ -761,8 +761,10 @@ static VALUE ossl_ec_group_initialize(in
method = EC_GFp_mont_method();
} else if (id == s_GFp_nist) {
method = EC_GFp_nist_method();
+#if !defined(OPENSSl_NO_EC2M)
} else if (id == s_GF2m_simple) {
method = EC_GF2m_simple_method();
+#endif
@eric1234
eric1234 / even_height.coffee
Last active August 29, 2015 14:03
Script to force unrelated elements to have the same height. Does not dynamically adjust for changes in content but you can re-run the "apply" function after a data change if you need to allow for changing content.
# https://gist.github.com/eric1234/13501faf7471a45d10be
class @EvenHeight
constructor: (@elements...) -> @apply()
apply: ->
# In case the page doesn't have the elements so we don't have to
# check when calling the constructor.
return if @elements.length == 0
@eric1234
eric1234 / 2.0.0-p0-rbenv.patch
Last active August 29, 2015 14:04 — forked from thescouser89/1.8.7-rbenv.patch
Like the original 1.8.7 patch but for 2.0.0-p0
--- ext/openssl/ossl_pkey_ec.c
+++ ext/openssl/ossl_pkey_ec.c
@@ -762,8 +762,10 @@
method = EC_GFp_mont_method();
} else if (id == s_GFp_nist) {
method = EC_GFp_nist_method();
+#if !defined(OPENSSl_NO_EC2M)
} else if (id == s_GF2m_simple) {
method = EC_GF2m_simple_method();
+#endif
@eric1234
eric1234 / README.md
Last active August 29, 2015 14:10
Fast mass deletion on S3 for Node

Description

This script is conceptually based on s3nuke but with an entirely different implementation. The key differences are:

  • Uses deleteObjects to delete in batches rather than calling a delete for each key.
  • Is implemented in node to take advantage of it's evented IO

Performance

@eric1234
eric1234 / csv_reader_with_header.rb
Created September 10, 2009 20:08
CSV::Reader extension: Utilize header row
# Extends CSV::Reader to assume the first row is the headers to the data
# (i.e. fields names). Each non-header row in the data with then be
# passed a hash instead of the normal array so you can reference the
# data by field name. For example:
#
# CSV::Reader::WithHeader.parse(io) do |row|
# puts row['first_name'] + ' ' + row['last_name']
# end
class CSV::Reader::WithHeader < CSV::Reader
def self.parse(str_or_readable, fs=',', &blk)
@eric1234
eric1234 / import_helper.rb
Created September 10, 2009 21:30
Simple method to help import a data while normalizing at the same time.
# Most simply just returns the data. But can allow for adjusting of the
# data a bit more to ensure more normalized data or format conversions.
#
# * If data is blank? (as defined by ActiveSupport) then nil is
# returned.
# * If the block is given then that will be called and the return
# value will be passed back. If the value is blank? then the block
# will not be called and nil will be returned (to avoid checks
# in the blocks)
#
# An example of verbose Ruby code to counter the argument that
# optional syntax should be used as expressed on the blog post
# http://robots.thoughtbot.com/post/185504560/to-self-or-not-to-self
#
# I.E. the logical conclusion of this sort of thinking.
class User < ActiveRecord::Base
self.before_save(:sanitize_names);
def display_name()
return self.email() if self.first_name().blank?();
@eric1234
eric1234 / podcast_slurp.rb
Created September 11, 2009 18:44
Will slurp media attached to audio/video podcasts.
#!/usr/bin/env ruby
# Will slurp all the media attached to a audio/video podcasts. USAGE:
#
# ruby -rrubygems podcast_slurp.rb http://feeds.feedburner.com/railscasts railscasts
$VERBOSE = true
require 'open-uri'
require 'nokogiri'