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
Rehearsal ----------------------------------------------------
using httpclient 0.570000 0.280000 0.850000 ( 42.646417)
using EM 0.140000 0.130000 0.270000 ( 3.381920)
------------------------------------------- total: 1.120000sec
user system total real
using httpclient 0.520000 0.230000 0.750000 ( 28.525617)
using EM 0.140000 0.130000 0.270000 ( 3.902702)
AmazeSNS.list_topics do |resp|
response = Crack::XML.parse(resp.response)
# do further processing here
EM.stop
end
@cheeyeo
cheeyeo / gist:399702
Created May 13, 2010 10:27
Clearing session
# something trivial but might be helpful if you want to implement clearing the session hash when the user presses the
# Back button
# used in IQF project when the email contact link on top right of page has to show the title of current page
def clear_session
response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
end
@cheeyeo
cheeyeo / example1.rb
Created November 2, 2010 11:19
A generic interface example
class Vehicle
def start_engine
# start the engine
end
def stop_engine
#stop the engine
end
@cheeyeo
cheeyeo / example2.rb
Created November 2, 2010 11:21
Composition over inheritance
class Engine
def initialize
# set engine properties here etc
end
# other engine methods
end
class Car < Vehicle
@cheeyeo
cheeyeo / template_not_refactored.rb
Created November 2, 2010 11:23
First implementation of the Report class
class Report
def initialize
@title = 'Monthly Report'
@text = ['Things are going', 'really, really well.']
end
def output_report(format)
if format == :plain
puts("*** #{@title} ***")
elsif format == :html
@cheeyeo
cheeyeo / template_pattern.rb
Created November 2, 2010 11:25
Report class refactored to use Template pattern
class Report
def initialize
@title = 'My Report'
@text = ['Lorem’, ‘Ipsum']
end
end
def output_report
output_start
output_head
@cheeyeo
cheeyeo / template_pattern_subclass.rb
Created November 2, 2010 11:26
HTML subclass of Report class using Template pattern
class HTMLReport < Report
def output_start
puts('<html>')
end
def output_head
puts(' <head>')
puts(" <title>#{@title}</title>")
puts(' </head>')
@cheeyeo
cheeyeo / singleton_pattern_example.rb
Created November 2, 2010 11:28
Example of using Ruby's built in Singleton Module
require 'singleton'
class MyClass
attr_accessor :data
include Singleton
end
a = MyClass.instance
b = MyClass.instance
@cheeyeo
cheeyeo / singleton_logger.rb
Created November 2, 2010 11:31
Simple logger using Ruby's built in Singleton module
require 'singleton'
class SimpleLogger
include Singleton
attr_accessor :level
ERROR=1
WARNING=2
INFO=3