Skip to content

Instantly share code, notes, and snippets.

# a trick that makes class instances function instances and not object instances
# aka - callable objects. (expects object to have a 'call' function defined)
callable = (cls) ->
callable_cls = (...args) ->
obj = (...args) -> obj.call.apply obj, args
obj.__proto__ = cls::
cls.apply obj, args
obj

Keybase proof

I hereby claim:

  • I am leshy on github.
  • I am lesh (https://keybase.io/lesh) on keybase.
  • I have a public key whose fingerprint is 35DB 878B A6B8 69A8 EE4A B304 C5F7 4693 F248 EF57

To claim this, I am signing this object:

@leshy
leshy / extendEach.js
Created January 15, 2012 22:51 — forked from alassek/extendEach.js
Easy multiple-inheritance in Backbone.js
/*
multiple inheritance/mixins for backbone js
automatic init call to super classes and defaults attribute inheritance
clsbla = Backbone.Model.extend4000(cls1,cls2,mixin6,{ bla: 3 })
*/
(function () {
@leshy
leshy / graph.js
Created January 18, 2012 22:21
js backbone graph node - should I use a backbone collection?
var GraphNode = Backbone.Model.extend({
defaults: { parents: [], children: [], name: 'node' },
addparent: function(parent) {
if (!this.hasparent(parent)) {
this.get('parents').push(parent)
this.trigger('addparent',parent)
parent.addchild(this)
var self = this;
parent.bind('destroy',function() { self.removeparent(parent) } )
@leshy
leshy / export-testingfw.js
Created February 14, 2012 15:07
selenium ide custom export
function parse(testCase, source) {
}
function format(testCase, name) {
var result = 'ctx.local.c\n';
var commands = testCase.commands;
for (var i = 0; i < commands.length; i++) {
var command = commands[i];
if (command.type == 'command') {
jA0EAwMClATSOzNKOxfWye0ufjcE3QZOVIqVUaJ4SV3FLDXAd79AdO+Y1WufUo5k
7UxOedCqq3eLA0BXdZSTYqerQndbHbVS6T1JFmzKtDoHmvUZLy6Os7zIpShD66zO
jab/v++HY8wB78PRZOnLn2WKFrhrJV0SG7VDyqzcqwFPMbi+aMP3c0qV6A2PyqLI
VdItXLnSlVAGMwld30gvzTzZDUFR4q0WeSX3Ncxd1XWfo+Ja9GOxc+98r4WweYIR
yh4dKHV8OrVn1Hz81sZzwCRyoxPo5RjOxO3LY5GboULnrvtHn+EQfGzMmYfCDvw5
YyRDLtef6Myk2w7t/AuLA2hiifWjfwC1EoK1i/rUF3jZfkyzpRYPHAp25ai6Azqn
kSQi8EnJDyXBH4R4gVgVP8eNMRWgIJxqOUbG9ja8LrlOqR+VtD39x16UbN5lv7sW
697G4bsI+JPXRGTDe0PHAbBDGCtX+dR0SiFn2tzBFCQCD2DBQlY3L6FSpHPoRrDj
dLG4GdDU7YaZ+TaLK+0f+ymFcZOznkNkNtF9eH725MajLcIg9BOcNFnyVNGqYfW/
XqcrhMTlh2SDTqWj+xKZxDvcRUHrAbKudQRauQ7SH5dzVIipsBPd+SJJ3etiyJLB
@leshy
leshy / prompt.sh
Created June 5, 2012 03:05
fancy git bash prompt
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
function git_repo_name {
basename $(git rev-parse --show-toplevel)
}
function git_status {
@leshy
leshy / ai.md
Created November 8, 2012 22:18
answer to some questions about hard ai and rights
;flycheck livescript
(flycheck-define-checker livescript
"A Livescript syntax checker using livescript.
See URL `http://livescript.net/'."
:command ("livescript" "--compile" "--print" "--stdin")
:standard-input t
:error-patterns
((error line-start "[" (message) "on line " line "]" line-end))
:modes livescript-mode)
#!/bin/bash
# downloads all mp3 jwz mixtapes (1-75)
for i in `seq -f "%03g" 1 75`;
do
URL="https://archive.org/compress/jwz-mixtape-$i/formats=VBR%20MP3&file=/jwz-mixtape-$i.zip"
echo $URL
wget -c $URL
done
for z in *.zip