Skip to content

Instantly share code, notes, and snippets.

Freek Wielstra fwielstra

Block or report user

Report or block fwielstra

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@fwielstra
fwielstra / pre-push
Last active Apr 30, 2019 — forked from strootman/pre-push
A pre-push git hook which runs a gradle test task
View pre-push
#!/bin/sh
# this hook is in SCM so that it can be shared
# to install it, create a symbolic link in the projects .git/hooks folder
#
# i.e. - from the .git/hooks directory, run
# $ ln -s ../../git-hooks/pre-commit.sh pre-commit
#
# to skip the tests, run with the --no-verify argument
# i.e. - $ 'git commit --no-verify'
@fwielstra
fwielstra / aliases
Created Aug 16, 2016
git list shizzle
View aliases
# log format base
lformat = log --pretty=format:'%Cred%h%Creset %C(bold blue)%an%Creset %Cgreen(%cr) %Creset-%C(yellow)%d%Creset %s'
# formatted, graph, branches
l = !git lformat --graph --branches
# formatted, graph current branch only
lb = !git lformat --graph
# formatted, topo-order (?)
lt = !git lformat --graph --branches --topo-order
# formatted, no pager (use with -n to show last X entries)
lnp = !git --no-pager l
View Test.swift
import ObjectMapper
struct Test: Mappable {
let name: String
init?(_ map: Map) {
name = map["name"].valueOrFail()
if !map.isValid {
return nil
@fwielstra
fwielstra / errorhandling.js
Created Dec 18, 2012
wrapError replacement for backbone.js
View errorhandling.js
var sync = Backbone.sync;
Backbone.sync = function(method, model, options) {
if (!options.error) {
options.error = function(method, model, options) {
// custom error handling here.
}
}
};
sync(method, model, options);
@fwielstra
fwielstra / mock.js
Created Mar 2, 2012
mock.js - NodeJS webservice test double / proxy
View mock.js
/*
Uses latest & greatest NodeJS version (0.7.5), may cause external libraries
like Mu to not work because of a changed package (sys was renamed to util)
Fix manually by going into ./node_modules/mu and replacing all instances of
require('sys') with require('util'). Should just run under earlier versions
of Node as long as you replace the below require('util') with require('sys').
Download dependencies using 'npm install'
Run using node mock.js <port (optional)>
View gist:1899746
var util = require("util"),
http = require("http"),
url = require("url"),
fileSystem = require('fs'),
path = require('path');
var responseMap = [
{pattern:/\btest\?test\=true$/, response:"test-ok.xml"},
{pattern:/\btest\?test=true&henk=liev$/, response:"test-ok.xml"},
// 'begins with' test
@fwielstra
fwielstra / JSONParser.scala
Created Sep 9, 2011
Parsing a nested JSON object
View JSONParser.scala
case class Trip(
deviceId:String,
plannedDeparture: DateTime,
fromStation: String,
plannedDepartureFirstStation:DateTime,
viaStation: Option[String],
toStation: String,
plannedArrivalLastStation: DateTime) {
@fwielstra
fwielstra / api-test.js
Created Jun 14, 2011
An example unit test for our save thread method
View api-test.js
var nodeunit = require('nodeunit');
exports['API'] = nodeunit.testCase({
'The show() API method returns a specific thread by title and its replies by threadid': function(test) {
test.expect(4);
// our mock data
var posts = [{post: 'test'}, {post: 'test2'}];
var thread = {_id: '1234', title: 'my thread'};
@fwielstra
fwielstra / api.js
Created Jun 14, 2011
Our controller refactored
View api.js
module.exports = function(Thread, Post) {
return {
post: function(req, res) {
new Thread({title: req.body.title, author: req.body.author}).save();
},
list: function(req, res) {
Thread.find(function(err, threads) {
res.send(threads);
});
@fwielstra
fwielstra / api.js
Created Jun 14, 2011
An example NodeJS / Mongoose / Express application based on their respective tutorials
View api.js
/* The API controller
Exports 3 methods:
* post - Creates a new thread
* list - Returns a list of threads
* show - Displays a thread and its posts
*/
var Thread = require('../models/thread.js');
var Post = require('../models/post.js');
You can’t perform that action at this time.