Skip to content

Instantly share code, notes, and snippets.

View davisford's full-sized avatar

Davis Ford davisford

View GitHub Profile
@davisford
davisford / promises.js
Created November 28, 2012 17:40
Promises
// with promise
app.controller('FooCtrl', ['$scope', 'rpc', function ($scope, rpc) {
var promise = rpc.exec('foo.get');
promise.then(
/* success */ function (foos) { console.log('got some foos', foos); },
/* failure */ function (err) { conosle.log('got an error', err); }
);
}]);
// without a promise
@davisford
davisford / 1.app.js
Created December 10, 2012 18:50
mocha + testacular + angular
/*global angular:false */
'use strict';
// this is the main angular application modeule
var app = angular.module('app', ['app.filters', 'app.services', 'app.directives', 'ui']).
config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
// setup routing
$routeProvider.when("/home", {
// represents a single home view
'use strict';
/*global describe, beforeEach, it, expect, chai, inject */
describe('controller tests', function () {
var $scope, $controller, assert = chai.assert,
expect = chai.expect,
should = chai.should();
@davisford
davisford / fooSpec.js
Created December 17, 2012 20:15
mocha.js + mongoosejs database test skeleton
var mongoose = require('mongoose');
mongoose.connection.on('error', function (err) {
console.log('mongoose err: ', err);
});
mongoose.connection.on('open', function () {
console.log('mongoose connection established');
});
int accel_spi_init()
{
if (bcm2835_init() != 1)
{
perror("Could not initialize BCM2835 library");
return -1;
}
// enable SPI for accelerometer
@davisford
davisford / gist:4685670
Created January 31, 2013 19:32
Get SublimeClang working on Linux + Sublime Text 2

Instructions here are not great.

First shut down ST2.

Make sure you use absolute paths for symlink:

e.g.

$ curl -kL http://xrl.us/pythonbrewinstall | bash
$ source "$HOME/.pythonbrew/etc/bashrc"
@davisford
davisford / demo.js
Last active December 14, 2015 00:29
var app = angular.module('app', []);
// service to fetch data
app.factory('Service', ['$rootScope', function ($rootScope) {
var Data = {}, intervalId;
return {
data: Data,
@davisford
davisford / gist:5039064
Last active February 9, 2022 13:39
git clone into non-empty directory

Let's say you start a project locally, and do some editing.

$ mkdir -p ~/git/foo && cd ~/git/foo
$ touch NEWFILE

Now you decide you want to create a new github repo and track it, but the directory is non-empty so git won't let you clone into it. You can fix this, thusly:

@davisford
davisford / app.js
Last active December 16, 2015 02:48
AngularJS promise problem on embedded device w/WebKit. The problem I am seeing is that a call to `deferred.resolve( )` does not end up reaching the promise's `then(fn, fn)` success callback function. Sometimes it does, but sometimes it disappears into the ether, and I can't figure out why. There is a global Angular exception handler which is not…
// error handling is all trapped with window.onerror; I also override Angular $exceptionHandler which both
// post back to the remote logger service. I have also inserted try/catch blocks in the code below which
// never gets into the catch block; net summary: I am not seeing any erorr thrown which would be the root
// cause of this issue.
(function () {
var app = angular.module('app');
/**
@davisford
davisford / gist:5877879
Created June 27, 2013 16:21
Checking out Chromium source
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
export PATH="$PATH":`pwd`/depot_tools
mkdir chromium && cd chromium
fetch chromium --nosvn=True
fetch blink --nosvn=True # skip if you don't want blink
fetch android --nosvn=True # skip if you don't want android