Skip to content

Instantly share code, notes, and snippets.

@pfigue
pfigue / count_words.erl
Created November 15, 2011 17:58
Count the number of words of a string in Erlang
-module(count_words).
-export([count_words/2]).
count_words([32 | Tail], NumWords) -> count_words(Tail, NumWords);
count_words([Letter | Tail], NumWords) -> 1 + count_words2(Tail, NumWords);
count_words([], NumWords) -> NumWords.
count_words2([32 | Tail], NumWords) -> count_words(Tail, NumWords);
count_words2([Letter | Tail], NumWords) -> count_words2(Tail, NumWords);
count_words2([], NumWords) -> NumWords.
@pfigue
pfigue / max.erl
Created November 15, 2011 20:54
Return the biggest term in a list
-module(max).
-export([max/1, max0/2]).
max([]) -> [];
max([Head | Tail]) -> max0(Tail, Head).
max0([], CurrentMax) -> CurrentMax;
max0([Head | Tail], CurrentMax) ->
if
CurrentMax >= Head -> max0(Tail, CurrentMax);
@pfigue
pfigue / gist:1368320
Created November 15, 2011 20:57
Example of my Erlang max:max()
6> c(max).
{ok,max}
8> max:max([]).
[]
10> max:max([10]).
10
11> max:max([2, 3, 10]).
10
13> max:max([2, 3, 10, 1]).
10
@pfigue
pfigue / bin2dec.erl
Created November 15, 2011 21:25
From binary to decimal, in erlang
-module(bin2dec).
-export([bin2dec/1, bin2dec_/2]).
bin2dec("") ->
0;
bin2dec(List) -> bin2dec_(List, 0).
bin2dec_([], Sum) ->
Sum;
bin2dec_([48 | Tail], Sum) -> %48 is ascii code for 0
@pfigue
pfigue / create_rabbit_vhost.sh
Created May 23, 2012 10:52
Create a RabbitMQ vhost and user, and provide permissions
#!/bin/bash
# Syntax: create_rabbit_vhost.sh <vhost> <user> <pass>
if [ $# != 3 ]; then
echo "Fail! Syntax: $0 <vhost> <user> <pass>"
exit 1
fi
rabbitmqctl add_vhost $1
@pfigue
pfigue / hosts.txt
Created June 3, 2012 07:12
Subdomain list to use with Pentbox in bruteforcing DNS
0
01
02
03
1
10
11
12
13
14
@pfigue
pfigue / cron_alive.sh
Created July 6, 2012 15:53
Icinga Plugin to monitor if cron is alive
#!/bin/bash
# Determine if cron is running
# Comes from https://gist.github.com/3061023
UNKNOWN_STATE=3
CRITICAL_STATE=2
WARNING_STATE=1
OK_STATE=0
@pfigue
pfigue / receiving_cookie.sh
Created October 18, 2012 06:34
Who gives me cookies?
@pfigue
pfigue / ec2-user-data-parser.py
Last active December 29, 2015 15:28
Facter fact code and a python script to read some user defined AWS EC2 instance properties during provisioning.
# Invocation example:
#
# $ curl -s "http://169.254.169.254/latest/user-data/" > /tmp/test.yaml
# $ cat /tmp/test.yaml
# instance:
# flavor: application-server
# $ abc=$(cat /tmp/test.yaml | python ec2-user-data-parser.py instance flavor)
# $ echo $abc
# application-server
# $
@pfigue
pfigue / timezone.pp
Last active September 6, 2016 02:56
Puppet Manifest to set the timezone in the system.
file { '/etc/timezone':
ensure => present,
content => "Europe/Berlin\n",
}
exec { 'reconfigure-tzdata':
user => root,
group => root,
command => '/usr/sbin/dpkg-reconfigure --frontend noninteractive tzdata',
}