Skip to content

Instantly share code, notes, and snippets.

Dennis Rongo menacestudio

View GitHub Profile
View gist:36c8d1d246a94098c16b

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 / slider.ts
Created Mar 17, 2015
An AngularJS slider directive
View slider.ts
slider.$inject = [];
function slider() {
return <ng.IDirective>{
restrict: 'E',
replace: true,
scope: {
model: '=ngModel',
isRequired: '=',
min: '=',
menacestudio / numericOnly.ts
Last active Aug 29, 2015
An AngularJS decorator directive to only allow numeric values.
View numericOnly.ts
numericOnly.$inject = ['$log'];
function numericOnly(
$log: ng.ILogService): ng.IDirective {
return <ng.IDirective>{
restrict: 'A',
scope: true,
link: link
menacestudio / datepickerFormatter.js
Created Mar 13, 2015
An AngularJS decorator directive to apply automatic formatting to Angular UI datepickers.
View datepickerFormatter.js
function datepickerPopup() {
return <ng.IDirective>{
restrict: 'EAC',
require: 'ngModel',
link: function ($scope, $element, $attrs, controller) {
angular.module('app').directive('datepickerPopup', datepickerPopup);
menacestudio / sortableGrid.js
Created Mar 13, 2015
An AngularJS directive to add sorting capability to table headers.
View sortableGrid.js
sortableGrid.$inject = [];
function sortableGrid() {
return <ng.IDirective>{
restrict: 'A',
scope: {
order: '=',
by: '=',
reverse: '='
menacestudio / scoreDirective.js
Created Mar 13, 2015
An AngularJS directive for handling score input.
View scoreDirective.js
scoreInput.$inject = [];
function scoreInput() {
return <ng.IDirective>{
restrict: 'E',
replace: true,
scope: {
model: '=ngModel',
isRequired: '=',
isReadonly: '=',
View index.html
<!DOCTYPE html>
<script data-require="angular.js@*" data-semver="1.3.5" src=""></script>
<script src="" data-semver="1.3.5" data-require="angular-route@*"></script>
<script data-require="angular-resource@1.3.5" data-semver="1.3.5" src=""></script>
<link href="style.css" rel="stylesheet" />
<script src="script.js"></script>
menacestudio / service.js
Created Dec 7, 2014
Angular ngResource sample
View service.js
angular.module("exampleApp", []).service('exampleService', ["$http", "$q" ,function ($http, $q) {
var service = {
returnedData: [],
getData = function(forceRefresh)
var deferred = $q.defer();
if(!service.dataLoaded.genericData || forceRefresh)
menacestudio / controller.js
Last active Aug 29, 2015
Angular using Angular directives for Bootstrap
View controller.js
(function(app) {
app.controller('Ctrl', Ctrl);
app.controller('CtrlModal', CtrlModal);
//Ctrl.$inject = ['$scope', '$modal', 'dataservice'];
function Ctrl($scope, $modal, dataservice) {
var vm = this;
menacestudio / sample_cte_paging.sql
Created Nov 13, 2014
Sample paging in TSQL using common table expression (CTE)
View sample_cte_paging.sql
-- Calculate paging
DECLARE @topRecord VARCHAR(20) = CAST(((@pageSize+@offset)+1) AS VARCHAR)
SET @cte_query = WITH cte_res
AS ( SELECT ROW_NUMBER() OVER(ORDER BY ['+@sortBy+'] '+@sortDir+') AS rowid, count(*) over() as TotalRecords,* from (SELECT * FROM #someTable WITH(NOLOCK)) as table1)
select rowID, TotalRecords, id, someField from cte_res with(nolock) where rowid>'+ CAST(@offset AS VARCHAR) +' and rowid< ' + @topRecord
EXECUTE sp_executesql @cte_query
You can’t perform that action at this time.