Skip to content

Instantly share code, notes, and snippets.

@brianmhunt
brianmhunt / gist:4365815
Last active December 10, 2015 02:09
A CasperJS wrapper for remote jQuery calls (untested)
class jQueryCasperWrapper
constructor: (@selector) ->
wrappedMethods = ['data', 'visible'] # ... plus all the other jQuery functions being wrapped
_.each(wrappedMethods, (method) => # lodash/underscore foreach -- just from my own preferences
wrapper = (args...) => @RemotejQuery(method, args)
@[method] = wrapper
)
RemotejQuery: (methodName, args) ->
@brianmhunt
brianmhunt / gist:4413209
Last active December 10, 2015 09:18
An extension called 'recipe' that goes in place of the `task` function of Cakefiles. The `recipe` function emits events "taskname.start" and "taskname.complete". It also facilitates other events, on demand.
events = require('events')
recipe = (id, description, action) ->
# `recipe` wraps the Cake `task` command but fires a events through 'recipe'.
#
# One can listen for an event with `recipe.on('event_name', callback)`, and
# call that event with `recipe.emit('event_name', args)`.
#
# If `action` takes two arguments, the second argument is presumed to be a
# `done` callback. The presence of this callback makes the recipe
@brianmhunt
brianmhunt / pickadate-ko-binding.coffee
Last active December 16, 2015 19:10
Knockout binding for amsul/pickadate.js
# This is just a stub variable to keep track of multiple bindings.
# One could just have the bindings.date below directly link to
# ko.bindingHandlers, but then you would have to update the unit tests.
bindings = {}
# This gist depends on the inclusion of libraries:
#
# lodash (or underscore): http://lodash.com
# Used for _.isEqual, _.isDate, _.isString, _.defer
#
@brianmhunt
brianmhunt / gist:5512916
Last active December 16, 2015 23:19
A way to walk a namespace with a string in Coffeescript/Javascript; requires lodash/underscore
#
# Deep pluck
# ~~~~~~~~~~
# Pull a deeply nested element out based on an array of arguments
#
# e.g. array['abc'][0] == deepPluck(array, ['abc', 0])
#
deepPluck = (obj, array_or_string, _default=undefined) ->
if _.isString(array_or_string)
keys = array_or_string.split('.')
@brianmhunt
brianmhunt / flask-session-test.py
Created May 13, 2013 18:01
A substantial attempt at replicating an issue with the unit testing of Flask sessions
import os
import sys
import logging
import unittest
from pdb import set_trace
from google.appengine.ext import testbed
from flask import Flask, session
app = Flask('fs')
@brianmhunt
brianmhunt / credentials.py
Created January 25, 2014 19:09
Storing passwords using Python (on Google App Engine)
import Crypto.Random
from Crypto.Protocol import KDF
from google.appengine.ext import ndb
from datetime import datetime
class Credentials(ndb.Model):
"""Credentials to authenticate a person.
"""
# --- Class Variables ---
# Our pseudo-random stream - used for generating random bits for the
@brianmhunt
brianmhunt / models.py
Last active December 3, 2015 19:01
tags for ndb on Google App Engine / Python
"""
From blog post: http://brianmhunt.github.io/articles/ndb-tags/
License: MIT <http://brianmhunt.mit-license.org/>
"""
from google.appengine.ext import ndb
MAX_TAGS_FOR_TAGGABLE = 1000
POPULAR_PAGE_SIZE = 30
@brianmhunt
brianmhunt / b-b.coffee
Last active August 29, 2015 14:09
Browserify transforms not working with paths
# << Any invalid Javascript character.
module.exports.hereiam = ->
console.log("0xDEADBEEF")
@brianmhunt
brianmhunt / trepid.py
Created January 3, 2015 20:27
Human UX strings mapping
"""
Human UX strings mapping
See http://stackoverflow.com/a/27459196
0 1 2 3 4 5 6 7 8 9 A B C D E F Hexadecimal
H M N 3 4 P 6 7 R 9 T W C X Y F Replacement
Y = U = V
C = G
@brianmhunt
brianmhunt / README.md
Last active August 29, 2015 14:25
MWE re. karma-browserify#137

Run npm install then gulp &amp;&amp; karma start to try out the tests.