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 / 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/
@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 / 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 / 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 / fizzbuzz.rb
Created March 20, 2014 20:10
Ruby hash selector pattern
class Fizzbuzz
def initialize(number)
@number = number
end
def self.count(number)
count = new(number)
count.output_data[count.selector.to_s]
end
@cheeyeo
cheeyeo / pagination.rb
Created March 20, 2014 19:54
Ruby pagination example with extend
module Pagination
def paginate(page = 1, items_per_page = size, total_items = size)
@page = 1
@items_per_page = items_per_page
@total_items = total_items
end
attr_reader :page, :items_per_page, :total_items
def total_pages
@cheeyeo
cheeyeo / polymorphic.rb
Created March 19, 2014 17:12
Ruby polymorphic example
class GenericParser
def parse(parser)
puts "The parser class received the parse method"
parser.parse
end
end
class JSONParser
def parse
puts "An instance of the JSONParser receives the parse message"
@cheeyeo
cheeyeo / search.rb
Created March 19, 2014 13:58
Ruby: calling included classes within parent module
module Search
@children = []
def self.included(base)
@children << base
end
def self.query(val)
@children.each do |child|
child.query(val)
@cheeyeo
cheeyeo / fizzbuzz.rb
Created March 14, 2014 15:10
Example of FizzBuzz in Ruby using procs
MULTIPLE_OF_3 = ->(n){ (n % 3).zero? }
MULTIPLE_OF_5 = ->(n){ (n % 5).zero? }
MULTIPLE_OF_3_AND_5 = ->(n){ MULTIPLE_OF_3[n] && MULTIPLE_OF_5[n] }
(1..100).each do |num|
case num
when MULTIPLE_OF_3_AND_5
puts "FizzBuzz"
when MULTIPLE_OF_3
puts "Fizz"