This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Get the 1.0.1 version of SSL | |
| brew install openssl | |
| ./configure --disable-hipe --enable-smp-support --enable-threads --enable-kernel-poll --enable-darwin-64bit --with-ssl=/usr/local/opt/openssl | |
| touch lib/wx/SKIP lib/odbc/SKIP | |
| make -j4 | |
| sudo make install |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def string_to_constant(constant_name) | |
| constant_name.split("::").inject(Object) { |s,e| s.const_get(e) } | |
| end | |
| class Article; end | |
| string_to_constant("Article") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'active_support/core_ext' | |
| module Mixpanel | |
| module ClassMethods | |
| def mixpanel(*names) | |
| # Defines both class and instance accessors for class attributes. | |
| class_attribute :mp_attrs | |
| self.mp_attrs = names | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # using active_support | |
| require 'active_support/core_ext' | |
| module Mixpanel | |
| extend ActiveSupport::Concern | |
| # class methods | |
| included do | |
| mixpanel | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require "socket" | |
| class MyLogger | |
| attr_accessor :format | |
| def initialize | |
| @format = '%<severity>s %<time>s %<host>s %<pid>s %<message>s' | |
| end | |
| def error(message) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 1) Create your private key (any password will do, we remove it below) | |
| $ cd ~/.ssh | |
| $ openssl genrsa -des3 -out server.orig.key 2048 | |
| # 2) Remove the password | |
| $ openssl rsa -in server.orig.key -out server.key |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Multiton pattern | |
| # extension to the Singleton pattern which maps unique keys to specific instances of a class. The idea is that there should only be one instance of an object for each unique key in use, limiting the number of objects that need to be created | |
| class Font | |
| class << self | |
| def file_names | |
| @file_names ||= {} | |
| end | |
| def instances |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'date' | |
| def ndays_from(from, step=7) | |
| Enumerator.new {|y| | |
| loop { | |
| y.yield from | |
| from += step | |
| } | |
| } | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # usage: | |
| # dr = DateRange.new(Date.today) | |
| # dr.each{|d| puts d} | |
| # enum = dr.lazy | |
| # enum.next | |
| # enum.find_all{|d| d.cwday < 5 } # returns all | |
| # enum.detect{|d| d.cwday < 3 } # only returns the first instance | |
| require 'date' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Abstract event binding | |
| Example: | |
| var MyEventEmitter = function(){}; | |
| MyEventEmitter.prototype = new AbstractEventsDispatcher; | |
| var emitter = new MyEventEmitter(); | |
| // Bind to single event | |
| emitter.bind('foo_event', function(data){ alert(data)} ); |