Skip to content

Instantly share code, notes, and snippets.

View martinheidegger's full-sized avatar
😅
working

Martin Heidegger martinheidegger

😅
working
View GitHub Profile
@martinheidegger
martinheidegger / gist:4232590
Created December 7, 2012 11:13
npm problems
{
"name": "myProject",
"description": "A test project to get my dependencies running",
"version": "1.0.0",
"preferGlobal": "true",
"dependencies": {
"mocha" : "*"
}
}
var phantom=require('phantom');
phantom.create(function(ph) {
ph.createPage(function(page) {
page.set('onInitialized', function() {
console.log("We are now inside onInitialized");
});
page.set('onLoadStarted', function() {
console.log("We are now inside onLoadStarted");
@martinheidegger
martinheidegger / mb_include.php
Last active December 24, 2015 15:59
Including a php file with a different encoding can be very frustrating. Here is a method to get that done!
define("MB_INCLUDE_BLOCK", 3000);
function mb_echo($str, $to_encoding, $from_encoding) {
$len = mb_strlen($str);
for($pos=0; $pos < $len;) {
$part = mb_strcut($str, $pos, min($len-$pos, MB_INCLUDE_BLOCK), $from_encoding);
$pos += strlen($part);
$converted = mb_convert_encoding($part, $to_encoding, $from_encoding);
echo $converted;
var rl = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
function Point(x, y){
this.x = x;
this.y = y;
}
@martinheidegger
martinheidegger / reset-audio.sh
Created April 14, 2014 06:15
A tiny little script that fixes the audio of a macbook air after going to sleep mode with headphones.
#!/bin/bash
sudo killall coreaudiod
sudo kextunload /System/Library/Extensions/AppleHDA.kext
sudo kextload /System/Library/Extensions/AppleHDA.kext
@martinheidegger
martinheidegger / node.sublime-build
Created May 13, 2014 08:19
Sublime build script to test a node system
{
"cmd": ["npm", "test"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${project_path:${folder:${file_path}}}",
"selector": "package.json"
}
@martinheidegger
martinheidegger / docker-gc.sh
Created August 29, 2014 02:24
Small tool to remove all the docker images and containers that you once created and forgot about (I added this to ~/.zshrc)
#!/bin/bash
docker-gc() {
docker rm `docker ps -a -q`
docker rmi `docker images -q -f="dangling=true"`
}
@martinheidegger
martinheidegger / thoughts.md
Created August 29, 2014 08:58
Thoughts about easier joi definitions.
module.exports = Joi.object({
   a: Joi.string()
}).description("");

is a lot to write. It would be cool if it could look like

object({
@martinheidegger
martinheidegger / thoughts.md
Last active August 29, 2015 14:05
Thoughts on quality assurance of joi definitions

Joi is nice but it can also be used unsufficiently. For example: If you want to make sure that didn't forget a restriction on every input it would be nice to lint the joi definition for a quality assurance.

require("joi-qa").sizeRestrictions().wellDocumented().noRegExp().hasExamples().verify({
   ...
});
@martinheidegger
martinheidegger / npm-i.sh
Last active August 29, 2015 14:06
Shell script to install a package locally and automatically put a require statement in the clipboard. (mac) "$ curl -sL http://git.io/MPadbw >> ~/.zshrc"
#
# npm-i (https://gist.github.com/martinheidegger/5217df563c8e1edcacbd)
# Helper to make installing a package in node-js more comfortable.
#
npm-i() {
if [[ -z "$1" ]]; then
echo "Usage: npm-i <package> (var)"
else
npm install $1 --save
if [[ "$2" == "var" ]]; then