Skip to content

Instantly share code, notes, and snippets.

View menacestudio's full-sized avatar

Dennis Rongo menacestudio

View GitHub Profile
@menacestudio
menacestudio / gist:9d25efcd922662709eb7
Created May 25, 2012 23:12
ASP.NET - Recursive find control within a parent.
private Control FindField(Control source, string id)
{
Control target = source.FindControl(id);
if (target != null) return target;
foreach (Control child in source.Controls)
{
target = this.FindField(child, id);
if (target != null) return target;
}
return null;
@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 / 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>
@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 / ServiceResolverAdapter.cs
Created March 13, 2012 03:56 — forked from haacked/ServiceResolverAdapter.cs
ServiceResolverAdapter: Allows you to use the ASP.NET MVC DependencyResolver for ASP.NET Web API
public class ServiceResolverAdapter : IDependencyResolver
{
private readonly System.Web.Mvc.IDependencyResolver dependencyResolver;
public ServiceResolverAdapter(System.Web.Mvc.IDependencyResolver dependencyResolver)
{
if (dependencyResolver == null) throw new ArgumentNullException("dependencyResolver");
this.dependencyResolver = dependencyResolver;
}

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 / slider.ts
Created March 17, 2015 22:47
An AngularJS slider directive
slider.$inject = [];
function slider() {
return <ng.IDirective>{
restrict: 'E',
replace: true,
scope: {
model: '=ngModel',
isRequired: '=',
min: '=',
@menacestudio
menacestudio / numericOnly.ts
Last active August 29, 2015 14:17
An AngularJS decorator directive to only allow numeric values.
numericOnly.$inject = ['$log'];
function numericOnly(
$log: ng.ILogService): ng.IDirective {
return <ng.IDirective>{
restrict: 'A',
scope: true,
link: link
};
@menacestudio
menacestudio / datepickerFormatter.js
Created March 13, 2015 21:39
An AngularJS decorator directive to apply automatic formatting to Angular UI datepickers.
function datepickerPopup() {
return <ng.IDirective>{
restrict: 'EAC',
require: 'ngModel',
link: function ($scope, $element, $attrs, controller) {
controller.$formatters.shift();
}
}
}
angular.module('app').directive('datepickerPopup', datepickerPopup);