Skip to content

Instantly share code, notes, and snippets.

View darkone23's full-sized avatar
💭
💾☠🕸

0/∞ darkone23

💭
💾☠🕸
View GitHub Profile
@darkone23
darkone23 / minimalist-classes.js
Created December 20, 2011 06:46 — forked from BrendanEich/minimalist-classes.js
less minimalism, richer leather
// A response to jashkenas's fine proposal for minimalist JavaScript classes.
// Harmony always stipulated classes as sugar, so indeed we are keeping current
// JavaScript prototype semantics, and classes would only add a syntactic form
// that can desugar to ES5. This is mostly the same assumption that Jeremy
// chose, but I've stipulated ES5 and used a few accepted ES.next extensions.
// Where I part company is on reusing the object literal. It is not the syntax
// most classy programmers expect, coming from other languages. It has annoying
// and alien overhead, namely colons and commas. For JS community members who
~~~~~~~~~~~~~~~~~~~~
a one-line code block
~~~~~~~~~~~~~~~~~~~~
~~~~{lang}
codeFromLang();
~~~~
~~~~{python}
var hello = 'world'
@darkone23
darkone23 / tryme-test.clj
Created August 16, 2012 02:33
A simple functional test-runner in clojure (unit tests only)
(ns tryme.core)
(defn run-test
"Given a test sequence, runs the test and returns a result object"
[[name function input expected]]
(try
(let [actual (apply function input)]
(if (= expected actual)
{:type :success :name name}
{:type :failure :name name :expected expected :actual actual}))
@darkone23
darkone23 / tmpl-settings.js
Created September 20, 2012 01:51
Mustache style tags in underscore
_.templateSettings = {
evaluate : /\{\%([\s\S]+?)\%\}/g, // {% eval(js); %}
interpolate : /\{\{([\s\S]+?)\}\}/g // {{ interpolate }}
};
@darkone23
darkone23 / HelloIsolate.dart
Created November 20, 2012 03:39 — forked from adam-singer/HelloIsolate.dart
Hello world using new dart:isolate
#!/usr/bin/env dart
#import('dart:isolate');
isolateCode() {
isolate.port.receive((msg, reply) => reply.send("re: $msg"));
}
void main() {
isolate.SendPort sendPort = isolate.spawnFunction(isolateCode);
@darkone23
darkone23 / utilities.js
Last active December 9, 2015 19:18 — forked from oojacoboo/utilities.js
using a closure so middleware no longer requires currying
$.fn.setupFilterInput = function (events) {
var $input = $(this),
handlers = {
// use these to provide default but overwriteable functionality
focus: function () {},
blur: function () {},
keyUp: function () {},
click: function () {}
},
middleware = {
@darkone23
darkone23 / gist:4488312
Created January 8, 2013 21:52
underscore.bind as partial application
var add = function(a, b) {
return a + b;
};
add(20, 30); // 50
// Twenty is so special for our use case that we want it to always be included
var addTwenty = _.bind(add, {}, 20);
//fn, this, args...
render: function(){
this.collection.each(console.log);
},
@darkone23
darkone23 / bootstrap.bash
Last active December 11, 2015 20:39
Bootstrap a sudoless python 2.4 environment to support ansible via the ansible_python_interpreter var
#!/bin/sh
# invoke like: ./bootstrap <somehost> -u <someuser>
# all invocation time flags will be forwarded to ansible
# don't specify module or args
# pulls down simplejson to $HOME/.ansible/deps
# creates a new ansible_python_interpreter located at $HOME/.ansible/bin/python usable by anyone on the box
ansible -m raw $@ -a 'mkdir -p $HOME/.ansible/deps && \
curl http://pypi.python.org/packages/source/s/simplejson/simplejson-2.1.0.tar.gz | \
@darkone23
darkone23 / promptless_playbook.py
Created January 31, 2013 19:50
Use python expect to forward ssh and sudo password to ansible-playbook. This allows the password to be a parameter of the script invocation Because of the plaintext password it is probably wisest to use this as a subprocess instead of directly from the shell
#!/usr/bin/env python
import pexpect
import sys
PASS_PARAM = "-p"
def usage():
print "./promptless_playbook %s <PASSWORD> <PLAYBOOK_ARGS...>" % PASS_PARAM
print "example: ./promptless_playbook playbooks/myplaybook.yml -p Hax0r32 -u coolguy -u sudo_role -e 'foo=bar'"