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 / b32backup.py
Last active September 24, 2016 20:16
A tool to convert small binary files to text suitable to be printed on paper. It uses Base32 encoding so that the result is easily parseable with OCR software and every line includes a CRC16 for error verification. Efficiency is about 3000 bytes per page using a 10-pt font!
#! /usr/bin/env python
# Examples:
#
## encoding
#
# $ head -c 135 /dev/urandom | b32backup.py
# ZLBD4SI6YCWDF63FYMQ4X7ZOORL5UYBOXZ4Y2WU54OKEQ4N5LBAFA7YHMYTC3W33KHCENWPK 13CB
# TUK5QT55AXF5PZL6Q6A5RJ7CJ24YZML3WMRQWAI6TCO5XGMOHJWAATO7TUCEM7BCL6FGTC6G 03AF
# 6SZVCA4CTBGIHZXC5DEGMCIOLRJPKGVIQCTWAQZAX4VMNLPULEJLWJMV6AAPIOPUYCVKEEIT 228A
@romuloceccon
romuloceccon / byobu.desktop
Last active December 26, 2019 04:48
Gnome desktop launcher for starting Byobu with two vertical panes
[Desktop Entry]
Name=Byobu Terminal
Comment=Advanced Command Line and Text Window Manager
Icon=byobu
Exec=env BYOBU_WINDOWS=split2 gnome-terminal --app-id us.kirkland.terminals.byobu --window-with-profile=Byobu -e byobu
Type=Application
Categories=GNOME;GTK;Utility;
X-GNOME-Gettext-Domain=byobu
@romuloceccon
romuloceccon / Makefile
Last active November 18, 2016 09:32
Import a Ruby on Rails™ MySQL database dump (gzip compressed SQL) for use in a development environment using SQLite3
CFLAGS += -Wall
mysql2sqlite: mysql2sqlite.c
$(CC) $(CFLAGS) -o $@ $^
@romuloceccon
romuloceccon / google-finance-fetch
Last active November 6, 2016 15:31
Fetch financial statements from Google Finance
#! /usr/bin/env ruby
require 'bigdecimal'
require 'csv'
require 'net/http'
require 'nokogiri'
class CompanyStats
attr_reader :name
@romuloceccon
romuloceccon / open-printscreen
Created December 2, 2016 15:54
Opens Byobu's printscreen file in a text editor from the command line
#!/bin/bash
[[ -z "$BYOBU_RUN_DIR" ]] && \
echo "Not a Byobu session!" 1>&2 && exit 1
[[ ! -e $BYOBU_RUN_DIR/printscreen ]] && \
echo "No printscreen found! (try pressing Shift+F7)" 1>&2 && exit 1
geany $BYOBU_RUN_DIR/printscreen
require 'net/http'
require 'nokogiri'
$uri = URI('http://bvmf.bmfbovespa.com.br/cias-listadas/empresas-listadas/BuscaEmpresaListada.aspx?idioma=pt-br')
def fetch_html(post_data)
req = Net::HTTP::Post.new($uri)
req.body = post_data
res = Net::HTTP.start($uri.hostname, $uri.port) { |http| http.request(req) }
@romuloceccon
romuloceccon / assign-race-condition.rb
Last active December 19, 2020 16:24
Demonstrates how Ruby's idiom "my_var ||= MyObject.new" is NOT thread safe, as part of discussion at https://github.com/svenfuchs/i18n/pull/352#pullrequestreview-24816351. The script returns when a race condition is detected.
class MyObject
def initialize
@data = 'x' * 1_000_000
end
def inspect
object_id
end
end
@romuloceccon
romuloceccon / atom-custom-path.patch
Created March 14, 2017 11:37
Patch to install Atom in custom location
diff --git a/script/lib/install-application.js b/script/lib/install-application.js
index be790b4..477265b 100644
--- a/script/lib/install-application.js
+++ b/script/lib/install-application.js
@@ -39,7 +39,7 @@ module.exports = function (packagedAppPath) {
const apmExecutableName = CONFIG.channel === 'beta' ? 'apm-beta' : 'apm'
const appName = CONFIG.channel === 'beta' ? 'Atom Beta' : 'Atom'
const appDescription = CONFIG.appMetadata.description
- const userLocalDirPath = path.join('/usr', 'local')
+ const userLocalDirPath = '/home/romulo/opt/atom'
@romuloceccon
romuloceccon / printable-code-points.py
Created March 15, 2017 13:01
182 printable unicode code points to be used in a base-32768 encoder
def is_printable(x):
return \
x >= 0x25 and x <= 0x2a or \
x >= 0x2c and x <= 0x3c or \
x >= 0x3e and x <= 0x7e or \
x >= 0xa1 and x <= 0xac or \
x >= 0xae and x <= 0xff
s = [chr(x) for x in range(256) if is_printable(x)]
@romuloceccon
romuloceccon / divmod.c
Last active March 17, 2017 13:28
How to calculate modulo division (like Python's divmod) in C without conditionals (also works in Java)
#include <stdio.h>
int main()
{
int i;
static const int dm = 4;
for (i = -2 * dm; i < 2 * dm; i++) {
int rem = i % dm;
int mod = (rem + dm) % dm;