Skip to content

Instantly share code, notes, and snippets.

View cosimo's full-sized avatar
🇳🇴

Cosimo Streppone cosimo

🇳🇴
View GitHub Profile
@cosimo
cosimo / pre-commit
Created February 26, 2014 12:59
Puppet manifests and templates syntax check git pre-commit hook
#!/bin/bash
# pre-commit hook to syntax check puppet manifests and erb templates
# at checkin.
# Stig Sandbeck Mathisen <ssm@fnord.no>
#
# Modified to run with puppet < 2.7 as well, Cosimo 13/Dec/2011
#
# Requirements:
perl6-lwp-simple $ ufo
No such method 'split' for invocant of type 'CompUnitRepo::Local::Installation'
in sub mkpath at /home/cosimo/.perl6/2014.05-118-ge88e462/bin/ufo:161
in sub get_prefix at /home/cosimo/.perl6/2014.05-118-ge88e462/bin/ufo:148
in sub MAIN at /home/cosimo/.perl6/2014.05-118-ge88e462/bin/ufo:69
in block at /home/cosimo/.perl6/2014.05-118-ge88e462/bin/ufo:221
@cosimo
cosimo / rtail
Created September 22, 2014 14:45
#!/usr/bin/perl
=head1 NAME
rtail - tail multiple files remotely
=head1 SYNOPSIS
./rtail --host h1 --host h2 --command 'tail -f /var/log/syslog'
./rtail --user someuser --host h1 --host h2 --command 'uname -a'
@cosimo
cosimo / graphite-null-value-aggregates-problem
Created November 21, 2014 10:03
Problem with graphite aggregates and NULL values coming from some hosts
We're using graphite 0.9.12.
We have per-datacenter aggregates and total-across-datacenters
aggregates, constructed as follows (flush interval is 10s):
# Total
<project>.<env>.aggregates.total.recommender.api.suggestions.rate (10) = sum <project>.<env>.*.*.counters.recommender.api.suggestions.rate
# Per-datacenter
<project>.<env>.aggregates.dc.<datacenter>.recommender.api.suggestions.rate (10) = sum <project>.<env>.<datacenter>.*.counters.recommender.api.suggestions.rate
@cosimo
cosimo / Shortener.py
Created March 30, 2015 13:35
Simple class used to generate "shortened" URLs
import math
class Shortener:
"""
Simple class to shorten URLs, or rather, numerical IDs.
Each URL must be saved to a database, with the data about source,
category, country, publisher, etc... The database will give back
a numerical ID. We're using that ID to convert it to a base 62
number and using a symbol table, converting it to a sequence
cosimo@ubuntu:~/src/web$ export PERL6LIB=/home/cosimo/src/perl6-sqlite/lib:/home/cosimo/src/web/lib
cosimo@ubuntu:~/src/web$ perl6 t/squerl/01-sqlite-write.t
invoke() not implemented in class 'Undef'
in sub SQLite3::sqlite_open (/home/cosimo/src/perl6-sqlite/lib/SQLite3.pm:50)
called from method Squerl::Database::open (/home/cosimo/src/web/lib/Squerl.pm:334)
called from method Squerl::Database::create_table (/home/cosimo/src/web/lib/Squerl.pm:360)
called from Main (t/squerl/01-sqlite-write.t:12)
@cosimo
cosimo / gist:803454
Created January 31, 2011 00:07
Opera contacts to Mutt aliases converter
#!/usr/bin/env perl
#
# Convert Opera contacts file (.adr) into
# mutt aliases file format.
#
# Usage:
# perl opera-adr-to-mutt-aliases.pl < ~/.opera/contacts.adr >> ~/.mutt/aliases
#
# Cosimo, 31/Jan/2011
#
/* Per Buer's code, "Re: Lots of configs"
* http://pastebin.com/a68y15hp
*/
#include <stdio.h>
#include <string.h>
#include <pcre.h>
int main() {
const char *error;
@cosimo
cosimo / gist:884307
Created March 24, 2011 00:05
Convert svn tags to git tags
#!/bin/bash
#
# Convert remote tags imported from SVN to real git tags
#
REMOTE_TAGS=$(git branch -r | grep 'tags/' | cut -f2 -d/)
GIT=$(which git)
for t in $REMOTE_TAGS
do
@cosimo
cosimo / gist:1171210
Created August 25, 2011 17:25
Strace of a IO::Socket.recv() from local memcached socket
connect(3, {sa_family=AF_INET, sin_port=htons(11211), sin_addr=inet_addr("127.0.0.1")}, 16) = 0
sendto(3, "get trololol\r\n", 14, 0, NULL, 0) = 14
# ite(1, "# Sent 'get trololol\r# \n# '. Wai"..., 50# Sent 'get trololol
# '. Waiting a response...) = 50
write(1, "\n", 1
) = 1
recvfrom(3, "END\r\n", 2048, 0, NULL, NULL) = 5
recvfrom(3, <stuck-here>