Skip to content

Instantly share code, notes, and snippets.

View c4urself's full-sized avatar

Christian Verkerk c4urself

  • Tubular Labs
  • Mountain View
View GitHub Profile
@c4urself
c4urself / traverse_object.js
Created December 5, 2012 21:13
Javascript querying object traversal
/**
* Returns a value or array of values by traversing the `object` using `path`
*
* @param object {Object}
* @param path {String}
* @returns value {String, Array}
*
* traverseObject({a: {b: [{c: {d: 'gotcha!'}}, {c: {d: 'yes!'}}]}}, 'a__b____c__d');
* --> ['gotcha!', 'yes!']
* traverseObject({a: {b: [{c: 'gotcha!'}, {c: 'yes!'}]}}, 'a__b____c');
@c4urself
c4urself / films.md
Created November 21, 2012 00:11
Films
@c4urself
c4urself / recursive_hide.js
Created October 5, 2012 20:33
Recursively hide a set of matched elements
// Self-calling named function which takes an array of elements
// calls an event on the first element in that array and passes
// the rest of the array to that function recursively until the
// array is empty. The recursive call is done in the callback of
// the previous element's event so that it nicely waits for the
// previous element to be done.
(function hidenext(jq) {
jq.eq(0).fadeOut("fast", function(){
@c4urself
c4urself / setup.py
Created October 5, 2012 17:30
Setup.py example
#!/usr/bin/env python
from distutils.core import setup
setup(name='Zachs script',
version='1.0',
description='Zach is the man',
author='Zach',
author_email='[email protected]',
packages=['mypackage'],
@c4urself
c4urself / prototyping_basic.js
Created October 5, 2012 17:18
Prototyping example
function Engineer () {}
Engineer.prototype = {
getYearsWorked: function () {
return this.yearsWorked;
}
};
function UIEngineer (years) {
this.yearsWorked = years;
@c4urself
c4urself / topnav.js
Created August 4, 2012 17:43
Topnav backbone view
define([
'jquery',
'underscore',
'views/abstractview',
'models/authentication',
'text!templates/navigation/topnav.html',
'text!templates/navigation/notauthenticated.html'
], function($, _, AbstractView, authModel, mainNavigationTemplate, notAuthenticatedTemplate){
var view = AbstractView.extend({
@c4urself
c4urself / email_backend.py
Created March 26, 2012 11:57
Django email
"""
This file enables email-based authentication for Django. The only steps required are
1. Add 'EmailAuthenticationBackend' to your settings' AUTHENTICATION_BACKENDS file
2. Add the {'authentication_form': EmailAuthenticationForm} to your login view (if using 'django.contrib.auth.views.login')
3. When saving a User instance, generate the username from the email using the 'generate_hash_from_email' function
"""
import hashlib
from django import forms
@c4urself
c4urself / abstractview.js
Created February 23, 2012 09:43
Abstract view for Backbone
define([
'jquery',
'underscore',
'backbone',
'mustache'
], function($, _, Backbone, Mustache){
var view = Backbone.View.extend({
model: null,
template: null,
@c4urself
c4urself / it_fib.py
Created February 17, 2012 23:17
Iterative fibonacci
def iterative(n):
if n == 0 or n == 1:
return n
prev2 = 0
prev1 = 1
for index in xrange(2, n + 1):
ivalue = prev1 + prev2
prev2 = prev1
prev1 = ivalue
if index == n: