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
@cheeyeo
cheeyeo / global-callback-listener.js
Last active August 29, 2015 13:57
TRACK AJAX REQUESTS Success callback across multiple js files
//Within jquery you can listen to global ajax event handlers for the outcome of any ajax requests for when you want to write
// your own callback from predefined ajax calls
// e.g.
// the below js call is in a separate js file say 'main.js'
function makeAjaxCall(){
//...
$.ajax({
url: 'http://something.com'
});
@cheeyeo
cheeyeo / opts.rb
Created March 28, 2014 17:21
Optsparse example
require 'optparse'
require 'optparse/time'
require 'ostruct'
require 'pp'
class OptparseExample
CODES = %w[iso-2022-jp shift_jis euc-jp utf8 binary]
CODE_ALIASES = { "jis" => "iso-2022-jp", "sjis" => "shift_jis" }
@cheeyeo
cheeyeo / temp.rb
Created April 6, 2014 20:47
Using ruby tempfile to fetch a remote resource for custom formatting
class LocalResource
attr_reader :uri
def initialize(uri)
@uri = uri
end
def file
@file ||= Tempfile.new(tmp_filename, tmp_folder, encoding: encoding).tap do |f|
io.rewind
@cheeyeo
cheeyeo / gist:10384414
Last active August 29, 2015 13:58
Useful links to VIM commands
http://www.radford.edu/~mhtay/CPSC120/VIM_Editor_Commands.htm
http://www.cyberciti.biz/faq/vi-show-line-numbers/
/* 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)} );
@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'
@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 / 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
# 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 / 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)