Skip to content

Instantly share code, notes, and snippets.

@aib
aib / orientation_helper.svg
Created October 21, 2024 12:22
Test image for when working with 2D transformations
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@aib
aib / PID.js
Created August 19, 2024 16:56
JS PID Controller
class PIDController
{
constructor(Kp, Ki, Kd) {
this.Kp = Kp;
this.Ki = Ki;
this.Kd = Kd;
this.deltaError = 0;
this.sumError = 0;
this.lastError = 0;
#!/bin/bash
CA=/etc/openvpn/keys/ca.crt
CERT=/etc/easy-rsa/keys/$1.crt
KEY=/etc/easy-rsa/keys/$1.key
TLS_AUTH=/etc/openvpn/keys/ta.key
cat client.ovpn \
| sed -e '/<ca><\/ca>/{' -e 'i <ca>' -e "r $CA" -e 'a </ca>' -e 'd' -e '}' \
| sed -e '/<key><\/key>/{' -e 'i <key>' -e "r $KEY" -e 'a </key>' -e 'd' -e '}' \
use std::sync::Arc;
type Log = Box<dyn Fn(&str)>;
struct OpenLibrary {
pub log: Log,
}
struct OpenDevice {
library: Arc<OpenLibrary>,
@aib
aib / selenium_persistent_driver.py
Created September 21, 2022 18:56
Persistent profile in selenium
import selenium
import selenium.webdriver
options = selenium.webdriver.chrome.options.Options()
options.binary_location = '/home/aib/tmp/chrome-linux/chrome'
options.add_argument('--user-data-dir=/tmp/selenium_data_dir')
options.add_argument('--profile-directory=SeleniumProfile')
service = selenium.webdriver.chrome.service.Service(executable_path='/home/aib/tmp/chromedriver_linux64/chromedriver')
@aib
aib / hexdump.js
Created July 22, 2022 13:15
JavaScript hexdump
function hexdump(buffer, bytesPerRow) {
bytesPerRow = bytesPerRow || 16;
const hexDigits = "01234567890abcdef";
var str = "";
for (var addr = 0; addr < buffer.length; addr += bytesPerRow) {
var rowStr = ("0000" + addr.toString(16)).slice(-4) + ":";
for (var i = addr; i < addr + bytesPerRow; i++) {
if (i < buffer.length) {
rowStr += " " + hexDigits[(0xf0 & buffer[i]) >> 4] + hexDigits[0x0f & buffer[i]];
@aib
aib / gist:96753c296a047c818a10369457e90e1b
Created January 27, 2022 10:59
TWAIN 2.5 Operation Triplets
TWAIN 2.5 Operation Triplets (§7)
A -> SM
DG_CONTROL DAT_IDENTITY MSG_CLOSEDS 7-58 duplicated (SM -> S)
DG_CONTROL DAT_IDENTITY MSG_GETDEFAULT 7-61
DG_CONTROL DAT_IDENTITY MSG_GETFIRST 7-62
DG_CONTROL DAT_IDENTITY MSG_GETNEXT 7-64
DG_CONTROL DAT_IDENTITY MSG_OPENDS 7-66 duplicated (SM -> S)
DG_CONTROL DAT_IDENTITY MSG_SET 7-69
DG_CONTROL DAT_IDENTITY MSG_USERSELECT 7-70
DG_CONTROL DAT_PARENT MSG_CLOSEDSM 7-78
@aib
aib / main.rs
Created February 13, 2021 14:18
Bad trait suggestion of rustc 1.47.0
#[derive(Debug)]
#[derive(Copy, Clone)]
pub struct Vec3<T> {
pub x: T,
pub y: T,
pub z: T
}
impl<T> Vec3<T> {
pub fn new(x:T, y:T, z:T) -> Vec3<T> {
@aib
aib / pretty_log_formatter.py
Created January 29, 2021 16:01
Colored log formatter for Python's logging
import logging
LEVELS = {
logging.CRITICAL: { 'label': "CRIT ", 'style-pre': "\033[95m", 'style-post': "\033[0m" },
logging.ERROR: { 'label': "ERROR", 'style-pre': "\033[91m", 'style-post': "\033[0m" },
logging.WARNING: { 'label': "WARN ", 'style-pre': "\033[93m", 'style-post': "\033[0m" },
logging.INFO: { 'label': "INFO ", 'style-pre': "\033[97m", 'style-post': "\033[0m" },
logging.DEBUG: { 'label': "DEBUG", 'style-pre': "\033[37m", 'style-post': "\033[0m" },
logging.NOTSET: { 'label': " ", 'style-pre': "\033[90m", 'style-post': "\033[0m" },
}
@aib
aib / digitproblems.py
Created March 1, 2020 18:52
Should help with a certain type of mathematical puzzles
import functools
import itertools
import operator
def groupings(sum_):
if sum_ == 0:
return [()]
else:
return [(i,) + subg for i in range(1, sum_ + 1) for subg in groupings(sum_ - i)]