Skip to content

Instantly share code, notes, and snippets.

View callmehiphop's full-sized avatar
👾

Dave Gramlich callmehiphop

👾
  • Detroit, MI
View GitHub Profile
@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 / 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 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 / 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 / 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 / $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;
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
import BaseHTTPServer, SimpleHTTPServer
import ssl
httpd = BaseHTTPServer.HTTPServer(('localhost', 4443), SimpleHTTPServer.SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket (httpd.socket, certfile='path/to/localhost.pem', server_side=True)
httpd.serve_forever()