Skip to content

Instantly share code, notes, and snippets.

@florian
florian / README.md
Created November 17, 2018 10:20
Quine

Notes:

  • Using heredocs made it easier to write the quine. In Python the same approach would've required a lot more escaping quotes
  • New lines would make the code more readable. I didn't bother because ignoring that makes the quine slightly simpler and shorter
@florian
florian / index.js
Created March 20, 2016 12:43
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);
@florian
florian / index.js
Created March 20, 2016 12:41
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);
@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);
@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 / 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 / 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);
});
}
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 / 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
@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