Skip to content

Instantly share code, notes, and snippets.

View marcbachmann's full-sized avatar
🏳️‍🌈

Marc Bachmann marcbachmann

🏳️‍🌈
View GitHub Profile
@marcbachmann
marcbachmann / nodejs passport configuration
Last active December 15, 2015 22:09
This is a passport LocaStrategy with custom error messages from my app.
passport.use(new LocalStrategy(
function(username, password, done) {
if (username.indexOf('@') == -1) {
username = username + '@example.com';
}
User.findOne({ 'email': username.toLowerCase()}, function(err, user) {
if (err) { return done(err); }
if (!user) {
var error = new Error('User not found or wrong Credentials');
@marcbachmann
marcbachmann / nodejs passport authenticate
Last active December 15, 2015 22:09
Login function with express-validator
function postLogin(req, res, next){
req.assert('username', 'username is required').notEmpty();
req.assert('password', 'password is required').notEmpty();
var username = (req.body.username)? req.body.username: '';
var password = (req.body.password)? req.body.password: '';
var errors = req.validationErrors(true);
if (errors) {
res.render('login.jade', {locals: { title: 'Login Error', username: username, password: password, errors: errors}});
return;
@marcbachmann
marcbachmann / index.coffee
Last active August 29, 2015 14:03
Spellcheck test
# http://jsperf.com/in-vs-hasownproperty-vs-has/2
fs = require('fs')
_ = require('lodash')
async = require('async')
nodehun = require('nodehun')
redis = require("redis")
cache = redis.createClient()
affbuf = fs.readFileSync('/Users/marcbachmann/Desktop/de-NZZ.aff');
@marcbachmann
marcbachmann / db.coffee
Created October 2, 2014 08:37
mongodb-native Entity class
mongodb_url = require('../../config').get('mongodb:url')
MongoClient = require('mongodb').MongoClient
exports.db = null
exports.connect = (callback) ->
exports.client = new MongoClient()
MongoClient.connect mongodb_url, (err, db) ->
return callback(err) if err
exports.db = db
return callback(null, db)
@marcbachmann
marcbachmann / delete-multiple-github-tags.sh
Last active March 4, 2016 17:22
Delete all semver remote tags
T=$(git tag -l | grep -v '^[0-9\.]*$') \
&& git tag -d $(echo $T) \
&& for i in $(echo $T); do git push origin :refs/tags/$i; done
@marcbachmann
marcbachmann / example.coffee
Last active August 29, 2015 14:27
Knex Migration Class
db = require('knex')(yourConfig)
Migration = require('../../lib/db').Migration
upgrade = new Migration(db)
upgrade.createTable 'documents', (t) ->
t.uuid('id')
t.text('title')
upgrade.createTable 'users', (t) ->
@marcbachmann
marcbachmann / Dockerfile
Created August 25, 2015 12:37
Docker elasticsearch with modified config file
FROM elasticsearch
RUN sed -i.bak -e "s|^varname:.*$|varname: \"value"|;" /data/elasticsearch.yml
RUN plugin -i elasticsearch/marvel/latest
@marcbachmann
marcbachmann / sound.scpt
Created September 13, 2015 13:04
Switch audio output on mac
tell application "System Preferences" to activate
tell application "System Events"
get properties
tell application "System Preferences"
reveal anchor "output" of pane id "com.apple.preference.sound"
end tell
tell process "System Preferences"
set theRows to every row of table 1 of scroll area 1 of ¬
tab group 1 of window "sound"
repeat with aRow in theRows
@marcbachmann
marcbachmann / backup.sh
Created September 20, 2015 00:47
Database backup script
#!/bin/bash
# Based on https://gist.github.com/2206527
echo -e "Backup MySQL Databases to S3"
# Basic variables
host="localhost"
mysqlpass="rootpass"
bucket="s3://bucketname"
accesskey="awsaccesskey"
secretkey="awssecretkey"
@marcbachmann
marcbachmann / populate.coffee
Last active October 8, 2015 05:33
Small script to populate collections
_ = require('lodash')
module.exports =
populate = (mapName, fromCollection, toCollection, fromId, toId='id') ->
indexed = _.indexBy(toCollection, toId)
for doc in fromCollection || []
doc[mapName] = indexed[doc[revision_id]]
docs = [