Skip to content

Instantly share code, notes, and snippets.

View menacestudio's full-sized avatar

Dennis Rongo menacestudio

View GitHub Profile

This afternoon I encountered a race condition in an Angular app I'm working on. Essentially my controller was pushing some values to an Array on its scope and something (I wasn't sure what) was asynchronously overriding the Array's contents. The Array was being used by a custom directive- written by someone else- as well as an ngModel and it wasn't clear who was making the change.

I ended up trying something I had not done before and it worked well enough that I thought I'd post it here in case it helped anyone else.

First I enabled The "Async" option in Chrome's "Sources > Call Stack" panel.

Next I set a breakpoint in my controller where I was modifying the Array. When I hit that breakpoint, I ran the following code in my console:

Object.observe(this.theArray, function(changes) {
@menacestudio
menacestudio / 0_reuse_code.js
Created August 16, 2014 07:33
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
// Original idea: http://stackoverflow.com/questions/9565889/get-the-ip-address-of-the-remote-host
using System.Net.Http;
using System.ServiceModel.Channels;
using System.Web;
namespace CrowSoftware.Api
{
public static class HttpRequestMessageHelper
{
@menacestudio
menacestudio / paginated_collection.js
Created January 23, 2013 00:05 — forked from takinbo/paginated_collection.js
Backbone: pagination
// includes bindings for fetching/fetched
var PaginatedCollection = Backbone.Collection.extend({
initialize: function() {
_.bindAll(this, 'parse', 'url', 'pageInfo', 'nextPage', 'previousPage', 'filtrate', 'sort_by');
typeof(options) != 'undefined' || (options = {});
typeof(this.limit) != 'undefined' || (this.limit = 20);
typeof(this.offset) != 'undefined' || (this.offset = 0);
typeof(this.filter_options) != 'undefined' || (this.filter_options = {});
typeof(this.sort_field) != 'undefined' || (this.sort_field = '');
@menacestudio
menacestudio / gist:4515310
Created January 12, 2013 00:43 — forked from efeminella/gist:1937609
Handlebars: Loading external templates
/*
* Extends Handlebars with a basic get method for loading external
* Handlebars templates. Simply pass an options object which contains
* the following properties:
* - path (required) : Path to the external template file to be loaded
* - success (required) : Callback invoked with the compiled loaded template.
* - cache (optional) : true if the template is to be cached, otherwise false.
*
* In addition to the above arguments, any jQuery/Zepto.ajax options argument
* can be specified as well.
@menacestudio
menacestudio / gist:4509238
Created January 11, 2013 09:24
Handlebars: Load template with RequireJS
define(['handlebars','text'], function (Handlebars, text) {
var _buildMap = {};
var _buildTemplate = Handlebars.compile(
'define("{{pluginName}}!{{moduleName}}", ["handlebars"], function(Handlebars){'+
' return {{fn}}'+
'});\n'
);
return {
load: function (name, req, onLoad, config) {
@menacestudio
menacestudio / example.html
Created April 25, 2012 22:19 — forked from joelnet/example.html
KO: Unobtrusive Knockout support library for jQuery
Choose a ticket class: <select id="tickets"></select>
<p id="ticketOutput"></p>
<script id="ticketTemplate" type="text/x-jquery-tmpl">
{{if chosenTicket}}
You have chosen <b>${ chosenTicket().name }</b>
($${ chosenTicket().price })
<button data-bind="click: resetTicket">Clear</button>
{{/if}}
@menacestudio
menacestudio / jquery.loadasync.js
Created April 18, 2012 22:16 — forked from mathiasbynens/jquery.loadasync.js
jQuery: Load scripts asynchronously
// Load scripts asynchronously
jQuery.loadAsync = function(url, callback) {
// Don't use $.getScript since it disables caching
jQuery.ajax({
'url': url,
'dataType': 'script',
'cache': true,
'success': callback || jQuery.noop
});
};
@menacestudio
menacestudio / jspat6_4.html
Created March 13, 2012 04:02 — forked from kentbrew/jspat6_4.html
JS: Pro JS Design Patterns Sample Code
<html>
<head>
<title>Chapter 6 Section 4, Pro JavaScript Design Patterns</title>
</head>
<body>
<script>
// this is straight from the code exampes at http://jsdesignpatterns.com/
// sadly, it fails with a syntax error. quoth JSLint:
//
@menacestudio
menacestudio / gist:2026647
Created March 13, 2012 03:57
JS: jQuery Google CDN
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/libs/jquery-1.7.1.min.js"><\/script>')</script>