Skip to content

Instantly share code, notes, and snippets.

@felipou
felipou / setup_traffic_logging.sh
Last active February 17, 2025 18:57
setup_traffic_logging.sh
#!/bin/bash
###############################################################################
# WARNING: Review this script carefully before running!
#
# - This script was created and tested on **Ubuntu Server 24.04 (Noble)**.
# It should work on other systems using UFW, rsyslog, and AppArmor,
# but may require minor modifications.
#
# - **Purpose**: This script configures UFW to log all traffic for later analysis
@felipou
felipou / bench_zdiff.py
Last active December 2, 2020 23:49
Simple benchmark for zdiff/zunion/zinter
import random
import re
import string
import pickle
import redis
ZADD_BATCH_SIZE = 2000
r = redis.Redis(port=6380)
# Existing tests
test "BRPOPLPUSH with zero timeout should block indefinitely" {
set rd [redis_deferring_client]
r del blist target
r rpush target bar
$rd brpoplpush blist target 0
wait_for_condition 100 10 {
[s blocked_clients] == 1
@felipou
felipou / tobase64mime.py
Created February 29, 2020 15:02
Convert image from URL to base64 and also prints the mime type
# Requires python-magic, which requires the native libmagic lib
# I installed both on macOS with:
# - pip3 install python-magic
# - port install libmagic
#
# To run:
# python3 tobase64mime.py http://imagedomain.com/file.jpeg
import sys
@felipou
felipou / decrypt_dbeaver.py
Last active February 11, 2025 10:48
DBeaver password decryption script - for newer versions of DBeaver
# https://stackoverflow.com/questions/39928401/recover-db-password-stored-in-my-dbeaver-connection
# requires pycryptodome lib (pip install pycryptodome)
import sys
import base64
import os
import json
from Crypto.Cipher import AES
@felipou
felipou / decrypt_dbeaver.py
Last active October 7, 2024 17:09
DBeaver password decryption script
# https://stackoverflow.com/questions/39928401/recover-db-password-stored-in-my-dbeaver-connection
import sys
import base64
print(sys.argv[1])
PASSWORD_ENCRYPTION_KEY = b"sdf@!#$verf^wv%6Fwe%$$#FFGwfsdefwfe135s$^H)dg"
@felipou
felipou / datetime_format_string.cpp
Created April 10, 2018 15:15
C/C++ Datetime Format String Performance Tests
/*
Just compile with g++ datetime_format_string.cpp -std=c++11
Tested on GCC 5.4.0 on Ubuntu 16.04
*/
#include <iostream>
#include <chrono>
#include <sys/time.h>
#include <stdio.h>
@felipou
felipou / retry.sh
Last active March 26, 2024 16:41
Retry command
#!/bin/bash
#
# Created by Felipe Machado - 2016/02/14
#
# A retry command for bash
# Retries the given command up to MAX_RETRIES, with an interval of SLEEP_TIME
# between each retry. Just put it on your bash_profile and be happy :)
# Usage:
# retry [-s SLEEP_TIME] [-m MAX_RETRIES] COMMAND_WITH_ARGUMENTS
#
@felipou
felipou / gist:6423969
Created September 3, 2013 13:33
Jump utility auto-completion for Mac OS X
# jeroen janssens' jump utility
# http://jeroenjanssens.com/2013/08/16/quickly-navigate-your-filesystem-from-the-command-line.html
# tab completion for bash on Mac OS X
# I just modified the find command to pipe to the 'basename' command,
# because find on BSD doesn't support the 'printf' option
# I didn't test it on Linux, but it should probably work
_completemarks() {
@felipou
felipou / bloggergist.html
Created October 2, 2012 15:34
Gist on Blogger dynamic views
<!-- You should replace GistID with the id of the gist you want! -->
<div class="gistLoad" data-id="GistID" id="gist-GistID">Loading ....</div>
<!-- This script does the magic! -->
<script src="https://raw.github.com/moski/gist-Blogger/master/public/gistLoader.js" type="text/javascript"></script>