Skip to content

Instantly share code, notes, and snippets.

@ebraminio
ebraminio / gist:5292017
Last active April 21, 2024 08:57
Check Iranian National Code Validity - بررسی صحت کد ملی ایرانی - Clojure, C#, F#, Ruby, JavaScript, Dart, Python, Scala, Java 8, PHP, C, Go, Swift, Kotlin, Groovy, Rust, Haskell, Erlang, Elixir, PowerQuery M Language, VBA, R, Lua, Fortran, Pascal/Delphi, Excel, Stored Procedure / MySQL
// Check Iranian National Code Validity - Clojure, C#, F#, Ruby, JavaScript, Dart, Python, Scala, Java 8, PHP, C, Go, Swift, Kotlin, Groovy, Rust, Haskell, Erlang, Elixir, Power Query M Language, VBA, R, Lua, Fortran, Pascal/Delphi, Excel, Stored Procedure / MySQL
// بررسی صحت کد ملی ایران - کلوژر، سی‌شارپ، اف‌شارپ، روبی، جاوااسکریپت، دارت، پایتون، اسکالا، جاوا ۸، پی‌اچ‌پی، سی، گو، سوئیفت، کاتلین، گرووی، راست، هسکل، ارلنگ، الکسیر، پاورکوئری ام، وی‌بی ای، آر، لوآ، فرترن، پاسکال/دلفی، اکسل، مای‌اس‌کیوال
// در نسخه‌های قبل یکسان بودن اعداد نا معتبر تشخیص داده می‌شد ولی
// اعداد یکسان نامعتبر نیست https://web.archive.org/web/20170706081048/http://www.fardanews.com/fa/news/127747/رندترین-شماره-ملی-بلای-جان-صاحبش-شد
// بعضی از پیاده‌سازی‌ها سریع نیستند، می‌توانید نسخهٔ خود را بر پایهٔ
// نسخهٔ سی یا گو ایجاد کنید که بهترین سرعت را داشته باشد
/**
@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 / code.py
Created December 16, 2018 17:04
fontfolio fonts tables
import os, hashlib, re
files = !ls **/*.{ttf,otf}
for f in files:
# this is jupyter notebook...
msg = !/home/ebrahim/Desktop/harfbuzz/build/src/main "{f}"
print(f, hashlib.sha1(open(f, 'rb').read()).hexdigest(), re.findall(r': (....) \(', str(msg)))
@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 / upload.go
Last active March 22, 2023 06:01
golang upload client and server
// curl -X POST -H "Content-Type: application/octet-stream" --data-binary '@filename' http://127.0.0.1:5050/upload
package main
import (
"fmt"
"io"
"net/http"
"os"
"time"
@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(
// `clang a.c && time ./a.out`
// real 0m0.071s
// user 0m0.067s
// sys 0m0.002s
// `clang -O3 a.c && time ./a.out`
// real 0m0.029s
// user 0m0.025s
// sys 0m0.001s
// `gcc-6 a.c && time ./a.out`
// real 0m0.093s
@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 / code.py
Last active June 7, 2021 19:56
fontlibrary.org fonts tables
#!/bin/python3
# needs `pip install cssselect fonttools`
import lxml.etree, lxml.cssselect, requests, re, fontTools.ttLib, gc
from io import StringIO, BytesIO
pages = [requests.get('https://fontlibrary.org/en/search?query=.&page=%d' % p) for p in range(1, 54)]
links_selector = lxml.cssselect.CSSSelector('.family-name a')
parser = lxml.etree.HTMLParser()