Skip to content

Instantly share code, notes, and snippets.

View aichholzer's full-sized avatar
🚴‍♂️
Improving...

Stefan Aichholzer aichholzer

🚴‍♂️
Improving...
  • Same as you...
View GitHub Profile
@aichholzer
aichholzer / prettyPrinter.js
Last active August 29, 2015 14:09
Simple pretty printer addition for the console.
var express = require('express'),
app = express();
app.use(function (req, res, next) {
req.prettify = function(json) {
json = json || this.body;
return console.log(JSON.stringify(json, null, 2));
};
next();
});
/**
* Simplest web page scrape
*
* sudo port install phantomjs
* npm install -g casperjs
*/
var casper = require('casper').create(),
links = [],
images = [],
@aichholzer
aichholzer / weaver.js
Last active August 29, 2015 14:26
String weaver
'use strict';
module.exports = function stringWeaver(stringArray, sortByLength) {
sortByLength = sortByLength || true;
var result = [],
index = 0,
lastIndex = 0;
@aichholzer
aichholzer / shufflr.js
Last active December 21, 2015 01:05
Shuffle & match a list of names for whatever occasion.
'use strict';
class Shufflr {
constructor () {
process.argv.splice(0, 2);
this.people = process.argv.sort();
this.selectedPeople = [];
@aichholzer
aichholzer / gist:6ce25f9f69fcbc38adfe0be6d79cf9bc
Created March 29, 2017 00:21
Parse MongoDB duplicate error
'use strict';
let err = 'E11000 duplicate key error collection: home.users index: name_1 dup key: { : "francis" }';
let err = 'E11000 duplicate key error collection: home.users index: email.personal_1 dup key: { : "me@me.com" }';
let [i, field, input] = err.match(/index:\s([.a-z]+).*{\s?\:\s?"(.*)"/i);
console.log(field, input);
@aichholzer
aichholzer / bash_profile.sh
Last active September 22, 2017 04:43
Shell
export PS1="\n\[\033[1;102m\]\[\033[1;30m\] \A \[\033[1;103m\]\[\033[1;30m\] \u \[\033[0;107m\]\[\033[1;30m\] \w \[\033[0m\] \[\`if [ \$? != 0 ]; then echo 😠 ' '; fi \`\]"
alias ls='ls -lhaG'
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
alias gm="grunt nodemon"
alias gish="ssh -T git@github.com"
@aichholzer
aichholzer / promiseMap.js
Created November 3, 2017 10:49
Promise maps
const heartbeats = [1, 2, 3].map((value) => Promise.resolve({ id: value, date: +new Date() }));
Promise.all(heartbeats).then((values) => {
console.log(values.map((value) => !value.date ? null : {
id: value.id,
name: 'location',
heartbeat: value.date
}).filter(v => v).sort()
);
});
@aichholzer
aichholzer / jquery.animator.js
Last active November 9, 2017 03:31
Element animator for jQuery
/**
* Element fadeIn plugin for jQuery.
* @author Stefan Aichholzer <https://github.com/aichholzer>
* @param options -Object defining the animation's end result.
*
* {
* opacity: 1,
* marginBottom: 5,
* duration: 50
* }
@aichholzer
aichholzer / clean.js
Created February 7, 2018 21:59
Remove all empty properties from an object, recursively.
const sample = {
a: 'Hello',
b: '', // Will be removed
c: null,
d: {
a: 1,
b: '', // Will be removed
c: 3,
d: {
a: 1,
@aichholzer
aichholzer / client.js
Created May 2, 2018 05:02
Gzip - client/server
const http = require('http');
const { readFile } = require('fs');
const { gzip } = require('zlib');
const { promisify } = require('util');
const run = async () => {
try {
const data = await promisify(readFile)('./menu.json');
const req = http.request({
method: 'POST',