Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am justinwinslow on github.
  • I am jwin (https://keybase.io/jwin) on keybase.
  • I have a public key whose fingerprint is 465E 9D17 019E 4F5C DE28 6E15 AC1A DB8F BAE2 D3DC

To claim this, I am signing this object:

@justinwinslow
justinwinslow / gist:9b9629ea7221ec08b177
Created December 13, 2014 07:01
localStorage in angular
// Grab or create stored data
$scope.localData = JSON.parse(localStorage.getItem('localData')) || {};
// Watch for items to change and update data in localStorage
$scope.$watch('localData', function(localData, oldLocalData){
if (localData != oldLocalData) {
localStorage.setItem('localData', JSON.stringify($scope.localData));
}
}, true);
@justinwinslow
justinwinslow / ngRepeatTimer.js
Last active August 29, 2015 14:26
Simple ng-repeat rendering timer
angular.module('someModule', [])
.directive('ngRepeatTimer', function() {
var start;
return function(scope) {
if (scope.$first) {
start = new Date().getTime();
}
if (scope.$last){
console.log('ng-repeat rendering time:', new Date().getTime() - start);
}
@justinwinslow
justinwinslow / ngHttpDedupe.js
Created August 14, 2015 20:49
Angular - Prevent duplicate $http GETs from firing at the same time
$provide.decorator('$http', ['$delegate', function($delegate) {
// Angular injects the service as $delegate
var $http = $delegate;
// Store promises for requests
var pendingRequests = [];
// Let's overwrite the get method to prevent duplicate queries
$http.get = function (url, config) {
config = config || {};
// Let's make a simple key for us to reference on subsequent requests
@justinwinslow
justinwinslow / gist:4088942
Created November 16, 2012 16:55
Split module pattern
/*
DIRECTORY STRUCTURE
module1.js
module2.js
module2/
- model.js
- view1.js
- view2.js
@justinwinslow
justinwinslow / Constructors, apply and call
Created May 25, 2013 20:38
Example of public/private properties in constructors and the difference between apply/call
//New constructor
var cons = function(){
var property_private = 'bye';
this.property_public = 'see ya';
//Instead of returning this, return only what needs
//to be accessible
return {
property_public: this.property_public,
method_public: function(){
Timeseries format
{
device_legend: [device1, device2],
data_legend: [[dataType1, dataType2], [device2_dataType1]],
data: [
{
x: timestamp,
y: [
[
@justinwinslow
justinwinslow / gist:5861694
Created June 25, 2013 19:40
Dev Tools Magic Sauce
//Log events fired on given DOM element
monitorEvents(elem);
unmonitorEvents(elem);
//See a trace of how we reached this line.
console.trace();
//Performance timing
console.time('Timer');
console.timeEnd('Timer');
@justinwinslow
justinwinslow / gist:5882743
Created June 28, 2013 05:57
Baseline node.js nginx configuration
# Add multiple servers at different ports for load balancing
upstream node {
server 127.0.0.1:3005;
}
# the nginx server instance
server {
listen 0.0.0.0:80;
server_name {{ your_app_name }} {{ your.domain.com }};
access_log /var/log/nginx/{{ your.domain.com }}.log;
@justinwinslow
justinwinslow / gist:6148354
Last active December 20, 2015 14:39
Marionette.js List Navigation Core
define([
'jquery',
'underscore',
'backbone',
'backbone.marionette',
'backbone.virtual-collection',
'hbs!navigation/templates/list',
'hbs!navigation/templates/listItem'
], function(