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
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
@cheeyeo
cheeyeo / equi.rb
Created May 15, 2014 20:45
Array equi in ruby
def equi(arr)
return 0 if arr.empty?
left, right = 0, arr.inject{|sum, n| sum + n}
equi_indices=[]
arr.each_with_index do |val,i|
left += val
equi_indices << i if right == left
@cheeyeo
cheeyeo / traffic_light.rb
Created May 12, 2014 20:30
Example of using classes to represent states, removing the need for case statements
class TrafficLight
class State
def to_s
name
end
def name
self.class.name.split('::').last.downcase
end
@cheeyeo
cheeyeo / point.rb
Created May 7, 2014 16:10
Defining idempotent conversion functions
def Point(*args)
respond_to_point = ->(arg){ arg.respond_to?(:to_point) }
respond_to_ary = -> (arg){ arg.respond_to?(:to_ary) }
case args.first
when Integer then Point.new(*args)
when String then Point.new(*args.first.split(':').map(&:to_i))
when respond_to_point
args.first.to_point
when respond_to_ary
@cheeyeo
cheeyeo / endian.m
Created April 28, 2014 19:34 — forked from markd2/endian.m
#import <Foundation/Foundation.h>
// Xcode_3_2_6/usr/bin/gcc -arch ppc -std=c99 -isysroot /Xcode_3_2_6/SDKs/MacOSX10.5.sdk -g -Wall -framework Foundation -o endian-ppc ~/Downloads/endian.m (thanks to Jeremy W. Sherman for the assist)
// clang -arch x86_64 -g -Weverything -framework Foundation -o endian endian.m
int main (void) {
unsigned int values[] = { 1, 387, 8533937 };
@cheeyeo
cheeyeo / audit_log.rb
Created April 28, 2014 19:20
Simple decorator pattern
class AuditLog
def record(number, action, amount, balance)
printf(
"%<time>s #%<number>s %<action>s %<amount>.2f (%<balance>.2f)\n",
time: Time.now,
number: number,
action: action,
amount: amount / 100,
balance: balance / 100)
end
<table>
<thead>
<tr>
<th>Name</th>
<th>Email></th>
<th>Country</th>
<th></th>
</tr>
</thead>
@cheeyeo
cheeyeo / gist:11354652
Created April 27, 2014 20:14
Microservice
http://martinfowler.com/articles/microservices.html
@cheeyeo
cheeyeo / readme.md
Created April 26, 2014 20:50
Brew update fails or unresponsive