Skip to content

Instantly share code, notes, and snippets.

View RobertDober's full-sized avatar

Robert Dober RobertDober

  • Narbonne, France
View GitHub Profile
function! s:Ruby(l1,l2,fn)
exe a:l1 . ',' . a:l2 .'!ruby -n ' . a:fn
endfunction
command! -nargs=1 -range -complete=file Ruby call s:Ruby(<line1>,<line2>,<q-args>)
@RobertDober
RobertDober / cannonical_express_app.js
Created November 21, 2013 14:50
Canonial express app
var express = require('express');
var app = express();
app.get('/', function(req, res){
res.send('Hello World');
});
app.listen(3000);
@RobertDober
RobertDober / canonical_node_js.js
Last active December 28, 2015 23:59
Node.js code
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/');
@RobertDober
RobertDober / git_vs_hg.md
Last active December 27, 2015 09:29
Some musings about git vs. hg
# ...
SINATRA_ENV = ENV.fetch "SINATRA_ENV", "development"
# ...
DataMapper.setup :default, "sqlite3://#{File.expand_path("../db", __FILE__)}/bookmarx_#{SINATRA_ENV}.db"
# part of spec_helper.rb
ENV['SINATRA_ENV'] = 'test'
# ...
require 'database_cleaner'
# ...
RSpec.configure do | conf |
# ...
Dir.new("/tmp").each_path.to_a # ---> [ ["aaa", "/tmp/aaa"], ["bbb", "/tmp/bbb"], ... ]
# alternatively / additionally
Dir.each_path( "/tmp" ).to_a # ---> same result
@RobertDober
RobertDober / hexToInts.rb
Last active December 11, 2015 16:28
Converting a list of hex strings to ints incremented by one and adding them up
%{0x12 0x13 0x14}.split.map{ |x| x.to_i(16).inc }.inject(&:+)
%{0x12 0x13 0x14}.split.map(&sendmsg(:to_i, 16).and(sendmsg(:inc))).inject(&sendmsg(:+))
@RobertDober
RobertDober / open_hash_spec.rb
Created January 22, 2013 14:52
A summary Spec for OpenHash (for lab419/open_hash)
describe OpenHash do
let( :from_hash ){ {a: 42, b: 43} }
subject do
described_class.new from_hash
end
context "read access by both methds" do
it{ subject.a.should eq( 42 )}
it{ subject[:a].should eq( 42 )}
end
context "write access by both methods" do
(function() {
var a, aHash, b, putab;
putab = function() {
return console.log("a: " + a + ", b: " + b);
};
aHash = {
a: 1,
b: 2,