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:8997948
Created February 14, 2014 09:01 — forked from orend/gist:5134300
require 'csv'
def memstats
size = `ps -o size= #{$$}`.strip.to_i
end
memstats #4900
CSV.open('visitors.csv', headers: true) do |csv|
visitors = csv.each # Enumerator
memstats # 5164
var tweet = "Currently chilling out at W1B 2EL, then on to WC2E 8HA or maybe even L1 8JF! :-)";
// Here's a simple regex that tries to recognise postcode-like strings.
// See http://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom#Validation
// for the rules on how UK postcodes are formatted.
var postcode_regex = /[A-Z]{1,2}[0-9][0-9A-Z]?\s?[0-9][A-Z]{2}/g;
var postcodes = tweet.match(postcode_regex);
console.log(postcodes);
@cheeyeo
cheeyeo / callback.rb
Created February 19, 2014 21:27
Ruby example of caller specified callback
require 'ostruct'
require 'open-uri'
require 'json'
class TemperatureApiError < StandardError
end
class CheeError < StandardError
end
@cheeyeo
cheeyeo / episode.rb
Created March 3, 2014 17:27
Example of ghost loading pattern
class Episode
def self.lazy_accessor(*names)
names.each do |name|
attr_writer name
define_method(name) do
load
instance_variable_get("@#{name}")
end
end
end
@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"
@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 / 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 / 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 / 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