Skip to content

Instantly share code, notes, and snippets.

@justinwinslow
justinwinslow / ng-actually-checked.js
Last active June 29, 2016 22:25
ng-actually-checked directive - For when you want to subvert checkbox clicks
angular.module('Module', [])
.directive('ngActuallyChecked', function(){
return {
link: function(scope, el, attrs) {
// Let's immediately store the value of our expression
var actualValue = scope.$eval(attrs.ngActuallyChecked);
// Don't let clicks overwrite our actual value
el.on('click', function(event){
el.prop('checked', actualValue);
/* Module */
define(['dep'], function(dep){
var Module = {};
// Instantiate a local controller
Module.controller = new Backbone.Controller.extend({
foo: bar
})();
@justinwinslow
justinwinslow / gist:8347017
Last active January 2, 2016 18:59
Angular $resource abstraction for Backbone collection-like interactions
/*
TODO
[ ] Returns return a $q promise or the $resource return. Need to mimic the
$resource return for all returns
[ ] Extend Collection with underscore methods
*/
angular.module('ngCollection', ['ngResource'])
.factory('$collection', ['$resource', '$q', function($resource, $q){
// Collection constructor
@justinwinslow
justinwinslow / gist:7994944
Last active December 31, 2015 13:48
Angular ui-router breadcrumbs
// State example:
//
// $stateProvider
// .state('state', {
// url: 'state/:id',
// template: stateTemplate,
// controller: stateController,
// // Expose parameters in display names using {:param} syntax
// displayName: 'State ({:id})'
// });
@justinwinslow
justinwinslow / gist:7924701
Last active December 31, 2015 02:59
Loading and no items indication for angular
<!-- This assumes you are using ngResource to request data (http://docs.angularjs.org/api/ngResource.$resource) -->
<ul>
<!--
We can use ng-show="{expression}" to programmatically display something.
ngResouce adds a handy $resolved property to your data objects.
So, let's key off of that to indicate loading
-->
<li ng-show="!things.$resolved">Loading...</li>
@justinwinslow
justinwinslow / gist:7663088
Last active December 29, 2015 11:19
Proposed Angular App Structure

js/

  • index.html
  • controller.js
    • angular.module('Application', ['ModuleA', 'AppViewACtrl', 'lodash', function(){}]);
  • dependencyFactory.js
    var lodash = angular.module('lodash', []);
    
    lodash  
    

.factory('_', function() {

@justinwinslow
justinwinslow / gist:7031239
Created October 17, 2013 19:59
Intelligent Array Init.d script
#! /bin/sh
### BEGIN INIT INFO
# Provides: intelligentarray
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Uses forever to manage the node.js application
# Description: Launches a node.js application using forever.
### END INIT INFO
@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(
@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: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');