Skip to content

Instantly share code, notes, and snippets.

View tafsiri's full-sized avatar

Yannick Assogba tafsiri

View GitHub Profile
@tafsiri
tafsiri / us-states.json
Created April 30, 2015 03:23
US States GeoJSON
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tafsiri
tafsiri / index.html
Last active September 16, 2015 16:51
<html lang="en">
<head>
<meta charset="utf-8">
<title>2D Picking with SVG</title>
<meta name="description" content="">
<meta name="author" content="Yannick Assogba">
<script src="https://cdnjs.cloudflare.com/ajax/libs/stats.js/r14/Stats.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.5/dat.gui.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script>
#fib with memoization
fakeClosure := Object clone
fakeClosure memo := Map clone
fakeClosure fibmemo := method(num,
#I need this next line when i assign this method to a slot in the
#outer object (see last line of this gist).
#Feels like a 'this/self' binding issue. Otherwise i would have expected
#the memo slot on fakeClosure to be visible here
memo := fakeClosure memo #not strictly necessary when calling 'fakeClosure fibmemo'
memo atPut(0 asString, 0)
#traditional recursive fib
fib := method(num,
if(num == 0 or num == 1
, num
, fib(num-1) + fib(num-2)
)
)
@tafsiri
tafsiri / gist:762296
Created January 2, 2011 04:58
making objects and types in io
#differential inheritance
#making types (objects with a type field)
Shape := Object clone
Shape area := method(width * height)
Shape width := 5
Shape height := 9
Rect := Shape clone
Square := Shape clone
Ellipse := Shape clone
fakeClosure := Object clone do(
memo := Map clone
fibmemo := block(num, #note 'blocks' are lexically scoped
memo atPut(0 asString, 0)
memo atPut(1 asString, 1)
fibhelp := method(num,
one := memo at((num-1) asString)
two := memo at((num-2) asString)
if(one == nil
, one = fibhelp(num-1,memo)
#get rid of the object and just use a method as a container
fibmemoclosure := method(num,
memo := Map clone
fibmemo := block(num, #note 'blocks' are lexically scoped
memo atPut(0 asString, 0)
memo atPut(1 asString, 1)
fibhelp := method(num,
one := memo at((num-1) asString)
two := memo at((num-2) asString)
if(one == nil
@tafsiri
tafsiri / mixins.io
Created January 23, 2011 22:37
mixins in Io
#Minimal mixins in Io!
Object mix := method(obj,
#grab all the objects methods and add them to the target
#the target is the object mixing in the mixin
mixer := call target
obj slotNames foreach(slotName,
if(obj getSlot(slotName) type == "Block"
, mixer setSlot(slotName, obj getSlot(slotName))
#ignore properties for the moment
)
#Actors
#this code is from day 2
Delay := Object clone
Delay send := method(
args := call message arguments
for(i,0, args size - 1, 2,
delay := doMessage(args at(i))
msg := args at(i+1)
wait(delay)
#The sleeping barber problem http://en.wikipedia.org/wiki/Sleeping_barber_problem
#Solved with Io actors
Barber := Object clone do(
sleeping := false
wakeup := method(
"Waking Up!" println
sleeping = false
)