Skip to content

Instantly share code, notes, and snippets.

View pluma's full-sized avatar
👋
Looking for projects

Alan Plum pluma

👋
Looking for projects
View GitHub Profile
@pluma
pluma / knockout.tasty.js
Created July 10, 2012 07:41
Knockout->Tastypie Resource classes
define(['ko', 'q-reqwest', 'q-tils', 'aug'], function(ko, qr, qt, aug) {
"use strict";
function propertyGetter(name) {
return function(obj) {
var prop = obj[name];
return (typeof prop === 'function' ? prop.call(obj) : prop);
}
}
function propertyFilter(name, value) {
@pluma
pluma / vagrant_aliases.sh
Last active December 16, 2015 22:59
Bash functions I found useful when working with multiple vagrant projects.
_vagrant_dirnames() {
if [[ $COMP_CWORD > 1 ]]; then
COMPREPLY=()
return 1
fi
local cur="${COMP_WORDS[COMP_CWORD]}"
pushd ~/vagrant/ > /dev/null
local opts=( $cur*/ )
popd > /dev/null
if [[ "$opts" == "$cur*/" ]]; then
@pluma
pluma / xmldicts.py
Last active December 20, 2015 16:49
from lxml import etree
def node_from_dict(tag, data=None):
node = etree.Element(tag)
if isinstance(data, dict):
for key, value in data.items():
if isinstance(value, list):
for v in value:
node.append(node_from_dict(key, v))
@pluma
pluma / golem.js
Last active December 26, 2015 21:28
ES-harmony multiple inheritance.
require('harmony-reflect');
var uniq = require('uniq');
var arrp = Array.prototype;
function merge(obj, src) {
Object.keys(src).forEach(function(name) {
var value = src[name];
if (obj.hasOwnProperty(name)) {
merge(obj[name], value);
} else {
@pluma
pluma / delegating.js
Last active December 26, 2015 21:39
Slate-like object property delegation. With appologies to Sorella on FreeNode ##javascript.
require('harmony-reflect');
var uniq = require('uniq');
var arrp = Array.prototype;
function ext(obj) {
var sources = arrp.slice.call(arguments, 1);
sources.forEach(function(src) {
src && Object.keys(src).forEach(function(name) {
obj[name] = src[name];
});
@pluma
pluma / node-stability.md
Last active January 4, 2016 04:38
Node stability index badges using buckler.repl.ca
[![stability 0 - deprecated](http://b.repl.ca/v1/stability-0_--_deprecated-red.png)
](http://nodejs.org/api/documentation.html#documentation_stability_index)

stability 0 - deprecated

var DuplexStream = require('readable-stream').Duplex,
// A duplex stream is a combination of a read stream and a write stream
// For more on streams see http://nodeschool.io/#stream-adventure
util = require('util')
// The "util" module contains several node core utilities.
// In this case we're just using its inheritance helpers.
// See http://nodejs.org/api/util.html for API docs.
function BufferList(callback) {
// In JavaScript it is common to indicate that a function is a constructor by
@pluma
pluma / smart-transform.js
Created September 30, 2014 18:26
Smarter version of `omit` and `pick` that can handle prop paths including wildcards and escaping (with backslash).
var wildcard = typeof Symbol === 'undefined' ? true : Symbol.for('wildcard');
function _tokenize(key) {
var tokens = [];
for (var i = 0; i < key.length; i++) {
var token = '';
if (key[i] === '*' && (i + 1 >= key.length || key[i + 1] === '.')) {
tokens.push(wildcard);
i++;
continue;
@pluma
pluma / webapp
Created October 15, 2014 15:47
Node init.d script with naught.
#!/bin/bash
NAME=webapp
IPC=/var/run/naught/$NAME.ipc
DESC="my application server"
WORKERS=2
set -e
case "$1" in
start)
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Tree</title>
<style id="jsbin-css">
.tree {
width: 400px;
margin: 15px 0;
}