Skip to content

Instantly share code, notes, and snippets.

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)]
@aib
aib / gist:ce5bb91ee6e006bcaaa4f438879bfd7b
Created January 24, 2020 09:50
Python standard library breakdown
import collections
import importlib
import inspect
import sys
MODULES = """\
string
re
difflib
textwrap
@aib
aib / tuntap.py
Created February 4, 2019 05:58
TUN/TAP packet decoder prototype
import struct
import bitstream
import dotdict
import numpy as np
import pytun
def read_uint(stream, n=None):
integer = 0
for _ in range(n):
@aib
aib / tuntap_tun.py
Created February 4, 2019 00:25
tun packet decoder
import struct
import bitstream
import dotdict
import numpy as np
import pytun
def read_uint(stream, n=None):
integer = 0
for _ in range(n):