Skip to content

Instantly share code, notes, and snippets.

View dgs700's full-sized avatar

David Shapiro dgs700

  • Mountain View, CA
View GitHub Profile
@dgs700
dgs700 / customElementService.js
Last active August 29, 2015 14:05
AngularJS 1.x service that constructs and registers Custom Elements in the DOM
// This depends on a custom element polyfill for browsers
// other than chrome and opera - 9/1/14
angular.module('CustomElemFactory', [])
.service('customElem', [
'$window',
function($window){
// hash of registered element types
// that Angular knows about
// note that this would NOT include CEs registered from
// elsewhere
@dgs700
dgs700 / gulpfile.js
Last active August 29, 2015 14:02 — forked from torgeir/gulpfile.js
// Load plugins
var gulp = require('gulp'),
sass = require('gulp-ruby-sass'),
autoprefixer = require('gulp-autoprefixer'),
minifycss = require('gulp-minify-css'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
imagemin = require('gulp-imagemin'),
rename = require('gulp-rename'),
clean = require('gulp-clean'),
@dgs700
dgs700 / backbone_hb_template.html
Created August 9, 2013 22:04
Example of an Angularjs web component included inside a Backbone.js app. A bit rough for now, but will be refined.
<div class="action-links">
<!-- Include our Angular web component in the page as html markup
passing in (injecting) any data, config, or styling objects from the bckbone app-->
<span angular-web-component
og-id="{{model.id}}"
og-url="{{model.url}}"
og-key="{{model.key}}"
og-title="{{model.title}}"
og-image="{{model.image}}"
@dgs700
dgs700 / app.js
Last active December 17, 2015 08:38
Tibbr App Framework bootstrap code - Angularjs and some bare metal js
//Tibbr plugins html directives and associated controllers
(function () {
'use strict';
//declare the plugins module with dependancies
var tibbrPlugins = angular.module('TibbrPlugins', [
'TibbrFilters',
'Tibbr',
'EventsBus',
'PageBus',
'TibbrAPI',
@dgs700
dgs700 / app.js
Created February 25, 2013 02:18
First Angular.js implementation example. Tibbr plugin components "Like" and "Follow" that were previously handled with untestable jQuery spaghetti refactored to Angular conventions. Besides its main role as a tight data binding (MVVM) framework, Angular is showing promise for creating reusable and exportable UI components without too much overhead.
//Tibbr plugins html directives and associated controllers
(function () {
'use strict';
//declare the plugins module with dependancies
var tibbrPlugins = angular.module('TibbrPlugins', ['TibbrFilters', 'Tibbr', 'EventsBus', 'PageBus', 'TibbrAPI']);
//code to run when a like tag is encountered
tibbrPlugins.directive('tibrLike', function factory($window) {
var directiveDefinitionObject = {
//template: '<div>hi</div>',
@dgs700
dgs700 / gist:5010993
Created February 22, 2013 05:37
Tibbr - Pattern for processing a large number of items without freezing the UI or causing long running script errors in IE
var arrayChunk = [],
//an array of models possibly with 100s or 1000s of items
//that need to be tranformed into views
combinedArray = users.models.concat( subjects.models).concat(broadcasts.models);
while( !_.isEmpty(combinedArray)){
//process 10 at a time
arrayChunk = combinedArray.splice(0, 10);
//wrapper around setTimeout 0 to defer execution to the end of the call stack
_.defer( function(chunk){
@dgs700
dgs700 / gist:4975399
Created February 18, 2013 06:14
FICO gist
(function () {
//make an array of Widgets
var widgetArray = [], //array of widgets
widget, //widget
w, i; //temp vars
//widget constructor
function Widget(name, gears, angle) {
//assign parameters or defaults
this.name = name || 'widget';
@dgs700
dgs700 / objectToQueryString.js
Created January 30, 2013 22:39
Javascript object to URL encoded query string converter. Code extracted from jQuery.param() and boiled down to bare metal js. Should handle deep/nested objects and arrays in the same manner as jQuery's ajax functionality.
var objectToQueryString = function (a) {
var prefix, s, add, name, r20, output;
s = [];
r20 = /%20/g;
add = function (key, value) {
// If value is a function, invoke it and return its value
value = ( typeof value == 'function' ) ? value() : ( value == null ? "" : value );
s[ s.length ] = encodeURIComponent(key) + "=" + encodeURIComponent(value);
};
if (a instanceof Array) {
@dgs700
dgs700 / Ext.module.js
Created July 24, 2012 20:07
Pattern for importing/exporting a simple Javascript Module / Singleton from Ext.define()
//define a dependancy
Ext.define( 'My.dependancyModule', {
//prevents unnecessary class construction methods
singleton: true,
//wrap logic scoped in self executing function
module: (function(){
//protected vars
@dgs700
dgs700 / Backbone.Configurator.js
Created May 11, 2012 05:58
Remove all hardcoded dependancies from your Backbone classes for clean MVC separation!
/* Copywrite 2012, David Shapiro - portions added to existing Backbone code*/
/* Subject to FFRUYL licensing - Feel free to rip and use as you like. */
/*globals Backbone:true, _:true, $:true*/
// @name: Configurator
//
// @tagline: Configurator for Backbone Apps- models, views and routers
//