Skip to content

Instantly share code, notes, and snippets.

View cheeyeo's full-sized avatar
💭
Researching on use of transformers in computer vision

Chee Yeo cheeyeo

💭
Researching on use of transformers in computer vision
View GitHub Profile
# 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
@cheeyeo
cheeyeo / gist:11324200
Created April 26, 2014 16:18
Object.const get
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")
@cheeyeo
cheeyeo / mixpanel.rb
Last active August 29, 2015 14:00
Mixpanel module as mixin for Activerecord classes
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
@cheeyeo
cheeyeo / mixpanel.rb
Created April 25, 2014 19:35
Mixpanel generic module as a mixin in AR using ActiveSupport
# using active_support
require 'active_support/core_ext'
module Mixpanel
extend ActiveSupport::Concern
# class methods
included do
mixpanel
end
@cheeyeo
cheeyeo / my_logger.rb
Created April 23, 2014 20:12
Ruby string template
require "socket"
class MyLogger
attr_accessor :format
def initialize
@format = '%<severity>s %<time>s %<host>s %<pid>s %<message>s'
end
def error(message)
# 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
@cheeyeo
cheeyeo / test.rb
Created April 14, 2014 19:37
Multion pattern
# 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
@cheeyeo
cheeyeo / daterange2.rb
Created April 13, 2014 16:36
Date range with enumerator rather than enumerable
require 'date'
def ndays_from(from, step=7)
Enumerator.new {|y|
loop {
y.yield from
from += step
}
}
end
@cheeyeo
cheeyeo / date.rb
Last active August 29, 2015 13:59
Date range enumerator
# 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'
/* 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)} );