Skip to content

Instantly share code, notes, and snippets.

@tgvashworth
tgvashworth / gist:3532070
Created August 30, 2012 16:14
Asynchronous Basehold.it code
<script>
(function(d,t){
var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
g.href='//basehold.it/24';
g.rel='stylesheet';
s.parentNode.insertBefore(g,s)
}(document,'link'));
</script>
@tgvashworth
tgvashworth / gist:3559121
Created August 31, 2012 21:15
Watch the app.net global stream for annotations
/*
Note: this was hacked together _very_ fast. It's probably wrong, stupid,
broken, idiotic and generally useless.
To use: stick this in app.js & npm install request
*/
var request = require('request')
, url = require('url')
console.log("Hello, test");
@tgvashworth
tgvashworth / gist:4020664
Created November 5, 2012 21:59
Angular & Ace

I'm building an app using Angular that involves using the Ace editor. What I'd like to do is be able to create and editor & control a select few element of Ace's API in an Angular-like way. ie:

<div ng-controller="AceCtrl">
  <ace-editor mode="html" ng-model="code" ng-change="do_stuff()"></ace-editor>
</div>

And have that construct an Ace instance with observable properties.

[color]
diff = auto
status = auto
branch = auto
ui = true
[help]
autocorrect = 1
[mergetool]
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDL8wZcK7Jd4dPbOhInow1qbJ8zd+KTmm5Fc0BcYkKy6hFshXnrZtXqJGauXQwUCc7Z+9Nz8eEqUL1eB0PtHfBhRGDxFTfUAKtUmLfAaT3ePqOROvXVIXTiCFA9uof2YNcv+wAzrg81h0nHtmGxMrB/tyNuDDqwZHhD+my6xmfZxv5Y3o8GygF+mDIYaoOzpDONrRDprC7tdia+BFUXTpUd4JmGllCZko/3RFhsywS27OBDMwrPLe6UCRZizayJnLUHtlBU789m60afSx2O4xTVyBXE/qEPFSYW1RdsedQ1mdx5vcKJolrY5BBcaicHRVyi1QPIPc3IKJeMHJrPlZaz tashworth@twitter.com
@tgvashworth
tgvashworth / gist:4582024
Created January 20, 2013 21:50
nick cdnjs
var https = require('https');
var find_by = function (key, search, array) {
var matches = [];
array.some(function (item) {
if( item[key] ) {
if( (''+item[key]).toLowerCase().indexOf(search) !== -1 ) {
matches.push(item);
}
}
@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) {