Skip to content

Instantly share code, notes, and snippets.

@ebraminio
ebraminio / challenge_2.sql
Last active April 7, 2023 22:03 — forked from kartikynwa/challenge_2.sql
Challenge 2 of https://yrashk.com/blog/2023/04/04/make-postgres-an-application-server-gamified/ based on kartikynwa version but without plpgsql
create table if not exists users
(
id int primary key generated always as identity,
name text not null
);
create table if not exists apikeys
(
userid int references users(id),
apikey text not null
@ebraminio
ebraminio / README.md
Last active June 13, 2022 20:34
Modded SSD1305 for mt32-pi

Getting the Waveshare 1.3inch OLED hat to work

These hats offer a nice control interface and display that is sized to a Pi Zero. Unfortunately, they require some hardware modification to work on the MT32-pi lite.

First, you need to move the 5 resistors to the i2c state as it is shown in the table printed on the back of the HAT (DIN, CLK, DC, CS and BS1 resistors need to be repositions). In addition, you need to tie the reset pin to high (VCC) which was the reason for why the display was not working on the I2C mode. Also, adding a pair of 4.7k pull up resistors will assure the functionality of the display flawlessly. Now, in order to get the buttons work, you cannot simply remap them in software and get them work, rather you have to cut the traces and rewire them other compatible pins. This is due to the fact that the existing pins used on the hat for buttons are used for I2S communication between the mt32-pi and the MiSTer. Here is a picture of a modified hat to get it work.

[Waveshare 1.3 OLED Hat on

@ebraminio
ebraminio / time-calculator.html
Last active February 8, 2022 12:35
dead simple calculator for time
<textarea id=input style="width: 50%; height: 5em; white-space: pre" oninput="result.innerText = calculate(this.value)"></textarea>
<div id=result></div>
<script>
window.onload = () => {
input.value = '1d 2h 3m 4s + 4h 5s - 2030s + 28h';
input.dispatchEvent(new Event('input'))
};
function calculate(input) {
const units = Object.entries({ d: 86400, h: 3600, m: 60, s: 1 });
const seconds = eval(
@ebraminio
ebraminio / a.mjs
Created October 10, 2021 19:20
Split each page of a PDF document in two using Ghostscript and pdftk
#!/usr/bin/env zx
await $`gs -q -dNOPAUSE -dBATCH -o ${'out_' + argv.input} -sDEVICE=pdfwrite ${
(await $`pdftk ${argv.input} dump_data`).stdout
.split('\n')
.filter(line => line.startsWith('PageMediaDimensions: '))
.map(line => line.split(' ').slice(1).map(x => +x.replace(/,/g, '')))
.reduce((acc, page, i) => {
const w = Math.floor(page[0] / 2);
const h = Math.floor(page[1]);
@ebraminio
ebraminio / persian-calendar.ipynb
Last active May 28, 2021 13:20
Persian Calendar related calculations, install https://github.com/Kotlin/kotlin-jupyter first
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ebraminio
ebraminio / demo.go
Last active May 18, 2021 21:16
make sure `pkg-config pangocairo --cflags --libs` prints something, otherwise some -dev packages should be installed given your distribution
package main
// #cgo pkg-config: pangocairo
// #include <pango/pangocairo.h>
// void draw(const char *font, const char *text, const char *output) {
// int width, height;
// PangoFontDescription *font_description = pango_font_description_from_string(font);
// {
// cairo_surface_t *cairo_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 0, 0);
// cairo_t *cr = cairo_create(cairo_surface);
@ebraminio
ebraminio / .SRCINFO
Last active May 14, 2021 13:21
[WIP] Download and install llvm nightly in Arch Linux
pkgbase = llvm-toolchain-nightly-bin
pkgdesc = NOT READY YET. Precompiled binaries of llvm-toolchain (clang+lld+lldb+...) nightly builds. Status: Can't fetch llvm version.
pkgver = 12
pkgrel = 1
url = https://llvm.org/
arch = x86_64
license = custom:Apache 2.0 with LLVM Exception
makedepends = patchelf
makedepends = wget
depends = libedit
@ebraminio
ebraminio / mingw-w64-x86_64.cmake
Last active April 15, 2024 15:04 — forked from peterspackman/mingw-w64-x86_64.cmake
cmake toolchain file for mingw-w64 x86_64 builds on Ubuntu
# Sample toolchain file for building for Windows from an Ubuntu Linux system.
#
# Typical usage:
# *) install cross compiler: `sudo apt-get install mingw-w64` or `brew install mingw-w64` on macOS
# *) cmake -DCMAKE_TOOLCHAIN_FILE=~/mingw-w64-x86_64.cmake -G Ninja -B build -S .
# *) ninja -C build
set(CMAKE_SYSTEM_NAME Windows)
set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)
@ebraminio
ebraminio / files.py
Last active July 17, 2020 15:51
files
from collections import deque
import bs4
import requests
def extract_files(site_name):
dirs = deque('/')
result = []
while len(dirs):
path = dirs.pop()
page = bs4.BeautifulSoup(requests.get(site_name + path).text, 'html.parser')
for link in page.find_all('a'):
@ebraminio
ebraminio / nesemu1.cc
Last active May 13, 2020 20:11
nesemu1
// modified version of nesemu1.cc, STL is removed
// clang -fno-threadsafe-statics -lm -fno-exceptions nesemu1.cc `pkg-config sdl --libs --cflags` -Wall -W -pedantic -Ofast -std=c++0x -g -Og && ./a.out Rockman.nes
#include <stdint.h>
#include <signal.h>
#include <assert.h>
#include <math.h>
#include <SDL.h>
/* NESEMU1 : EMULATOR FOR THE NINTENDO ENTERTAINMENT SYSTEM (R) ARCHITECTURE */