Skip to content

Instantly share code, notes, and snippets.

@jakeatoms
jakeatoms / results.sh
Created March 20, 2016 01:38
There is a ruby script that parses a junit.xml file, returning the test cases that failed (this gist). I need to get (in Bash) each "CM####" in the string returned from the script. Ultimately, I need a comma-delimited list
'I, [2016-03-19T18:31:17.013853 #13420] INFO -- : 23 failures found in the following test suites:
UITests.CM6322_TestCaseTitle
UITests.CM7032_YetAnotherTestCaseTitle
UITests.CM7296_OneLastTitleForGoodMeasure'
@jakeatoms
jakeatoms / auth.js
Last active August 29, 2015 13:56
Securing access to an api endpoint based on user roles. Either require the user be in at least 1 role specified or in all roles specified
var passport = require('passport');
var userInAnyRole = function(user, roles){
'use strict';
if(roles === undefined || roles.length === 0) {return false;}
// sorry IE8
// every one of the given roles must appear in the user's roles
return roles.some(function(role){
@jakeatoms
jakeatoms / gulp-zip
Created February 9, 2014 03:15
Zip a folder using gulp
'use strict'
var gulp = require('gulp');
var zip = require('gulp-zip');
gulp.task('default', function(){
return gulp.src('src/folder-to-zip')
.pipe(zip('casper-mod.zip'))
.pipe(gulp.dest('dist'));
});
@jakeatoms
jakeatoms / ko-sort.js
Last active December 22, 2015 06:39
simple knockoutjs custom binding for sorting a table of data. View in action (with markup) here: http://jsfiddle.net/norepro/bVB96/
ko.bindingHandlers.sort = {
init: function (element, valueAccessor) {
var asc = false;
ko.utils.registerEventHandler(element, 'click', function (event) {
var value = ko.utils.unwrapObservable(valueAccessor()),
sortBy = event.target.getAttribute('data-sort-by'),
list = value.list,
alwaysBy = value.alwaysBy;
@jakeatoms
jakeatoms / effeckt-tooltip.scss
Last active December 21, 2015 05:39
effeckt.css tooltip class reuse
[data-effeckt-tooltip-text] {
position: relative;
}
// probably should make various things into variables, like colors
.effeckt-tooltip[data-effeckt-tooltip-text] {
&::before, &::after {
opacity: 0;
transition: 0.2s; // no delay on hover off
}
@jakeatoms
jakeatoms / mapToArrayOfType.js
Last active December 18, 2015 03:58
We often have an array of js objects that we get from the server and we want to map those to a particular viewmodel. This function takes the array, the desired constructor, and any additional constructors arguments and returns an array of the given viewmodel. See any areas for improvement?
function mapToArrayOfType(valuesToPush, vm) {
if (!valuesToPush || Object.prototype.toString.call(valuesToPush) !== '[object Array]') {
return [];
};
var vmArray = [],
args = [];
if (arguments.length > 3) {
args = Array.prototype.slice.call(arguments, 3);