Skip to content

Instantly share code, notes, and snippets.

View badjano's full-sized avatar
💭
unity + python + c++

Badjano badjano

💭
unity + python + c++
View GitHub Profile
@badjano
badjano / threaded_pixel.cs
Last active March 13, 2023 12:32
Multi-Threaded pixel painting on the CPU in Unity
using System;
using System.Linq;
using System.Threading;
using UnityEngine;
using Random = System.Random;
public class PixelThreading : MonoBehaviour
{
[SerializeField] private Material material;
[SerializeField] private int width = 512;
@badjano
badjano / t5test.py
Last active May 19, 2022 03:51
a T5 model test in portuguese
import os
import random
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
from transformers import T5Tokenizer, TFT5ForConditionalGeneration
model_sizes = ["small", "base", "large"]
model_name = f'unicamp-dl/ptt5-{model_sizes[1]}-portuguese-vocab'
tokenizer = T5Tokenizer.from_pretrained(model_name)
@badjano
badjano / rateio.py
Created December 30, 2021 22:23
Script de rateio de gastos em python
names = ["Fulano", "Sicrano", "Beltrano"]
costs = [397.03, 199.42, 0]
individual_cost = sum(costs) / len(costs)
costs_str = "\n".join([f"{a} gastou R${b}" for a, b in zip(names, costs)])
print(f"Sabendo que:\n{costs_str}\n")
print(f"E que o custo total foi R${sum(costs):.02f}\ne o individual foi R${individual_cost:.02f}\n")
for n, c in zip(names, costs):
specific_cost = individual_cost - c
word = "receber" if specific_cost < 0 else "pagar"
print(f"{n} deve {word}: R${abs(specific_cost):.02f}")
@badjano
badjano / movie_converter.py
Last active December 6, 2021 03:02
Converts all video from a folder to much smaller ones in another folder
import os
from glob import glob
from moviepy.editor import *
from tkinter import Tk
from tkinter.filedialog import askdirectory
from include.colors import Colors
def get_filename(file_path):
return file_path.split(os.sep)[-1]
@badjano
badjano / wacom_preserve_ratio.sh
Created November 23, 2021 00:00
Make wacom tablet preserve aspect ratio
SIZE=`xdpyinfo | grep dimensions | sed -r 's/^[^0-9]*([0-9]+x[0-9]+).*$/\1/'`
WIDTH=${SIZE%x*}
HEIGHT=${SIZE#*x}
echo "SIZE: $SIZE"
echo "WIDTH: $WIDTH"
echo "HEIGHT: $HEIGHT"
echo
WACOM_SIZE=`xsetwacom get 11 Area`
import numpy as np
import cv2
from PIL import ImageGrab
from screeninfo import get_monitors
monitors = []
for m in get_monitors():
monitors.append((m.x, m.y, m.x + m.width, m.y + m.height))
bbox = monitors[0]
import datetime
class Range:
def __init__(self, start, end):
self.start = min(start, end)
self.end = max(start, end)
self.empty = self.start == self.end
self.log = False
import numpy as np
from PIL import Image
arr = np.random.rand(256, 256, 4) * 255
img = Image.fromarray(arr.astype('uint8'), mode="RGBA")
img.save("random_img.png")
img.show()
@badjano
badjano / fbcp_square_screen.sh
Created March 2, 2021 01:48
I shell script for installing fbcp-ili9341 with square screen cropping
sudo apt-get install cmake
cd ~
#git clone https://github.com/juj/fbcp-ili9341.git # original repo
git clone https://github.com/badjano/fbcp-ili9341 # my modified repo for square screen cropping
cd fbcp-ili9341
mkdir build
cd build
cmake --clean-first -DSPI_BUS_CLOCK_DIVISOR=20 -DWAVESHARE_ST7735S_HAT=ON -DDMA_TX_CHANNEL=7 -DDMA_RX_CHANNEL=1 -DBACKLIGHT_CONTROL=OFF -DDISPLAY_BREAK_ASPECT_RATIO_WHEN_SCALING=ON -DSTATISTICS=0 ..
make -j
sudo install ./fbcp-ili9341 /usr/local/bin/fbcp
@badjano
badjano / mouse.py
Created February 28, 2021 17:36
Mouse and keyboard control for raspberry pi LCD HAT ST7735S
from pymouse import PyMouse
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
btn_up = 5
btn_down = 26
btn_left = 19
btn_right = 6