Skip to content

Instantly share code, notes, and snippets.

View m-2k's full-sized avatar
🌴
On vacation

Andy m-2k

🌴
On vacation
View GitHub Profile
@m-2k
m-2k / erlang_fast_hex.erl
Created September 27, 2017 19:10
Erlang fast HEX decoder/encoder
% Erlang fast HEX decoder/encoder
digit(0) -> $0; digit(1) -> $1; digit(2) -> $2; digit(3) -> $3;
digit(4) -> $4; digit(5) -> $5; digit(6) -> $6; digit(7) -> $7;
digit(8) -> $8; digit(9) -> $9; digit(10) -> $a; digit(11) -> $b;
digit(12) -> $c; digit(13) -> $d; digit(14) -> $e; digit(15) -> $f.
hex(Bin) -> << << (digit(A1)),(digit(A2)) >> || <<A1:4,A2:4>> <= Bin >>.
unhex(Hex) -> << << (erlang:list_to_integer([H1,H2], 16)) >> || <<H1,H2>> <= Hex >>.
@m-2k
m-2k / email.erl
Created September 26, 2017 15:40 — forked from seriyps/email.erl
Send emails using Erlang gen_smtp shortcut.
% Send plaintext email using gen_smtp https://github.com/Vagabond/gen_smtp
% This function sends email directly to receiver's SMTP server and don't use MTA relays.
%
% Example plaintext email:
% Mail = mail_plain(<<"Bob <sender@example.com>">>, <<"Alice <receiver@example.com>">>, <<"The mail subject">>, <<"The mail body">>),
% send_email(Mail).
%
% Example email with image attachment:
% ImgName = "image.jpg",
% {ok, ImgBin} = file:read_file(ImgName),
@m-2k
m-2k / intercept-https-with-python-mitmproxy.md
Created September 2, 2017 19:11 — forked from dannvix/intercept-https-with-python-mitmproxy.md
Intercept and manipulate HTTPs traffic with Python and mitmproxy

Intercepts HTTPs Traffic with Python & mitmproxy

Warning

This Gist is created in 2014, and it's highliy outdated now, according to one of mitmproxy's manjor contributor (check his comment below). Thanks for letting us know, @mhils!

Introduction

Modern applications usually make use of back-end API servers to provide their services. With a non-transparent HTTPs proxy, which intercepts the communication between clients and servers (aka the man-in-the-middle scheme), you can easily manipulate both API requests and responses.

@m-2k
m-2k / LICENSE
Created May 29, 2017 11:38 — forked from targodan/LICENSE
Complementing code for my blog post "Decoding audio files with ffmpeg": https://www.targodan.de/post/decoding-audio-files-with-ffmpeg
The MIT License (MIT)
Copyright (c) 2016 Luca Corbatto
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
@m-2k
m-2k / guide.md
Created May 17, 2017 21:39 — forked from jayktaylor/guide.md
Instructions for installing Python 3.5 using pyenv on Debian Jessie

Installing Python 3.5 on Debian Jessie with pyenv

Debian Jessie does not come with the correct Python version out of the box, and instead comes with Python 2. To be able to install Python 3(.5), we have a few options. We could build and install from source, but as per Debian's website, we shouldn't do this. Instead, we will use pyenv, a tool that allows users to switch Python versions easily without breaking their system.

Installing pyenv

To install pyenv, we will use the official installer.

curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash
@m-2k
m-2k / introrx.md
Created January 30, 2017 18:57 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@m-2k
m-2k / gist:04f7e31075065ac3c4b7024dfe98c765
Created January 20, 2017 15:15 — forked from Bouke/gist:10454272
Install FreeTDS, unixODBC and pyodbc on OS X

First, install the following libraries:

$ brew install unixodbc
$ brew install freetds --with-unixodbc

FreeTDS should already work now, without configuration:

$ tsql -S [IP or hostname] -U [username] -P [password]
locale is "en_US.UTF-8"

locale charset is "UTF-8"

@m-2k
m-2k / exit-exit-sc.user.js
Created December 23, 2016 22:28 — forked from noromanba/exit-exit-sc.user.js
remove exit.sc redirector from links on SoundCloud for UserScript
// ==UserScript==
// @name exit exit.sc
// @namespace http://noromanba.flavors.me
// @description remove exit.sc redirector from links on SoundCloud for UserScript
// @include https://soundcloud.com/*
// @grant none
// @noframes
// @run-at document-end
// @version 2016.6.8.1
// @homepage https://gist.github.com/noromanba/6b83ef63fe8b794364267bd832fdbc71
@m-2k
m-2k / Liberal Regex Pattern for Web URLs
Created September 4, 2016 09:30 — forked from gruber/Liberal Regex Pattern for Web URLs
Liberal, Accurate Regex Pattern for Matching Web URLs
The regex patterns in this gist are intended only to match web URLs -- http,
https, and naked domains like "example.com". For a pattern that attempts to
match all URLs, regardless of protocol, see: https://gist.github.com/gruber/249502
# Single-line version:
(?i)\b((?:https?:(?:/{1,3}|[a-z0-9%])|[a-z0-9.\-]+[.](?:com|net|org|edu|gov|mil|aero|asia|biz|cat|coop|info|int|jobs|mobi|museum|name|post|pro|tel|travel|xxx|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|s
//
// Regular Expression for URL validation
//
// Author: Diego Perini
// Updated: 2010/12/05
// License: MIT
//
// Copyright (c) 2010-2013 Diego Perini (http://www.iport.it)
//
// Permission is hereby granted, free of charge, to any person