Skip to content

Instantly share code, notes, and snippets.

@tgvashworth
tgvashworth / gist:5173950
Created March 15, 2013 23:18
Set value at string path of object
// Set a value at a string-designated path.
//
// Takes an object to be modified, a string path ('a.b') and a value to be set
// at that path.
//
// Returns the modified object (although the changes are made in place)
var set = function (obj, path, val) {
if (!obj || typeof obj !== "object") return obj;
if (!path || typeof path !== 'string') return obj;
var keys = path.split('.'),
// Recursively sum integer properties of an object
var sumObject = function (source, target) {
Object.keys(source).forEach(function (key) {
if (typeof source[key] === "object") {
if (!target[key]) target[key] = {};
target[key] = sumObject(source[key], target[key]);
}
if (typeof source[key] === "number") {
if (!target[key]) target[key] = 0;
target[key] += source[key];
/**
* Sandbox
*
* Use Backbone Events to create a generic event handler.
* http://backbonejs.org/#Events
*/
define([], function () {
return {
create: function (parent) {
@tgvashworth
tgvashworth / gist:5331538
Created April 7, 2013 17:44
Debounced callback
// Debouce a callback
var debounce = (function () {
// Save the previously used callbacks and timers
var cbs = [],
timers = [];
// When debounce is called, they're calling this function
return function (delay, cb) {
// Find or store this callback
var cbIndex = cbs.indexOf(cb);
@tgvashworth
tgvashworth / async-binary-insert.js
Last active December 15, 2015 22:19
Async Binary Insert
// Insert value into into array (via comparison cb) then call the done cb
var insert = function insert(item, arr, compare, done) {
if (!done) {
done = compare;
compare = false;
}
compare = compare || function (a, b, cb) { return cb(a < b); };
@tgvashworth
tgvashworth / .gitconfig
Last active December 13, 2022 14:15
.gitconfig & .gitignore
# A ~/.gitconfig file
[user]
name = YOUR NAME
email = YOUR EMAIL
[github]
user = YOUR USERNAME
token = YOUR TOKEN
[core]
quotepath = false
editor = nvim
@tgvashworth
tgvashworth / examples.js
Created April 21, 2013 20:21
Managing Modularity – Code Example
var myModule = (function () {
// Private
var name = "AsyncJS";
// Public
return {
getName: function () {
return name;
},
setName: function (value) {
return (name = value);
@tgvashworth
tgvashworth / gist:5478385
Last active December 16, 2015 18:29
local tld dreamcode/ideas
// Array
// pros:
// simple, no duplication of ports
// cons:
// a tld can be duplicated
{
6000: [
"api.name.dev",
"admin.name.dev"

Why?

Why are am I here? Why am I alive, on this planet, at this time?

A big question? No, a deepity. In one reading, truth. In another, nonsense.

The word ‘why’ can be taken in two ways: why meaning for what purpose did x happen; and why meaning how did x happen. Let's look at ‘why am I here?’ from both perspectives.

In the first sense, the question can be rewritten as ‘for what purpose am I here?’. In the second, ‘how is it that I came to be here?’.