Skip to content

Instantly share code, notes, and snippets.

### Keybase proof
I hereby claim:
* I am p886 on github.
* I am p886 (https://keybase.io/p886) on keybase.
* I have a public key whose fingerprint is AB19 9923 F1B6 F633 4756 B21A 2DBF 53C2 E30E D27C
To claim this, I am signing this object:
@p886
p886 / gist:44d73618ff04d2afb3a7
Created January 23, 2015 16:32
Basic Understanding of Pointers in Go
package main
import "fmt"
// Explanation:
// changeIt() takes as argument a pointer to a thing
// in line 14 we create such a pointer and pass it to changeIt().
// Hadn't we used a pointer but instead passed thing *normally*,
// we would not have been able to observe the change
// from "yolo" to "roflmao" in main
@p886
p886 / gist:0dc3d4807c764f116775
Created August 21, 2014 11:19
Ruby to_proc Example
def say(a_proc_obj)
a_proc_obj.call
end
def tell
yield
end
a_lambda = -> { puts "there you go" }
@p886
p886 / gist:a128d93ad524b7bce378
Last active August 29, 2015 14:03
Anonymous Class for quickly building Fake Objects
# Anonymous Class for quickly building Fake Objects
# advantage over Struct: doesn't even need a single argument
# (Struct.new accepts 1+ arguments, this 0)
thing = Class.new do
def name
"helloooo!!"
end
end.new # <-- immediately creating an instance of the anoymous class
# this:
person = Struct.new(:name, :age, :human)
# …is functionally equivalent to this:
class Person
attr_accessor :name, :age, :human
def initialize name, age, human
@name = name
@age = age
@human = human
@p886
p886 / gist:8462065
Created January 16, 2014 19:48
Javascript in Ruby
lamb = -> do
a = 2
b = 0
puts "lamb #{b}"
lamb = -> do
puts a
b += 1
puts "lamb #{b}"
lamb = -> do
puts a