Skip to content

Instantly share code, notes, and snippets.

View aclave1's full-sized avatar

Alex Clavelle aclave1

  • Meta
  • Bay Area, California
View GitHub Profile
@aclave1
aclave1 / EqualityStack.js
Last active August 29, 2015 13:55
Equality Stack
/**
Constructor function which keeps an array of objects, and makes sure they are all equal.
Used for checking consistency between many objects easily.
for example:
create a bunch of objects that should be exactly the same.
var data1 = object.serialize();
@aclave1
aclave1 / Synchronize.js
Created February 2, 2014 07:42
Javascript data synchronization
/**
Used to synchronize multiple types of storage and their timestamps.
options{
data : {}, the state that all storage should take.
date: int, the modified date that all storage should take
interval : int, sync interval in milliseconds.
callbacks : [], an ARRAY of callback functions which are to each be executed with data
and date as params. Each callback should be used to update a single storage medium.
}
@aclave1
aclave1 / Draggable.js
Created February 2, 2014 07:45
Simple Javascript draggable element
/**
Pass in a dom ID string or a dom node and to make it draggable.
*/
var Draggable = function(elem) {
var that = this;
var el = (typeof elem === 'string') ? document.getElementById(elem) : elem;
var offX, offY;
this.mouseDown = function(e) {
offX = e.clientX - parseInt(el.offsetLeft);
offY = e.clientY - parseInt(el.offsetTop);
@aclave1
aclave1 / ParticleGen.js
Created February 2, 2014 17:39
Simple Javascript particle Generator
/**
*
options:(OBJECT){
type : element type we're shooting.
x : x coordinate
y : y coordinate
color : color of element
}
*/
@aclave1
aclave1 / app.js
Last active August 29, 2015 14:04
Simplest possible node.js web server
var http = require('http');
var fileReader = require('fs');
http.createServer(function(req,res){
var path = __dirname+req.url;
fileReader.readFile(path,function(err,fl){
res.end(fl);
});
}).listen(8080);
@aclave1
aclave1 / PromiseMock.spec.js
Last active August 29, 2015 14:05
Unopinionated promise mocking
describe('An object which relies on promises', function () {
it('Should pass if provided the proper parameters', function () {
/**
* our real object would normally depend on promiseDependency,
* but we're replacing it with our mock promise chain here.
*/
sut.promiseDependency = PromiseMocks.ResolveMock();
var params = {
name : 'alex'
@aclave1
aclave1 / ngbootstrap
Created October 31, 2014 02:28
Angular bootstrapping snippet
angular.element(document).ready(function() {
angular.bootstrap(document, ['app']);
});
@aclave1
aclave1 / envocapplication.js
Last active August 29, 2015 14:09
job application for Envoc
var http = require('http');
var body = JSON.stringify({
Name:"OMITTED",
PhoneNumber: "OMITTED",
Email:"OMITTED",
Position:"Javascript Developer",
Urls:[
# Load balancer configuration
upstream exampleApp {
# Directs to the process with least number of connections.
least_conn;
# One failed response will take a server out of circulation for 20 seconds.
server 127.0.0.1:10080 fail_timeout=20s;
#server 127.0.0.1:10081 fail_timeout=20s;
#server 127.0.0.1:10082 fail_timeout=20s;
#server 127.0.0.1:10083 fail_timeout=20s;
@aclave1
aclave1 / directivebuilder.js
Last active August 29, 2015 14:17
A provider for a "directive builder". Inject this provider into a directive declaration and return its invocation and it will build a directive definition object. I got this idea from angular-ui-bootstrap's code here: https://github.com/angular-ui/bootstrap/blob/master/src/tooltip/tooltip.js#L12
module.exports = function () {
this.$get = [function () {
return function directiveBuilder(config) {
var options = config || {};
return {
replace: true,
restrict: "E",