Skip to content

Instantly share code, notes, and snippets.

View mokkabonna's full-sized avatar

Martin Hansen mokkabonna

  • Knowit Amende AS
  • Oslo, Norway
View GitHub Profile
@mokkabonna
mokkabonna / gist:301e53b19e726fb9dd7e
Last active August 29, 2015 14:02
sinon shorter stack errors, add in assert.fail
fail: function fail(message) {
var error = new Error(message);
error.name = this.failException || assert.failException;
try{
throw error;
} catch(e) {
if (error.stack){
console.log(error.stack);
error.stack = error.stack.split('\n').slice(0,20).join('\n')
@mokkabonna
mokkabonna / responsive-table
Created April 25, 2014 13:53
responsive-tables
<style>
table {
width:100%;
}
@media (max-width: 500px) {
table tr th {
float:left;
width:50%;
clear:left;
}
@mokkabonna
mokkabonna / expect-promise.js
Created March 16, 2014 21:27
promises for expect.js
var eventually = {
expect: function(promise) {
function notBe(expectedValue) {
return promise.then(function(eventualValue) {
expect(eventualValue).not.to.be(expectedValue);
});
}
function be(expectedValue) {
@mokkabonna
mokkabonna / gist:9584448
Created March 16, 2014 14:57
rename files
for file in *; do newname="$(cat $file | head -2 | tail -1 | cut -f 3 -d '[' | cut -d '(' -f 1).sublime-snippet"; mv "$file" "$newname"; done
@mokkabonna
mokkabonna / gist:9266784
Created February 28, 2014 07:24
Daily automatic backup/snapshots and purging for EC2 volumes
#!/bin/bash
#create snapshots of all volumes
aws ec2 describe-volumes | grep VOLUMES | cut -f 7 | while read volumeid; do aws ec2 create-snapshot --volume-id=$volumeid --description="daily-for-automatical-deletion" ; done
#delete all but the last 35 (if 5 volumes, this is keeping the daily automatic backups for the last 7 days)
aws ec2 describe-snapshots --owner-id=<insert-owner-id> --filters Name=description,Values="*for-automatical-deletion" | grep SNAPSHOTS | sort -r -k 6 | sed -n 35,1000p | cut -f 5 | while read snapshotid; do aws ec2 delete-snapshot --snapshot-id=$snapshotid; done
@mokkabonna
mokkabonna / gist:8610151
Last active January 4, 2016 10:39
Sublimelinter travis build image insertion
#!/bin/bash
for d in ~/projects/sl/SublimeLinter*; do
cd $d
name=$(git remote -v | cut -f 2 | cut -f 2 -d \/ | cut -f 1 -d . | cut -f 2 | head -1)
sed -i 's/\(==\+\)/\0\n\n[![Build Status](https:\/\/khancdn.eu\/badges.php?service=https%3A%2F%2Ftravis-ci.org%2FSublimeLinter%2FSublimeLinter-json.png%3Fbranch%3Dmaster)](https:\/\/travis-ci.org\/SublimeLinter\/SublimeLinter-json)/' README.md
sed -i 's/SublimeLinter-json.png/'$name'.png/' README.md
sed -i 's/SublimeLinter-json)/'$name')/' README.md
git commit -am "Added travis build status image"
done
@mokkabonna
mokkabonna / gist:6163981
Last active December 20, 2015 16:49
Client side html doc for jstd-karma adapter
/**
* A wrapper around the testcase and setup/teardown methods that parses the function first and inserts HTML into the page or the scope
* This is according to the jstestdriver HTML doc feature https://code.google.com/p/js-test-driver/wiki/HtmlDoc
*/
function createFunc(test) {
var commentMatches = test.toString().match(/\/\*[^*]*\*+(?:[^*\/][^*]*\*+)*\//g); //finds all comment blocks in the function
return function() {
var self = this;
if (commentMatches !== null) { //if we have any comment blocks loop each
@mokkabonna
mokkabonna / cancelledrequests.js
Created June 26, 2013 12:54
reported by frameworks when browser cancells ajax request
//vermin readystate 4, status 0
vermin.ajax.get('/longrunning', {
failure: function() {
console.log(JSON.stringify(arguments));
}
});
//jquery readystate 0, status 0
$.get('/longrunning').fail(function() {
console.log(JSON.stringify(arguments));
define(['../lib/jquery/jquery.js'], function() {
var jquery = $; //store original jquery before deleting it from the global namespace
$.noConflict(true); //delete $ and jQuery from the global namespace
return jquery; //return jquery to any module that requires it
});
@mokkabonna
mokkabonna / gist:5841346
Created June 22, 2013 15:48
qunit-setup
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>QUnit test</title>
<link rel="stylesheet" href="../lib/qunit/qunit.css"></head>
<script src="../lib/qunit/qunit.js"></script>
<script data-main="runner" src="../lib/requirejs/require.js"></script>
<body>
<div id="qunit"></div>