Skip to content

Instantly share code, notes, and snippets.

View apiv's full-sized avatar

Austin Pivarnik apiv

View GitHub Profile
/* the function */
fib = (x) ->
if x < 2
x
else
fib(x-1) + fib(x-2)
/* test it out */
solutions = []
for number in [0..10]
@apiv
apiv / Simple and Flexible Base View Class in Coffescript
Last active February 11, 2017 20:13
This is a simple coffeescript class that provides a flexible platform for creating interactive views; much like BackboneJS, although library-independent. TODO: use the document.querySelector for setup elements and event binding. querySelector can be implemented easily on browsers that don't include native support.
###
Helper functions
###
###
@function {getElementsByDataEl}: find and return elements by data-el attribute
@param {parent}: the DOM node to search through
@param {elements}: Array of data-el values to find
###
@apiv
apiv / Coffeescript: Measure Depth of Binary Tree
Created January 9, 2013 02:15
A simple process to measure the depth of a binary tree, using the recursive method
###
Here is a representation of a simple binary tree,
to illustrate the idea of using a self-calling function
to measure the length of a binary tree.
###
nodeMap = [
[
[
[
@apiv
apiv / backbone.grouped_collection.js.coffee
Last active August 29, 2015 14:08
A rough write-up of Backbone.GroupedCollection
class Backbone.Group extends Backbone.Model
constructor: ->
@childCollection = new Backbone.Collection
super
class Backbone.Grouped extends Backbone.Model
## Override Me
childGroupBy: (model)->
@apiv
apiv / migrate.js
Created September 2, 2015 19:37
Simple gulp task for migrating to new version of jspm
/**
* Paths ending with / are no longer valid
*/
gulp.task('migrate:jspm', function () {
gulp.src('src/**/*.js')
.pipe(replace(/[a-z\-_0-9]*\/'/gi, function (match) {
return match.substr(0, match.length - 1) + match.substr(0, match.length - 2) + '\'';
}))
.pipe(gulp.dest('src'))
});
@apiv
apiv / async-experiment.js
Created September 5, 2015 20:51
Experiment with running concurrent processes with async.js, and writing dynamic log information to the terminal
var async = require('async');
require('colors');
var CONCURRENCY = 5;
var S_BUILDING = ' Building '.bold;
var S_BUILT = ' Built '.green.bold;
function buildIt() {
console.log("Starting process with concurrency of ", CONCURRENCY);
@apiv
apiv / pc.js
Created September 10, 2015 01:42
Simple SystemJS plugin for paperclip
# jspm install paperclip
import {transpile} from 'paperclip/lib/parsers/default/transpiler';
export function translate(load) {
return 'module.exports = ' + transpile(load.source) + ';';
}
@apiv
apiv / wut.js
Created September 11, 2015 13:46
import view from './view';
function myModuleView(viewModel) {
const config = {
model: viewModel,
template: tmpl,
...
}
return view(config);
@apiv
apiv / reduce-obj.js
Created September 15, 2015 19:18
Reduce function for an object
function reduceObject(obj, fn, init) {
return Object.keys(obj).reduce(function (accum, key) {
return fn(accum, obj[key], key, obj);
}, init);
}
// usage
var obj = {
a: [1,2,3],

I'll expand this readme soon... but, you get the point, right?

decorator helper - Returns a function that allows you to invoke the decorator function to pass options to before applying the decorator to the property/method.

type option in property decorator - Will coerce the html attribute's value to the type specified when setting from an attribute.

Initializer support - Supports ES7 initial values.