Skip to content

Instantly share code, notes, and snippets.

Avatar

Martynas Pumputis brb

View GitHub Profile
@brb
brb / recaptcha.erl
Created Jun 12, 2012
Verifying reCAPTCHA with Erlang
View recaptcha.erl
-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 Oct 10, 2015
Erlang code snippets for snipmate.vim
View erlang.snippets
# module and export all
snippet mod
-module(${1:`Filename('', 'my')`}).
-compile([export_all]).
start() ->
${2}
stop() ->
@brb
brb / inet_pid.erl
Created Sep 25, 2012
Erlang PID by inet PORT
View inet_pid.erl
%% @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 Oct 22, 2012
LTU flag in XPM
View lt15.xmp
static char * lt15_xpm[] = {
"15 15 4 1",
" c None",
". c #FFFF00",
"+ c #1AA302",
"@ c #FC0000",
"...............",
"...............",
"...............",
"...............",
@brb
brb / build_erl.sh
Created Jan 31, 2013
Build deb package from Erlang/OTP source
View build_erl.sh
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 Aug 1, 2013
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.
View prepare-commit-msg
#!/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 Oct 20, 2013
C code snippets for snipmate
View c.snippets
# 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 Nov 23, 2020
area41 2014 challenge writeup
View area14_2014_challenge_writeup.md

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 Jun 6, 2014
a hack to enable paste from clipboard for pinentry (gtk2, based on 0.8.3 vsn). fcks up the security (!)
View pinentry-gtk2-0.8.3_paste.patch
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 Aug 29, 2015
poor man's Elastic IP
View ec2-update-etchosts.sh
#!/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"