Skip to content

Instantly share code, notes, and snippets.

@pc035860
pc035860 / glance.js
Created March 9, 2014 16:11
Attach a new helper function "$glance" to scope. Enables complex conditional scope one-time observation.
angular.module('scope.glance', [])
.factory('attach$glance', ['$q', function ($q) {
function $glance(watchExpression, checkFunction, objectEquality) {
var scope = this;
var dfd = $q.defer(),
clearWatch;
checkFunction = checkFunction || function (newVal, oldVal, scope) {
@pc035860
pc035860 / fire-util.js
Created March 9, 2014 15:19
Util module for working with Firebase & angularFire
angular.module('fireUtil', ['firebase'])
.provider('fireUtil', function () {
var util, $get;
util = {
rootUrl: null,
$get: ['Firebase', function (Firebase) {
var _rootRef = util.rootUrl ? new Firebase(util.rootUrl) : null;
var Promise = require('bluebird');
// log the error
Promise.onPossiblyUnhandledRejection(function(error){
// this will be called even though there is a catch
console.log('uncaught error here', error);
});
var toCall = Promise.coroutine(function* () {
console.log('going to explode');
@pc035860
pc035860 / async-chunk-queued.js
Created December 28, 2013 10:54
Chunked Executions Need "setImmediate" and "Promise"
// async version of timedChunk plus queued by robin
function asyncChunkQueued(items, process, context, callback) {
var todo = items.concat(), //create a clone of the original
i = 0, // index counter
dfd = $.Deferred(),
routine = function () {
process.call(context, todo.shift(), i++)
.then(function () {
if (todo.length > 0) {
_setImmediate(routine);
@pc035860
pc035860 / gist:8129655
Created December 26, 2013 04:05
javascript basic proxy function
/**
* Context and arguments proxy function
*
* @param {function} func the function
* @param {object} context the context
* @param {array} args arguments
* @return {function} proxied function
*/
function proxy(func, context, args) {
return function () {
app.directive('autoFillSync', function($timeout) {
return {
require: 'ngModel',
link: function(scope, elem, attrs) {
var origVal = elem.val();
$timeout(function () {
var newVal = elem.val();
if(ngModel.$pristine && origVal !== newVal) {
ngModel.$setViewValue(newVal);
}
@pc035860
pc035860 / 0_reuse_code.js
Created October 7, 2013 07:50
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@pc035860
pc035860 / scopes.txt
Created September 16, 2013 09:30 — forked from iambibhas/scopes.txt
Here is a list of scopes to use in Sublime Text 2 snippets -
ActionScript: source.actionscript.2
AppleScript: source.applescript
ASP: source.asp
Batch FIle: source.dosbatch
C#: source.cs
C++: source.c++
Clojure: source.clojure
CSS: source.css
@pc035860
pc035860 / randInt.js
Created September 13, 2013 04:02 — forked from gengkev/randInt.js
function randInt(min,max){
var range = max - min;
// it actually does work the other way...
// if (range < 0) { throw new RangeError("min must be less than max"); }
var rand = Math.floor(Math.random() * (range + 1));
return min + rand;
}
@pc035860
pc035860 / angularjs.directive.submitIt.js
Created September 7, 2013 02:24
AngularJS submitIt module
angular.module('submitIt', [])
/**
* @ngdoc directive
* @description form submission trigger
*
* @param {boolean} submit-it submit form on `true`
* @param {string} si-action submit action(optional)
* @param {string} si-method submit method(optional)
*/