Skip to content

Instantly share code, notes, and snippets.

View morkeleb's full-sized avatar

Morten Nielsen morkeleb

View GitHub Profile
@morkeleb
morkeleb / update-to-jasmine-2.sh
Last active May 5, 2017 09:17
A shell script to update from jasmine 1 to jasmine 2
sed -i '' 's/\.notToHaveBeenCalled/\.not\.toHaveBeenCalled/' spec/*.js spec/**/*.js
sed -i '' 's/\.calls\[0\]/\.calls\.first()/' spec/*.js spec/**/*.js
sed -i '' 's/\.calls\[1\]/\.calls\.all()\[1\]/' spec/*.js spec/**/*.js
sed -i '' 's/\.calls\.length/\.calls\.count()/' spec/*.js spec/**/*.js
sed -i '' 's/\.callCount/\.calls\.count()/' spec/*.js spec/**/*.js
sed -i '' 's/\.mostRecentCall/\.calls\.mostRecent()/' spec/*.js spec/**/*.js
sed -i '' 's/\.argsForCall\[0\]/\.calls\.first()\.args/' spec/*.js spec/**/*.js
sed -i '' 's/\.argsForCall\[1\]/\.calls\.all()\[1\]\.args/' spec/*.js spec/**/*.js
sed -i '' 's/\.argsForCall\[2\]/\.calls\.all()\[2\]\.args/' spec/*.js spec/**/*.js
sed -i '' 's/\.andCallFake/\.and\.callFake/' spec/*.js spec/**/*.js

Keybase proof

I hereby claim:

  • I am morkeleb on github.
  • I am morkeleb (https://keybase.io/morkeleb) on keybase.
  • I have a public key ASC2mT0F-yJJoeUbfiWksrY9sQI5m8olCQN0LK4ynNWwKwo

To claim this, I am signing this object:

@morkeleb
morkeleb / list-changes.rb
Created February 16, 2016 12:12
Latest change date for an organisations repositories
require "github_api"
user = 'username'
token = 'oauth access token obtained from user settings'
organisation = 'myorg'
Github.configure do |c|
c.basic_auth = "#{user}:#{token}"
c.oauth_token = token
@morkeleb
morkeleb / multiselect.html
Created September 20, 2015 18:56
Simple multiselect using bootstrap and knockout
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">
<span data-bind="text: selection_size"/> <span data-bind="localize:'Client.Management.NumberOfTagsSelected'"/>
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1" data-bind="foreach: sorted_values">
<li role="presentation"><a data-bind="click: selection_changed"><input type=checkbox data-bind="checked: selected"/> <span data-bind="text: Title"></a></li>
</ul>
</div>
@morkeleb
morkeleb / ServiceTestCase.py
Created February 19, 2015 20:34
Base class for testing appengine
'''
Created on 16 apr 2010
@author: Morten Nielsen
You may change this code as you see fit, but you are expected to provide a
reference back to the original author, Morten Nielsen.
http://www.morkeleb.com
'''
@morkeleb
morkeleb / README.md
Last active August 29, 2015 14:13 — forked from ni-ka/README.md

Usage

  1. Put server.coffee next to config.coffee
  2. Register server.coffee in config.coffee server: path: 'server.coffee'
  3. Add required modules to package.json npm install --save express http-proxy

Notes

@morkeleb
morkeleb / gist:5705647
Created June 4, 2013 12:51
Self documenting api in node.js
app.get('/api/', function(req, res) {
// This endpoint
//returns the routes available in the api
var routes = [];
for(var verb in app.routes){
app.routes[verb].forEach(function(route) {
var doc = route.callbacks[route.callbacks.length-1].toString().split('\n').filter(function(str) {
var doc = str.match(/(?:\s\/\/)(.*)/);
if(doc == null) return false;
return true;
@morkeleb
morkeleb / analytics.js
Created August 31, 2012 11:01
A simple javascript file that attaches to jquerys ajax events and logs metrics based on server performance.
(function() {
$(document).ready(function() {
function saveTime(e, jqxhr, settings) {
settings.startTime = new Date().getTime();
}
function registerTime(e, jqxhr, settings) {
_gaq.push(['_trackEvent', 'AjaxResponseTime', settings.type, settings.url.split('?')[0] ,(new Date().getTime() - settings.startTime), true]);
@morkeleb
morkeleb / README.markdown
Created February 28, 2012 14:21 — forked from gudbergur/README.markdown
Bootstrap's Typeahead plugin extended (allowing for AJAX functionality) among other things

This is a fork of Bootstrap Typeahead that adds minimal but powerful extensions.

For example, process typeahead list asynchronously and return objects

  # This example does an AJAX lookup and is in CoffeeScript
  $('.typeahead').typeahead(
    # source can be a function
    source: (typeahead, query) ->
 # this function receives the typeahead object and the query string
@morkeleb
morkeleb / switchToNUnit
Created September 12, 2011 07:54
Switch from MSTest to NUnit bash script
find . -type f -print1 | xargs -0 sed -i '' 's/\[TestMethod\]/\[Test\]/g'
find . -type f -print0 | xargs -0 sed -i '' 's/\[TestMethod()\]/\[Test\]/g'
find . -type f -print0 | xargs -0 sed -i '' 's/\[TestClass\]/\[TestFixture\]/g'
find . -type f -print0 | xargs -0 sed -i '' 's/\[TestClass()\]/\[TestFixture\]/g'
find . -type f -print0 | xargs -0 sed -i '' 's/\[TestInitialize\]/\[SetUp\]/g'
find . -type f -print0 | xargs -0 sed -i '' 's/\[TestInitialize()\]/\[SetUp\]/g'
find . -type f -print0 | xargs -0 sed -i '' 's/\[TestCleanup\]/\[TearDown\]/g'
find . -type f -print0 | xargs -0 sed -i '' 's/\[TestCleanup()\]/\[TearDown\]/g'
find . -type f -print0 | xargs -0 sed -i '' 's/\[ClassInitialize\]/\[TestFixtureSetUp\]/g'
find . -type f -print0 | xargs -0 sed -i '' 's/\[ClassInitialize()\]/\[TestFixtureSetUp\]/g'