Skip to content

Instantly share code, notes, and snippets.

<form action="your-action.lang" method="POST">
<script
src="https://my.tok3n.com/v1/embed.js" class="your-class"
data-publicKey="dOcPsnXndcRw3QdIosnE0j"
data-userKey="Ngfl6Gn2q15g8mR28vi2no"
data-theme="default"
data-action-name="Login"
data-app-name="Demo Site">
</script>
<input type="submit" />
@bttmly
bttmly / prototype-chain.js
Created March 27, 2014 21:28
Get the prototype chain of an object.
var prototypeChain = function( o ) {
prototypes = [];
while ( o = Object.getPrototypeOf( o ) ) {
prototypes.push( o )
}
return prototypes;
}
@bttmly
bttmly / collection-styles.coffee
Created March 28, 2014 02:54
Two ways of structuring Controls.js collection classes.
# uses dummy elements to listen for/dispatch events
class ControlCollectionA extends Array
constructor : ( arr ) ->
this.push( item ) for item in arr
this.el = document.createElement "dummy"
on : ( eventType, handler ) ->
thisEl = this.el
thisEl.addEventListener eventType, handler.bind( this ), false
@bttmly
bttmly / compose.coffee
Last active August 29, 2015 14:01
Function to compose a class from other classes.
compose = do ->
each = ( obj, itr ) ->
list = if Array.isArray( obj ) then obj.map ( e, i ) -> i else Object.keys( obj )
i = 0
while i < list.length
itr( obj[ list[i] ], list[ i ], obj )
i += 1
obj
var getPrototypeChainOf = function( obj ) {
var chain = [];
if ( isFunction(obj) ) {
obj = obj.prototype;
} else {
obj = obj.constructor.prototype;
}
do {
@bttmly
bttmly / curry-compose.js
Last active August 29, 2015 14:02
Curry and compose for functional programming.
// adapted from:
// http://javascriptweblog.wordpress.com/2010/04/05/curry-cooking-up-tastier-functions/
// http://javascriptweblog.wordpress.com/2010/04/14/compose-functions-as-building-blocks/
function curry( fn ) {
if ( arguments.length < 2 ) {
return fn;
}
var args = [].slice.call( arguments, 1 );
return function() {
var compose = function compose(f) {
var queue = f ? [f] : [];
var fn = function fn(g) {
if (arguments.length) {
queue.push(g);
return fn;
}
return function() {
var args = Array.prototype.slice.call(arguments);
queue.forEach(function(func) {
var first = (function() {
var chainNames = ["then", "andThen", "next"];
var endChainNames = ["finally", "andFinally", "last"];
var chain = function(fn) {
var f1 = function(g) {
var func = function() {return g.call(this, fn.apply(this, arguments));};
chain(func);
return func;
};
var f2 = function(g) {
@bttmly
bttmly / README.md
Last active August 29, 2015 14:03
workers-execution-contex

Download the files, run them on a local server (python -m SimpleHTTPServer works fine), and open up index.html.

@bttmly
bttmly / makeORMClass.coffee
Last active August 29, 2015 14:03
HR ORM Example
pairs = ( obj ) ->
arr = []
for own key, val of obj when key isnt "id"
arr.push "#{ key }=#{ val}"
arr.join ","
makeORMClass = ( table ) ->
# CoffeeScript syntactic sugar for class creation.
class Model