Skip to content

Instantly share code, notes, and snippets.

View romuloceccon's full-sized avatar

Rômulo Ceccon romuloceccon

  • Frankfurt am Main, Deutschland
View GitHub Profile
@romuloceccon
romuloceccon / check-redis.sh
Created August 2, 2020 07:27
How to connect both stdin and stdout of some process to netcat in Bash 3, or, how to emulate netcat traditional's -e switch
#! /bin/bash
if (( $# ))
then
echo "usage: mkfifo r.fifo ; nc -q 1 localhost 6379 < r.fifo | $0 > r.fifo" >&2
exit 2
fi
KEY="test-key"
VAL="val"
@romuloceccon
romuloceccon / README.md
Last active August 12, 2018 10:17
aptoffline-downloader

Usage

Given an apt-offline.sig file, launch an AWS EC2 instance to download the corresponding packages and upload the resulting bundle to the configured S3 bucket:

$ download-apt-packages apt-offline.sig
@romuloceccon
romuloceccon / tcptest-osx.c
Last active July 5, 2018 09:11
EventMachine/ECONNREFUSED bug on OSX
/*
This program demonstrates a bug with eventmachine on OSX. When /etc/hosts is
set like this:
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
the program will fail with a ECONNREFUSED (61) error when localhost is used
to resolve the local interface address. The program shows that in such
default-cache-ttl 36000
max-cache-ttl 86400
@romuloceccon
romuloceccon / profile.py
Last active April 12, 2018 11:08
Quick functions to easily profile Python code
import monotonic
from time import clock as cpu_time
import cProfile, pstats
try:
from StringIO import StringIO
except ImportError:
from io import StringIO
def time_it(label):
start_total = monotonic.monotonic()
function GOOGLEPCHANGE() {
var prices = arguments[0];
var result = [];
if (prices.length < 3) {
throw "Price array should have at least rows";
}
for (var i = 1; i < arguments.length; i++) {
result.push(findPriceChange_(prices, arguments[i]));
$ createdb mydb
$ sudo -u postgres psql mydb
# CREATE ROLE myrole WITH LOGIN PASSWORD 'mypwd';
# GRANT CONNECT ON DATABASE mydb TO myrole;
# GRANT USAGE ON SCHEMA public TO myrole;
# GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO myrole;
# GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO myrole;
@romuloceccon
romuloceccon / list-ibov-symbols
Created February 23, 2018 08:10
List all current IBOV symbols
#! /usr/bin/perl
use strict;
use warnings;
use LWP::UserAgent ();
use HTML::TreeBuilder::XPath;
my $url = "https://br.advfn.com/bolsa-de-valores/bovespa/";
my $ua = LWP::UserAgent->new;
@romuloceccon
romuloceccon / my-filters.txt
Last active January 10, 2023 16:43
uBlock origin filters
! folha.uol.com.br
||paywall.folha.uol.com.br^
^disablecopy.js|
! estadao.com.br
||acesso.estadao.com.br^
! abril.com.br
||cdn.tinypass.com^
! oglobo.globo.com
.glbimg.com/*/_js/paywall/*
||id.globo.com^
@romuloceccon
romuloceccon / parse_datetime.py
Last active December 22, 2017 12:48
A fast datetime parser written in Python with minimal validations.
import datetime
def parse_datetime(s):
"""Parse a datetime string with minimal validations.
`parse_datetime` takes a string with format yyyy-mm-dd HH:MM:SS.zzzzzz
and returns a `datetime.datetime` object. Any prefix of that format is
accepted as well; so a string like "2017-12-22" will return a datetime
with hour, mins, secs and microsecs set to zero.