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 / 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='zach@zach.com',
packages=['mypackage'],
@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 / films.md
Created November 21, 2012 00:11
Films
@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 / jira_importer.rb
Created December 28, 2012 22:43
GitHub to Jira importer
require 'octokit'
require 'csv'
require 'date'
# Description:
# Exports Github issues from one or more repos into CSV file formatted for import into JIRA
# Note: By default, all Github comments will be assigned to the JIRA admin, appended with
# a note indicating the Github user who added the comment (since you may not have JIRA users
# created for all your Github users, especially if it is a public/open-source project:
#
@c4urself
c4urself / mocha_jslint_happy.js
Created January 3, 2013 18:17
Chai doesn't play nice with JS Lint's check for incorrect use of `false` and `true` -- a setting that cannot be turned off via JS Lint options. The addition of `_true` and `_false` properties to Chai fixes this making JS Lint work correctly.
// We're providing some convenience functions here as well as making sure
// chai tests don't fall on jshint errors by remapping true/false properties
chai.Assertion.addProperty('_true', function () {
this.assert(
true === this.__flags.object,
'expected #{this} to be true',
'expected #{this} to be false',
this.negate ? false : true
);
});
@c4urself
c4urself / reference_by_value.js
Last active December 10, 2015 19:58
Javascript (mainly) pass-by-value
// More explicit example of
// http://stackoverflow.com/questions/518000/is-javascript-a-pass-by-reference-or-pass-by-value-language
//
// When you change the `item` property of the object referenced by `obj1`, you are changing the value
// of the `item` property that was originally set to 'unchanged'. When you assign `obj2` a value of
// {item: 'changed'} you are changing the reference to a new object. This object immediately goes out
// of scope when the function exits.
function changeStuff(_num, _obj1, _obj2) {
_num = _num * 10;
@c4urself
c4urself / raphael_svg_fix.js
Last active December 10, 2015 22:08
A function that moves a path -- has the nice side-effect of making SVG paths with different starting points behave the same way.
/**
* Move path method // hack for getting all svg icons
* working the same way
*/
var movePath = function (x, y) {
var path = Raphael.pathToRelative(this.attrs.path),
dim = Raphael.pathBBox(this.attrs.path),
dx = (path[0][1] - dim.x) + (x * 100),
dy = (path[0][2] - dim.y) + (y * 100);
path[0][1] = dx;
na.iconCreator = function (x, y, width, height, iconName, hoverTitle, sstr) {
var p = this.properties,
dim = this.wrapper.getBBox(),
wx = _.isFunction(x) ? x(dim) : x, wy = _.isFunction(y) ? y(dim) : y,
r = this.paper.rect(wx, wy, width, height),
i = this.paper.path(na.icons[iconName]);
set = this.paper.set();
tstr = (sstr || 'S0.05,0.05,0,0') + 'T' + wx + ',' + wy;
// This is a hack to get all icons doing the same thing