Skip to content

Instantly share code, notes, and snippets.

View brb's full-sized avatar

Martynas Pumputis brb

View GitHub Profile
@brb
brb / recaptcha.erl
Created June 12, 2012 13:59
Verifying reCAPTCHA with Erlang
-module(recaptcha).
-export([verify/3]).
-define(PRIVATE_KEY, "YOU_RPRIVATE_KEY").
-define(URL, "http://www.google.com/recaptcha/api/verify").
%% @doc WARNING: 'inets' application should be started!
-spec verify(list(), list(), list()) -> ok |
{error, invalid_site_private_key | invalid_request_cookie |
incorrect_captcha_sol}.
@brb
brb / erlang.snippets
Last active October 10, 2015 23:58
Erlang code snippets for snipmate.vim
# module and export all
snippet mod
-module(${1:`Filename('', 'my')`}).
-compile([export_all]).
start() ->
${2}
stop() ->
@brb
brb / inet_pid.erl
Created September 25, 2012 14:50
Erlang PID by inet PORT
%% @doc Return pid of a process which opened a socket binded to a given port.
-spec get_pid(inet:port_number(), 'tcp' | 'udp' | 'sctp') -> pid() | undefined.
get_pid(Port, Proto) when is_integer(Port), is_atom(Proto) ->
Name = name(Proto),
InetPorts = [P || P <- erlang:ports(),
{name, Name} == erlang:port_info(P, name)],
try
lists:filter(
fun (P) ->
@brb
brb / lt15.xmp
Created October 22, 2012 15:37
LTU flag in XPM
static char * lt15_xpm[] = {
"15 15 4 1",
" c None",
". c #FFFF00",
"+ c #1AA302",
"@ c #FC0000",
"...............",
"...............",
"...............",
"...............",
@brb
brb / build_erl.sh
Created January 31, 2013 08:25
Build deb package from Erlang/OTP source
git svn clone svn://svn.debian.org/svn/pkg-erlang/erlang/trunk debian-erlang
cd debian-erlang; git checkout 72f44f02d383d2858ed7480db7e5bbb662ea48d4
git clone git://github.com/erlang/otp.git
cd otp
git checkout OTP_R15B03
rm -rvf lib/*/doc/{archive,standard}/
ln -s ../debian-erlang/debian
./otp_build autoconf
dpkg-buildpackage -rfakeroot -uc -b
@brb
brb / prepare-commit-msg
Created August 1, 2013 08:25
Git hook for appending an issue id into commit messages. The issue id is taken from branch name which should be in a "foobar-ISSUE-ID" format.
#!/bin/bash
regexp=".*-([A-Z].*-[0-9]*)"
branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
if [[ "$branch" =~ $regexp ]]; then
refs_id=${BASH_REMATCH[1]}
if [ "$2" = message ]; then
echo -ne "\n${refs_id}" >> "$1"
else
sed -i "1s/^$/\n\n${refs_id}/g" "$1"
@brb
brb / c.snippets
Created October 20, 2013 19:31
C code snippets for snipmate
# main()
snippet main
int
main(int argc, const char **argv)
{
${1}
return 0;
}
snippet mainn
int
@brb
brb / area14_2014_challenge_writeup.md
Last active November 23, 2020 14:35
area41 2014 challenge writeup

Intro

Being a cheapass student, I couldn't resist to try to win a free entrance to [Area41 Security Conference][3] (don't mix with Alcoholics Anonymous Area 41 in Nebraska) after spotting @gandro23 retweet about the conference and the challenge.

Level 01

The challenge starts after downloading and extracting a [binary][1]. A quick look

@brb
brb / pinentry-gtk2-0.8.3_paste.patch
Created June 6, 2014 13:10
a hack to enable paste from clipboard for pinentry (gtk2, based on 0.8.3 vsn). fcks up the security (!)
diff --git a/gtk+-2/pinentry-gtk-2.c b/gtk+-2/pinentry-gtk-2.c
index 421bc02..91a9fbf 100644
--- a/gtk+-2/pinentry-gtk-2.c
+++ b/gtk+-2/pinentry-gtk-2.c
@@ -186,7 +186,7 @@ button_clicked (GtkWidget *widget, gpointer data)
gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (time_out)));
#endif
- s = gtk_secure_entry_get_text (GTK_SECURE_ENTRY (entry));
+ s = gtk_entry_get_text (GTK_ENTRY (entry));
@brb
brb / ec2-update-etchosts.sh
Last active August 29, 2015 14:08
poor man's Elastic IP
#!/bin/bash
# Update /etc/hosts with public non-elastic IPs of EC2 instances.
# Assumes that a name is set for each instance and there is only one value inside tags section.
PREFIX="aws_"
FILTER=".Reservations[].Instances[] |
select(.PublicIpAddress != null) |
.PublicIpAddress + \" $PREFIX\" + .Tags[].Value"