Skip to content

Instantly share code, notes, and snippets.

View ferronrsmith's full-sized avatar
⛱️
Chilling on the beach

Ferron H ferronrsmith

⛱️
Chilling on the beach
View GitHub Profile
@ferronrsmith
ferronrsmith / highlighter.js
Created October 3, 2013 01:48
A very nice json synax highlighter. Also can be reconfigured to work with an object
function syntaxHighlight(json) {
if (typeof json != 'string') {
json = JSON.stringify(json, undefined, 2);
}
json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
var cls = 'number';
if (/^"/.test(match)) {
if (/:$/.test(match)) {
cls = 'key';
@ferronrsmith
ferronrsmith / getUrlVars.js
Created October 20, 2013 18:18
Retrieve URL variables
function getUrlVars (url) {
var vars = [], hash, $href, hashes, i;
$href = (url !== undefined) ? url : exp.location.href;
hashes = $href.slice($href.indexOf('?') + 1).split('&');
for (i = 0; i < hashes.length; i += 1) {
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
@ferronrsmith
ferronrsmith / parseQueryString.js
Created October 20, 2013 18:20
Separate gist from previous. Extracts query string values
function parseQueryString (qs) {
if(arguments.length==0) {
qs = exp.location.href;
}
var e,
a = /\+/g, // Regex for replacing addition symbol with a space
r = /([\w]+)=?([\w]*)/g,
d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
urlParams = {};
@ferronrsmith
ferronrsmith / evTrigger.js
Last active December 26, 2015 02:59
Function to trigger events in phamtomjs
/*jslint browser:true */
/*global document */
/**
* @author ferron on 10/21/13.
* Adapted from http://stackoverflow.com/questions/17211466/how-can-i-simulate-a-click-event-in-my-angularjs-directive-test
* a simple trigger mechanism to allow testing of events to work inside phamtomjs
*/
function evTrigger(element, event) {
"use strict";
@ferronrsmith
ferronrsmith / browserTrigger.js
Created October 21, 2013 11:28
Function to trigger events in phamtomjs. Adapted from ng-scenario
'use strict';
(function () {
var msie = parseInt((/msie (\d+)/.exec(navigator.userAgent.toLowerCase()) || [])[1], 10);
function indexOf(array, obj) {
if (array.indexOf) return array.indexOf(obj);
for ( var i = 0; i < array.length; i++) {
if (obj === array[i]) return i;
@ferronrsmith
ferronrsmith / database.rake
Created November 10, 2013 06:20
The following task releases task fixes the issue where a database can't be dropped because it is already been used by another process e.g. There are 1 other session(s) using the database. : DROP DATABASE IF EXISTS "test_db". This task removes the process locks from the database that blocks the db from being dropped
namespace :testdb do
# The following task releases task fixes the issue where a database
# can't be dropped because it is already been used by another process
# e.g. There are 1 other session(s) using the database. : DROP DATABASE IF EXISTS "test_db"
# This task removes the process locks from the database that blocks the db from being dropped
# @author : FH
# @mod version of : http://stackoverflow.com/questions/17615574/cucumber-and-rspec-testing-with-zeus-postgres-is-being-accessed-by-other-users/17746382#17746382
desc 'Simple script to release the database lock and drop the environment database'
task :drop do
@ferronrsmith
ferronrsmith / default.js
Created December 4, 2013 14:53
This filter takes a default value and input to that value it it's null
'use strict';
// Default Value Filter
// ---------------------
// This filter takes a default value and input to that value it it's null
// i.e. {{ github.id | default:'N/A' }} > returns 'N/A' if null otherwise return the id
angular.module('default', []).filter('default', function () {
return function(input, defaultVal) {
if(angular.isUndefined(input) || input === null) {
@ferronrsmith
ferronrsmith / color.pl
Created December 4, 2013 15:48
colors for terminal
#! /usr/bin/perl
use strict;
use warnings;
my @fgColors = (
'default', 'bold', 'black', 'red', 'blue', 'yellow', 'green',
'majenta', 'cyan', 'white', 'bold black', 'bold red', 'bold blue',
'bold yellow', 'bold green', 'bold majenta', 'bold cyan', 'bold white');
@ferronrsmith
ferronrsmith / jsontocsv.js
Created December 6, 2013 00:25
Simple converter for json objects to csv
/*jslint browser: true */
/*global $ */
function genString(key, val) {
"use strict";
return '"' + key + '",' + '"' + val + '"' + '\r\n';
}
/**
@ferronrsmith
ferronrsmith / http_backend_sample_.js
Created December 9, 2013 16:25
Sample test with partial templateUrl
describe('The toggle-summary directive', function() {
var elm, $scope, unplannedAbsence, toggleSummary;
beforeEach(inject(function($injector) {
$httpBackend = $injector.get('$httpBackend');
$httpBackend.whenGET('partials/absenceAccordion.html').respond($window.__html__['src/partials/absenceAccordion.html']);
$httpBackend.whenGET('partials/directives/employeeAbsenceList.html').respond($window.__html__['src/partials/directives/employeeAbsenceList.html']);
}));
var offsetSpy = null;