Skip to content

Instantly share code, notes, and snippets.

View dalemanthei's full-sized avatar

Dale Manthei dalemanthei

  • Great White North, eh.
View GitHub Profile
@dalemanthei
dalemanthei / jasmine-$window-reload.js
Created January 24, 2016 22:20
Decorate $window to count page reloads
beforeEach(module(function ($provide) {
$provide.decorator('$window', ['$delegate',
function ($delegate) {
$windowMock = {};
$windowMock.prototype = $delegate;
$windowMock.reloadCount = 0;
$windowMock.location = {};
$windowMock.location.reload = function () {
$windowMock.reloadCount = $windowMock.reloadCount + 1;
};
@dalemanthei
dalemanthei / jasmine-window-decorator.js
Created January 24, 2016 22:18
Decorate $window to capture and count new window open events
// override the $window.open to count usage and prevent
// new windows from opening when running karma in watch mode
beforeEach(module(function ($provide) {
newWindow = {
location: {},
focusCalled: false,
closeCount: 0,
focus: function () {
newWindow.focusCalled = true;
},
@dalemanthei
dalemanthei / Jasmine-httpBackend-afterEach.js
Last active January 24, 2016 22:13
Standard afterEach $httpBackend checks for Jasmine
afterEach(function () {
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
});
@dalemanthei
dalemanthei / Preferences.sublime-settings
Created January 12, 2014 03:54
Preferences.sublime-settings
{
"close_windows_when_empty": false,
"color_scheme": "Packages/User/Monokai Extended (SL).tmTheme",
"font_face": "consolas",
"font_size": 15,
"ignored_packages":
[
"Vintage",
"Markdown"
],
@dalemanthei
dalemanthei / Jump to Finder or Path Finder
Created December 29, 2013 19:33
A .bash_profile snippet for Mac OS X from http://brettterpstra.com/2013/02/09/quick-tip-jumping-to-the-finder-location-in-terminal/ with added snippet for Path Finder.
# from http://brettterpstra.com/2013/02/09/quick-tip-jumping-to-the-finder-location-in-terminal/
# cd to the path of the front Finder window
cdf() {
target=`osascript -e 'tell application "Finder" to if (count of Finder windows) > 0 then get POSIX path of (target of front Finder window as text)'`
if [ "$target" != "" ]; then
cd "$target"; pwd
else
echo 'No Finder window found' >&2
fi
}
@dalemanthei
dalemanthei / .gitconfig
Created August 3, 2015 20:13
Git log commands (.gitconfig)
# list commands
le = log --oneline --decorate
ll = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --numstat
ls1 = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate
lds = log --pretty=format:"%C(yellow)%h\\ %C(green)%ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=short --graph
ls = log --pretty=format:"%C(green)%h\\ %C(yellow)[%ad]%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=relative
@dalemanthei
dalemanthei / flex-layout.less
Created May 3, 2015 16:19
Simple CSS styles to keep separate layout from other CSS concerns. The fc-* class establishes the container, its direct descendents should apply one of the fi-* styles.
/* Vertical (column) Flex Container for actions
-------------------------------------------------- */
.fc-col {
display: flex;
flex-direction: column;
flex-wrap: nowrap;
justify-content: flex-start;
align-content: stretch;
align-items: stretch;
@dalemanthei
dalemanthei / String fill
Created April 6, 2015 16:56
String fill
function stringFill2(x, n) {
var s = '';
while (n-- > 0) s += x;
return s;
}
@dalemanthei
dalemanthei / pre-commit
Last active August 29, 2015 14:13
NodeJS version of pre-commit to run jshint, jscs, and simple scan
#!/usr/local/bin/node
var cp = require('child_process');
module.paths.push('/usr/local/lib/node_modules'); // hacky hacky hacky to get to async
var async = require('async');
var getJsFiles = 'git diff --cached --name-only --diff-filter=ACM | grep ".js$"';
cp.exec(getJsFiles, function (err, stdout, stderr) {
var failCount = 0;
@dalemanthei
dalemanthei / pre-commit
Created January 17, 2015 04:10
A git pre-commit hook to validate JavaScript
#!/bin/sh
if git-rev-parse --verify HEAD >/dev/null 2>&1; then
against=HEAD
else
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
jsfiles=$(git diff --cached --name-only --diff-filter=ACM | grep ".js$")
if [ "$jsfiles" = "" ]; then