Skip to content

Instantly share code, notes, and snippets.

View mpneuried's full-sized avatar
🏠
Working from home

M. Peter mpneuried

🏠
Working from home
View GitHub Profile
@mpneuried
mpneuried / with.ex
Last active October 13, 2016 13:02
Small example how to use with
defmodule WithTest do
def run do
with{:ok, a} <- fun("A"),
{:ok, b} <- fun("B"),
{:ok, c} <- fun("C")
do
{:ok, [a,b,c] }
else
{:error, err} ->
{:error, err}
@mpneuried
mpneuried / rsmq-worker-event-counter.js
Last active June 20, 2016 11:32
Small script to test the event listener count after the `.start()` and `.stop()` methods of rsmq-worker
var RSMQWorker = require( "./" );
var RedisSMQ = require("rsmq");
var WORKERCOUNT = 12;
var rsmq = new RedisSMQ( {host: "127.0.0.1", port: 6379, ns: "rsmq"} );
rsmq.setMaxListeners(WORKERCOUNT)
// count the event listener per event
var countListener = function(){
var _ret = {};
@mpneuried
mpneuried / add-hosts.sh
Last active January 21, 2016 12:29
Scritp's to change /etc/hosts. Tahnks to Claus Witt, http://clauswitt.com/319.html.
DEFAULT_IP=127.0.0.1
IP=${2:-$DEFAULT_IP}
sed -ie "\| $1\$|d" /etc/hosts
echo "$IP $1" >> /etc/hosts
exit 0
@mpneuried
mpneuried / update-hosts.sh
Last active January 19, 2020 08:45 — forked from bzerangue/update-hosts.sh
A small shell script that will add and remove lines from the hosts file. Originally created by Claus Witt, http://clauswitt.com/319.html.
#! /bin/sh
# @author: Claus Witt
# http://clauswitt.com/319.html
# Adding or Removing Items to hosts file
# Use -h flag for help
DEFAULT_IP=127.0.0.1
IP=${3:-$DEFAULT_IP}
@mpneuried
mpneuried / start_nsq.sh
Created December 2, 2015 14:41
Start a NSQ environment
nsqlookupd -http-address=127.0.0.1:4161 -tcp-address=127.0.0.1:4160 &
nsqlookupd -http-address=127.0.0.1:4163 -tcp-address=127.0.0.1:4162 &
nsqd -lookupd-tcp-address=127.0.0.1:4160 -lookupd-tcp-address=127.0.0.1:4162 &
nsqadmin -lookupd-http-address=127.0.0.1:4161 -lookupd-http-address=127.0.0.1:4163 &
@mpneuried
mpneuried / jquery-ajax-json-post.coffee
Created November 18, 2015 07:01
jQuery: How to post with a json body
_data =
foo: 23
bar: 42
bazz: null
$.ajax
url: _path
type: "POST"
data: JSON.stringify( _data )
contentType: "application/json; charset=utf-8"
@mpneuried
mpneuried / dh_test.js
Created October 29, 2015 14:48
Diffie-Hellman Tests in Node
// Install: "npm i prompt"
// Usage: "node dh.js"
var crypto, dh, prompt;
crypto = require('crypto');
prompt = require('prompt');
dh = crypto.getDiffieHellman('modp5');
dh.generateKeys();
@mpneuried
mpneuried / grunt-fontello-edit.coffee
Created October 23, 2015 06:01
Fontello Grunt edit helper
###
USAGE:
1. Make sure you have a valid fontello config file
2. call "grunt edit-font" -> your browser will open with a session based on your config file
3. Edit your font within fontello and click "Save session"
4. call "grunt update-fonts". This will call the task "update-fonts-config" to download the session zip and replace the config. Then it's call the task `fontello:standard` based on your config.json.
###
@mpneuried
mpneuried / export_browser_module.coffee
Created September 16, 2015 12:14
code to export a browser module by commonjs, amd or global-var
root = @
MYMODULE =
foo: 42
fizzy: ->
return "bubbele"
# Export the module
if typeof module isnt 'undefined' and module.exports
exports = module.exports = MYMODULE
@mpneuried
mpneuried / trello_to_markdown.coffee
Created August 7, 2015 19:00
Export a trello board to markdown. Will generate H2 with list titles and a list element with every card name
txt = []
$( ".list" ).each ( idx, tbl )->
txt.push "\n## " + $(tbl).find( "h2" ).text() + "\n"
$(tbl).find( ".js-card-name" ).each (idx, card)->
txt.push "- " + card.lastChild.data
txt.join( "\n" )