Skip to content

Instantly share code, notes, and snippets.

View marcelog's full-sized avatar

Marcelo Gornstein marcelog

View GitHub Profile
@marcelog
marcelog / ls.mxs
Created October 29, 2012 01:04
poor (very) man's ls in elixir
#!/usr/bin/env elixir
files = File.wildcard(hd(System.argv()) <> "/*")
Enum.each files, fn(x) -> IO.puts x end
@marcelog
marcelog / gist:4063103
Created November 13, 2012 00:41
Multiple ami connections with nami (nodejs asterisk manager interface)
// Used to store different nami objects (dont worry about it)
var namis = [];
// Create your event emitter object, you will call "on()"
// on this one instead of "the namis".
var mainEventEmitter = ....;
// Assuming you have an array called "boxes" with the ami
// login info for each "ami box", and a "name" field.
for(var j = 0; j < boxes.length; j++) {
@marcelog
marcelog / generic_proxy.js
Last active December 17, 2015 01:10
Quick and small tcp proxy written in nodejs. Opens a socket and listens for incoming connections. For every new incoming connection, it will open a connection to the proxied host, and send whatever it gets from either side to the other.
#!/usr/bin/env node
var port_to = 6379;
var port_from = 63790;
var net = require('net');
var server = net.createServer(function(clientSocket) {
var targetSocket = net.connect({port: port_to});
targetSocket.on('data', function(data) {
clientSocket.write(data);
@marcelog
marcelog / generic_proxy.erl
Last active October 1, 2023 16:15
Quick and small tcp proxy written in erlang. Opens a socket and listens for incoming connections. For every new incoming connection, it will open a connection to the proxied host, and send whatever it gets from either side to the other.
-module(generic_proxy).
-export([run/0]).
-define(PORT_FROM, 63790).
-define(PORT_TO, 6379).
-define(BACKLOG, 10000).
run() ->
{ok, Socket} = gen_tcp:listen(0, [
@marcelog
marcelog / event_handler_guard.erl
Created May 11, 2013 15:20
gen_server that supervise and restarts event handlers (that implement the gen_event behavior) added with gen_event:add_sup_handler/3, suitable to be used in a standard otp supervision tree
-module(event_handler_guard).
-author('marcelog@gmail.com').
-behavior(gen_server).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Types.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-record(state, {}).
-type state():: #state{}.
@marcelog
marcelog / inet_utils.erl
Created June 15, 2014 12:39
inet_aton, inet_ntoa, ip_between functions for erlang. Convert an ip address address to/from its uint32 and text representations, check if the give ip address falls in a specific network range
-module(inet_utils).
-export([inet_aton/1, inet_ntoa/1]).
-export([ip_between/3]).
%% @doc Converts a binary string with a human readable ip
%% address representation into an uint32.
-spec inet_aton(binary()) -> pos_integer().
inet_aton(Ip) ->
[O1Bin, O2Bin, O3Bin, O4Bin] = binary:split(Ip, <<".">>, [global]),
@marcelog
marcelog / logstashUDP.js
Last active April 12, 2018 20:19
quick UDP Logstash logging from nodejs
var util = require('util');
var dgram = require('dgram');
function logstashUDP(host, port, type, message, fields, callback) {
var client = dgram.createSocket('udp4');
var logObject = {
'@timestamp': (new Date).toISOString(),
type: type,
message: message,
fields: fields
@marcelog
marcelog / webrtc2sip_optional_console.diff
Last active August 27, 2015 16:12
This is a patch to add an argument to webrtc2sip to optionally disable the console. After patching, recompile and start it with the argument --without-console
Index: mp_mediaproxy.cc
===================================================================
--- mp_mediaproxy.cc (revision 141)
+++ mp_mediaproxy.cc (working copy)
@@ -21,6 +21,7 @@
#include <libxml/tree.h>
+static int with_console = 1;
static char* sConfigXmlPath = NULL;
@marcelog
marcelog / libgsm-shared.patch
Created August 30, 2015 16:25
Patch needed to build libgsm as a shared library
diff -ur gsm-1.0-pl13.orig/Makefile gsm-1.0-pl13/Makefile
--- gsm-1.0-pl13.orig/Makefile 2006-04-26 22:14:26.000000000 +0300
+++ gsm-1.0-pl13/Makefile 2009-09-08 14:50:02.000000000 +0300
@@ -96,7 +96,7 @@
# Other tools
SHELL = /bin/sh
-LN = ln
+LN = ln -s
BASENAME = basename
@marcelog
marcelog / aws_lambda_hipchat_notifications.js
Created May 1, 2016 23:01
Send HipChat Notifications with SNS and Lambda
/*
Test it through SNS with a payload like:
{
"default": "{\"text\": \"hello world\", \"color\": \"yellow\"}",
"lambda": "{\"text\": \"hello world\", \"color\": \"yellow\"}"
}
*/
var http = require('http');
var https = require('https');