Skip to content

Instantly share code, notes, and snippets.

@florian
florian / chainable_canvas.js
Created April 7, 2012 13:23
A small script that makes it possible to chain the HTML5 canvas methods. Pretty much a smaller version of chainvas: http://leaverou.github.com/chainvas/
(function(){
var c = window.CanvasRenderingContext2D.prototype,
wrapFn = function (method) {
return function () {
var ret = method.apply(this, arguments);
return ret === undefined ? this : method;
};
};
@florian
florian / README.md
Created April 23, 2012 18:48
getting the type or constructor of a value

Usage

Getting the data type or constructor:

type("some string"); // 'string'
type(42); // 'number'
type(true); // 'boolean

Checking for a data type or constructor:

@florian
florian / usage.rb
Created September 1, 2012 17:39
String#word_wrap for Ruby
text = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam"
puts text.word_wrap(40)
# Lorem ipsum dolor sit amet, consetetur
# sadipscing elitr, sed diam nonumy eirmod
# tempor invidunt ut labore et dolore
# magna aliquyam
@florian
florian / silent.sh
Created November 15, 2012 19:23
Execute a bash command without output
# OK, so I'm terrible at bash and the code below might be terrible, too, but it does the work for me. :3
function silent {
echo $* | sh >/dev/null 2>&1
}
# Usage:
silent echo hai world
silent make server
@florian
florian / mixin.coffee
Created December 8, 2012 19:24
A mixin implementation for CoffeeScript
Function::extend = (mixin) -> @[key] = value for key, value of mixin
Function::include = (mixin) -> @::[key] = value for key, value of mixin
RuntimeError - oops:
/home/florian/tmp/btr_errs/app.rb:10:in `block in <top (required)>'
/home/florian/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:1265:in `call'
/home/florian/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:1265:in `block in compile!'
/home/florian/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:835:in `[]'
/home/florian/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:835:in `block (3 levels) in route!'
/home/florian/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:851:in `route_eval'
/home/florian/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:835:in `block (2 levels) in route!'
/home/florian/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:872:in `block in process_route'
/home/florian/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:870:in `catch'
@florian
florian / sleepsort.js
Created October 19, 2014 11:53
JavaScript sleepsort
function sleepsort (A) {
A.forEach(function (v) {
setTimeout(function (v) {
return function () {
console.log(v);
}
}(v), v);
});
}
@florian
florian / quora-profile-sort-by-upvotes.js
Last active March 18, 2016 16:16
Quora user profile: Sort answers by upvotes
// We need this method because Quora displays 1500 upvotes as "1.5k"
function parseUpvotes (str) {
if (match = str.match(/(\d+)\.(\d+)/)) {
return Number(match[1]) * 1000 + Number(match[2]) * 100
} else {
return parseInt(str, 10)
}
}
function sortByUpvotes () {
@florian
florian / index.js
Last active March 20, 2016 12:36
requirebin sketch
React = require('react');
ReactDOM = require('react-dom');
ShortcutChooser = require('react-shortcut-chooser');
function callback (newValue, oldValue) {
console.log("Changed from %s to %s", oldValue, newValue);
}
ReactDOM.render(React.createElement(ShortcutChooser, { onChange: callback }), document.getElementById('app'));
@florian
florian / index.js
Last active March 20, 2016 12:40
requirebin sketch
React = require('react');
ReactDOM = require('react-dom');
ShortcutChooser = require('react-shortcut-chooser');
function callback (newValue, oldValue) {
console.log("Changed from %s to %s", oldValue, newValue);
}
ReactDOM.render(React.createElement(ShortcutChooser, { onChange: callback }), document.body);