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 / add-item-to-list.js
Created December 2, 2014 06:07
Small script that adds a list of item to a list by an indexKey.
function addTo(list, indexField, generator) {
var storage = {};
generator = generator || function (key) {
return key;
}
list.forEach(function (item) {
storage[item[indexField]] = item;
});
@martinheidegger
martinheidegger / grunt-i.sh
Last active August 29, 2015 14:06
Helper to make installing a plugins in grunt more comfortable. (assumes $ npm i json -g is installed) '$ curl -sL http://git.io/XxlNhg >> ~/.zshrc'
#
# grunt-i (https://gist.github.com/martinheidegger/8099dcfae0591f10c0cd)
# Helper to make installing grunt and grunt plugins more fun. (doesn't require global grunt task)
#
grunt-i() {
if [[ $1 == "--help" ]]; then
echo "Usage: grunt-i [-b] [-c] |
grunt-i <package> [-r]
Installs grunt or a grunt plugin in a way that doesn't clutter the Gruntfile.js
@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
@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 / 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 / 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 / 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 / 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
var rl = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
function Point(x, y){
this.x = x;
this.y = y;
}
@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;