Skip to content

Instantly share code, notes, and snippets.

View callmehiphop's full-sized avatar
👾

Dave Gramlich callmehiphop

👾
  • Detroit, MI
View GitHub Profile
var lastConnectionState;
var speed = 10000;
var endpoint = 'http://www.reddit.com/.json';
(function checkConnection () {
var xhr = new XMLHttpRequest();
var connectionState;
// probably better if we do not make this call async for a couple of reasons
@callmehiphop
callmehiphop / $switch.js
Last active August 29, 2015 14:01
death to all the switches!
function $switch (test, cases) {
function doit (thing) {
return (cases[thing] || cases['default'] || function () {})();
}
if (test && cases) {
return doit(test);
}
cases = test;
@callmehiphop
callmehiphop / crazycurry.js
Last active August 29, 2015 14:03
Super awesome functions!
// http://www.codewars.com/kata/539a0e4d85e3425cb0000a88/
function add (n) {
var next = add.bind(n += this | 0);
next.valueOf = function () {
return n;
};
return next;
@callmehiphop
callmehiphop / expect-type.js
Last active August 29, 2015 14:03
the worst idea imaginable
(function () {
'use strict';
var slice = Array.prototype.slice;
Function.prototype.expect = function expect () {
var argTypes = slice.call(arguments);
var functionToCall = this;
@callmehiphop
callmehiphop / example.js
Created July 10, 2014 20:12
A really weird way to inject dependencies with AngularJS
angular.module('test', []).controller('Test', inject([
'$scope',
'$http'
], function () {
'use strict';
this.$scope.wat = 'hallo';
@callmehiphop
callmehiphop / angular.expect-headers.js
Last active August 29, 2015 14:04
Convenience wrapper for testing HTTP headers
function expectRequest (method, url, data) {
var $httpBackend;
inject(function ($injector) {
$httpBackend = $injector.get('$httpBackend');
});
function withHeaders (expectedHeaders) {
return $httpBackend.expect(method, url, data, function (actualHeaders) {
for (var header in expectedHeaders) {
@callmehiphop
callmehiphop / example.js
Created July 23, 2014 20:22
Formats large array of numbers into a string showing any ranges within the original array
ranger([1,2,3,5,7,8,9]) // "1:3,5,7:9"
@callmehiphop
callmehiphop / preload.js
Created August 13, 2014 16:05
angular image preloader
angular
.module('preload', [])
.factory('preload', function ($q) {
'use strict';
function getImage (src, ignoreFailure) {
var defer = $q.defer();
var img = new Image();
var resolve = defer.resolve.bind(defer, img);
@callmehiphop
callmehiphop / example.js
Last active August 29, 2015 14:08
the worst idea ever!
var Thing = Weird.extend({
myProp: 'hello',
getMyProp: function () {
return myProp;
},
setMyProp: function (value) {
myProp = value;

BigTable

var bigtable = gcloud.bigtable();

getZones

bigtable.getZones(function(err, zones, apiResponse) {});