Skip to content

Instantly share code, notes, and snippets.

@cawel
cawel / code-1.js
Last active August 29, 2015 14:09 — forked from bennadel/code-1.js
(function(){
// Define your class.
return( Singleton || Constructor );
})();
@cawel
cawel / gist:8b564a9ab298486e3e96
Last active August 29, 2015 14:09
blog-the-good-parts
Function.method('bind', function(that) {
var method = this,
slice = Array.prototype.slice,
args = slice.apply(arguments, [1]);
return function() {
return method.apply(that, args.concat( slice.apply(arguments, [0])) );
};
});
my_proc = Proc.new do |e|
puts "this is #{e}"
end
my_proc.call(2)
my_proc.(2)
my_proc[2]
my_proc === 2
@cawel
cawel / gist:c1e4bc203ab33c95e607
Last active August 29, 2015 14:09
blog-proc2
def run_proc(p)
p.call
end
name = "Fred"
my_proc = proc { puts name }
name = "Marc"
run_proc my_proc
@cawel
cawel / gist:eb531f95a63510a5686d
Last active August 29, 2015 14:09
blog-nodejs
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');
class Robot
def move(&block)
instance_eval( &block )
end
def up;
puts “u“;
end
def down;
@cawel
cawel / gist:edffa2085b8c3a7a0de9
Created November 19, 2014 22:49
blog-quiz-intermediate
class A
attr_accessor :var
def method
var = 45
end
end
a = A.new
a.method
puts a.var
@cawel
cawel / gist:506cafa394afa170ef62
Created November 19, 2014 22:59
blog-quiz-easy-10
value = compute_value
value = (value > CONSTANT) ? value : CONSTANT
@cawel
cawel / gist:df6bec78bd0822ccf81c
Created November 19, 2014 23:05
blog-quiz-easy-9
require 'rubygems'
require 'fileutils'
puts File.expand_path(File.dirname(__FILE__))
FileUtils.mkdir 'test'
FileUtils.chdir 'test'
puts File.expand_path(File.dirname(__FILE__))
@cawel
cawel / gist:494fd7f4df8b4ab89fb7
Created November 19, 2014 23:11
blog-quiz-easy-8
hash = {:language => 'ruby', :author => 'martin'}
puts hash['language']