Skip to content

Instantly share code, notes, and snippets.

@masimplo
masimplo / 0_reuse_code.js
Created July 18, 2014 10:57
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
@masimplo
masimplo / delete-really-long-directory.bat
Last active September 20, 2016 06:56
Delete directory/file with really long name on windows
mkdir empty_dir
robocopy empty_dir the_dir_to_delete /s /mir
rmdir empty_dir
rmdir the_dir_to_delete
@masimplo
masimplo / gist:9d1db2a99bf439b22732
Created August 7, 2014 21:16
Creating a db user in Azure MSSQL
- first, connect to the master database
CREATE LOGIN login1 WITH password='password';
- then connect to the database in question
CREATE USER login1User FROM LOGIN login1;
EXEC sp_addrolemember 'dbmanager', 'login1User';
EXEC sp_addrolemember 'loginmanager', 'login1User';
@masimplo
masimplo / gist:6c4bafbbd25dbe7dfd9b
Last active August 29, 2015 14:05
Install notepad++ on Azure VM
Set-ExecutionPolicy RemoteSigned
iex ((new-object net.webclient).DownloadString("http://chocolatey.org/install.ps1"))
cinst notepadplusplus
@masimplo
masimplo / index.html
Created September 10, 2014 13:21
Selectize Directive Selectize AngularJS Directive Demo // source http://jsbin.com/hozegujebibi/1
<!DOCTYPE html>
<html ng-app="demo">
<head>
<meta name="description" content="Selectize AngularJS Directive Demo" />
<meta charset="utf-8">
<title>Selectize Directive</title>
<link rel="stylesheet" href="http://brianreavis.github.io/selectize.js/css/selectize.default.css" />
<link rel="stylesheet" href="style.css" />
</head>
@masimplo
masimplo / gist:324e77a2dd20fb4aa227
Last active October 6, 2015 01:20
Decorating $http service to support url interpolation
function httpDecorator($delegate: ng.IHttpService) {
var $http = $delegate;
var wrapper = () => {
// interpolate the url
var config = arguments[0];
config.url = interpolateUrl(config.url, config.params, config.data);
return $http.apply($http, arguments);
};

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) {
sudo apt-get update
sudo apt-get install -y build-essential openssl libssl-dev pkg-config
cd ~
wget http://nodejs.org/dist/v0.12.2/node-v0.12.2.tar.gz
tar xvf node-v*
cd node-v*
./configure
make
sudo make install
cd ~
@masimplo
masimplo / Enable swap in Azure Linux VM
Created May 29, 2015 12:21
Enable swap in Azure Linux VM
edit the file /etc/waagent.conf
Toggle the option ResourceDisk.Format from 'n' to 'y'
Toggle the option ResourceDisk.EnableSwap from 'n' to 'y'
Add the swapspace size to the option ResourceDisk.SwapSizeMB
reboot the machine
@masimplo
masimplo / Create Certificate from VS command line
Last active August 29, 2015 14:22
Create azure management certificate and add it to CurrentUser storage
makecert -r -pe -a sha1 -n CN=AzureMgmt -ss My “AzureMgmt.cer"