Getting the data type or constructor:
type("some string"); // 'string'
type(42); // 'number'
type(true); // 'boolean
Checking for a data type or constructor:
(function(){ | |
var c = window.CanvasRenderingContext2D.prototype, | |
wrapFn = function (method) { | |
return function () { | |
var ret = method.apply(this, arguments); | |
return ret === undefined ? this : method; | |
}; | |
}; |
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 |
# 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 |
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' |
function sleepsort (A) { | |
A.forEach(function (v) { | |
setTimeout(function (v) { | |
return function () { | |
console.log(v); | |
} | |
}(v), v); | |
}); | |
} |
// 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 () { |
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')); |
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); |