Skip to content

Instantly share code, notes, and snippets.

@luxedo
luxedo / termo.py
Created January 21, 2022 13:55
Assistente pra achar as palavras no https://term.ooo/
#!/usr/bin/env python
"""
Cansei de apanhar no termo https://term.ooo/.
➜ python termo.py -x e r t i p a l c n -f 2u 5o -c s
musgo
"""
from string import ascii_lowercase, digits
import argparse
filename imagemagick quality size(KB) picamera quality
pic_001.jpg 1 60 1
pic_002.jpg 4 60 2
pic_003.jpg 92 60 3
pic_004.jpg 92 64 4
pic_005.jpg 25 68 5
pic_006.jpg 92 80 6
pic_007.jpg 49 104 7
pic_008.jpg 61 132 8
pic_009.jpg 70 160 9
@luxedo
luxedo / image_quality.sh
Created February 21, 2020 16:58
Creates a table with the jpeg quality and size for every file in the current directory
echo 'file_name\tquality\tsize (KB)' && for i in $(ls); do echo $i'\t'$(identify -format "%Q" "$i")'\t'$(ls -ls "$i" | cut -d " " -f1); done
# file_name quality size (KB)
# q_001_0001.jpg 1 152
# q_010_0001.jpg 75 852
# q_020_0001.jpg 94 2000
# q_030_0001.jpg 98 3144
# q_040_0001.jpg 99 3700
# q_050_0001.jpg 99 4260
# q_060_0001.jpg 100 4940
@luxedo
luxedo / int2bin.py
Created October 30, 2019 16:28
Function to convert integer to binary with a fixed length
import sys
import math
MAXIMUM_SIZE = math.ceil(math.log(sys.maxsize, 2))
def int2bin(integer, length=MAXIMUM_SIZE):
"""
Returns the `integer` as an unsigned binary string with a fixed `length` in bits.
Truncates to the `length` in bits to prevent overflow.
@luxedo
luxedo / titanic_kaggle.csv
Last active October 22, 2019 02:13
Titanic Kaggle passenger list. Use this to cheat and score 1.00. CHEATER!
Survived Name Age Class Fare Embarked Boat Body
1 Allen, Miss. Elisabeth Walton 29.0 1 211.3375 Southampton 2
1 Allison, Master. Hudson Trevor 0.92 1 151.55 Southampton 11
0 Allison, Miss. Helen Loraine 2.0 1 151.55 Southampton
0 Allison, Mr. Hudson Joshua Creighton 30.0 1 151.55 Southampton 135.0
0 Allison, Mrs. Hudson J C (Bessie Waldo Daniels) 25.0 1 151.55 Southampton
1 Anderson, Mr. Harry 48.0 1 26.55 Southampton 3
1 Andrews, Miss. Kornelia Theodosia 63.0 1 77.9583 Southampton 10
0 Andrews, Mr. Thomas Jr 39.0 1 0.0 Southampton
1 Appleton, Mrs. Edward Dale (Charlotte Lamson) 53.0 1 51.4792 Southampton D
@luxedo
luxedo / mean_pixel.py
Created August 21, 2019 13:13
Mean pixel of images
#!/usr/bin/env python3
"""Start with a bang!"""
import argparse
from os import path
import cv2
import numpy as np
def main(args):
@luxedo
luxedo / maxres.sh
Created May 15, 2019 17:08
Outputs the maximum resolution of `/dev/video0`
v4l2-ctl -d /dev/video0 --list-formats-ext | grep Size | sed 's/.*[^0-9]\([0-9]\+x[0-9]\+\)[^0-9]\?.*/\1/' | sort | uniq |python3 -c "import fileinput;res = [line.split('x') for line in fileinput.input()];res = [(int(r[0]), int(r[1]), int(r[0])*int(r[1])) for r in res];res=sorted(res, key=lambda x: -x[2]);print(res[0][0:2])"
@luxedo
luxedo / coco.names
Last active October 27, 2023 13:19
Tradução para o português das classes COCO para o modelo YOLO
pessoa
bicicleta
carro
motocicleta
avião
ônibus
trem
caminhão
barco
semáforo
@luxedo
luxedo / edit-last-layer.py
Created April 16, 2019 17:16
Script to truncate the output layer of .npz models for tensorpack
#!/usr/bin/env python3
import sys
import numpy as np
def main(input, output, categories):
with np.load(input) as npz:
data = dict(npz)
print("Chopping last layer")
data['maskrcnn/conv/W:0'] = data['maskrcnn/conv/W:0'][:,:,:,:categories]
@luxedo
luxedo / dvc.log
Last active April 15, 2019 19:08
$ dvc push -v > dvc.log 2>&1
DEBUG: PRAGMA user_version;
DEBUG: fetched: [(3,)]
DEBUG: CREATE TABLE IF NOT EXISTS state (inode INTEGER PRIMARY KEY, mtime TEXT NOT NULL, size TEXT NOT NULL, md5 TEXT NOT NULL, timestamp TEXT NOT NULL)
DEBUG: CREATE TABLE IF NOT EXISTS state_info (count INTEGER)
DEBUG: CREATE TABLE IF NOT EXISTS link_state (path TEXT PRIMARY KEY, inode INTEGER NOT NULL, mtime TEXT NOT NULL)
DEBUG: INSERT OR IGNORE INTO state_info (count) SELECT 0 WHERE NOT EXISTS (SELECT * FROM state_info)
DEBUG: PRAGMA user_version = 3;
DEBUG: Path /home/john/imagem-mariposas/.dvc/cache/3e/4a6b6668be13477f2b5c285ac9fbb5.dir inode 2097211
DEBUG: SELECT mtime, size, md5, timestamp from state WHERE inode=2097211