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
# Other syntax without patch
STUDENT_LEVELS = {
freshman: Student::Underclassman,
sophomore: Student::Underclassman,
junior: Student::Upperclassman,
senior: Student::Upperclassman,
graduate: Student::Graduate
}.tap { |h| h.default = Student::Unregistered }
@cheeyeo
cheeyeo / r1.rb
Created January 27, 2016 21:24
Refactory Ruby case using Hashes
STUDENT_LEVELS = Hash.new(Student::Unregistered).merge(
freshman: Student::Underclassman,
sophomore: Student::Underclassman,
junior: Student::Upperclassman,
senior: Student::Upperclassman,
graduate: Student::Graduate
)
klass = STUDENT_LEVELS[params[:student_level]]
student = klass.new(name, birthdate, address, phone)
@cheeyeo
cheeyeo / tree.py
Created January 13, 2016 16:40
Example python decision tree
class decisionnode:
def __init__(self,col=-1,value=None,results=None,tb=None,fb=None):
self.col=col # column index of criteria being tested
self.value=value # vlaue necessary to get a true result
self.results=results # dict of results for a branch, None for everything except endpoints
self.tb=tb # true decision nodes
self.fb=fb # false decision nodes
# Divides a set on a specific column. Can handle numeric or nominal values
@cheeyeo
cheeyeo / password_entropy.py
Created January 13, 2016 16:39
Password entropy example
import re
from math import log,pow
class PasswordStrength:
def __init__(self):
self.numeric=re.compile('\d')
self.loweralpha=re.compile('[a-z]')
self.upperalpha=re.compile('[A-Z]')
self.symbols=re.compile('[-_.:,;<>?"#$%&/()!@~]')
self.num_of_symbols=20 # adjust accordingly...
@cheeyeo
cheeyeo / how_many_nodes.rb
Created January 2, 2016 19:11 — forked from radarek/how_many_nodes.rb
Veryfing "Table 1—Number of additional T_NODE objects created by an iterator" from "Ruby Performance Optimization" book
def count_nodes(label)
before = ObjectSpace.count_objects
yield
after = ObjectSpace.count_objects
puts " #{label} created T_NODE: %d" % (after[:T_NODE] - before[:T_NODE])
end
class MyClass
include Enumerable
@cheeyeo
cheeyeo / lets.ex
Created January 2, 2016 19:09 — forked from radarek/lets.ex
defmodule ExUnit.Lets do
defmacro __using__([]) do
quote do
import ExUnit.Lets
end
end
defmacro let(name, expr) do
if match?([do: _], expr) do
expr = expr[:do]
@cheeyeo
cheeyeo / README.md
Created January 2, 2016 19:07 — forked from radarek/README.md