Skip to content

Instantly share code, notes, and snippets.

View joerx's full-sized avatar
💭
I may be slow to respond.

Jörg Henning joerx

💭
I may be slow to respond.
  • Transferwise
  • Singapore
View GitHub Profile
var express = require('express');
var app = express();
// ...
module.exports = app;
@joerx
joerx / user.js
Created June 7, 2014 17:18
Define a mongoose model in a module on it's own.
exports = db.model('User', {
name: String
, dob: { type: Date}
, age: Number
, email_id: String
});
@joerx
joerx / astah
Last active August 29, 2015 14:02
Astah Community launcher script and .desktop
#!/bin/sh
JAR=/opt/astah_community/astah-community.jar
JAVA_OPTS="-Xms16m -Xmx384m"
${JAVA_HOME}/bin/java $JAVA_OPTS -jar $JAR $1 $2 $3
@joerx
joerx / genymotion.desktop
Created June 28, 2014 05:59
genymotion.desktop
[Desktop Entry]
Encoding=UTF-8
Name=Genymotion
Comment=Alternative Android Emulator based on VirtualBox
Exec=/opt/genymotion/genymotion
Icon=/opt/genymotion/icons/icon.png
NoDisplay=false
Terminal=false
Type=Application
Categories=Application;Development;
@joerx
joerx / Preferences.sublime-settings
Last active September 23, 2015 11:21
Sublime preferences
{
"color_scheme": "Packages/Theme - Spacegray/base16-eighties.dark.tmTheme",
"font_face": "Source Code Pro",
"font_size": 12,
"ignored_packages":
[
"Vintage"
],
"overlay_scroll_bars": "enabled",
"preview_on_click": true,
@joerx
joerx / gist:ea16b9af330e0c346155
Last active January 15, 2021 06:09
Stubbing email sending in tests
// This is the simplest possible approach - use a custom module to wrap a single, pre-configured
// mail transport instance and then use sinon.js to stub out that modules sendmail()
// This approach has its limitations, but it is still better than having 'if(NODE_ENV === 'test')'
// all over the code base.
// -- app/sendmail.js --
var nodemailer = require('nodemailer');
var config = require('config').email;
@joerx
joerx / stripslashes.php
Created December 19, 2014 04:22
Strip leading/trailing slashes from a path-like string
<?php
// Replace '#' with whatever substitute desired, use '' to strip
echo preg_replace('@^/|/$@', '#', '/foo/'); // #foo#
@joerx
joerx / mkuri.php
Created January 5, 2015 06:56
PHP: Simple way to strip slashes and assemble a path-like structure avoiding missing/duplicate slashes.
<?php
function mkUri($base, $path) {
$base = preg_replace("/\/$/", "", $base);
$path = preg_replace("/^\//", "", $path);
return "$base/$path";
}
echo mkUri("http://localhost/", "/foo") . "\n";
echo mkUri("http://localhost/", "foo") . "\n";
@joerx
joerx / stripslashes.php
Created January 5, 2015 06:57
PHP: One-liner to strip leading and trailing slashes
<?php
echo preg_replace('@^/|/$@', '', '/foo/'); // 'foo'
@joerx
joerx / emitter.js
Last active August 29, 2015 14:16
EventEmitter
var EventEmitter = require('events').EventEmitter;
var emitter = new EventEmitter();
var obj = Object.create(EventEmitter.prototype);
obj.say = function say() {
obj.emit('hello');
}