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 / 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 / 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 / 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;
/**
* Simplest web page scrape
*
* sudo port install phantomjs
* npm install -g casperjs
*/
var casper = require('casper').create(),
links = [],
images = [],
@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();
});