Skip to content

Instantly share code, notes, and snippets.

View 46bit's full-sized avatar
🏳️‍🌈

Miki Mokrysz 46bit

🏳️‍🌈
View GitHub Profile
@46bit
46bit / deriving-mersenne-twister-state-from-outputs.txt
Last active October 14, 2023 10:59
Deriving how to reverse the output of a Mersenne Twister PRNG into the internal state, as used in https://github.com/46bit/pinocchio.
func (m *MersenneTwister) Urand32() uint32 {
if m.index == 0 {
m.generate_numbers()
}
y := m.State[m.index]
y = y ^ (y >> 11) //
y = y ^ ((y << 7) & 2636928640) //
y = y ^ ((y << 15) & 4022730752) //
y = y ^ (y >> 18) // "y XOR leftmost 14 bits of y"
import sys, cv2
# Refactored https://realpython.com/blog/python/face-recognition-with-python/
def cascade_detect(cascade, image):
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
return cascade.detectMultiScale(
gray_image,
scaleFactor = 1.15,
minNeighbors = 5,
@46bit
46bit / arch-digitalocean.md
Created February 16, 2015 03:50
Arch Linux on DigitalOcean

Arch Linux on DigitalOcean

DigitalOcean are a promising host: good machines, lovely interface, lots of free credit floating about. However they don't support custom disk images, which leaves a lot of distros unusable.

You can use this script to replace a fresh Debian 7.0 droplet with an Arch system (including the Arch Kernel). While there's no reason to think this script does anything naughty, it isn't easy to be sure. DigitalOcean might make a change that renders it unbootable, so backups would be advisable.

  1. Create a new Debian 7.0 droplet (either 32-bit or 64-bit works).
  2. In the droplet (either SSH or console access works), run the following as root:
@46bit
46bit / snake.ino
Created March 30, 2022 20:52
Arduino program to render a basic Snake effect on an Adafruit Matrix Portal attached to a 32x64 LED matrix
#include <Adafruit_SleepyDog.h>
#include <Adafruit_Protomatter.h>
#define HEIGHT 32
#define WIDTH 64
#define LED_COUNT (HEIGHT*WIDTH)
uint8_t rgbPins[] = {7, 8, 9, 10, 11, 12};
uint8_t addrPins[] = {17, 18, 19, 20};
uint8_t clockPin = 14;
export PASSWORD="$1"
export CURL_FLAGS=( -H 'Cookie: popup=1; key=value' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36' -L )
function md5_then_sha512() {
echo -n "$1" | md5sum | tr -d '[:space:]-' | shasum --algorithm 512 - | sed 's/[^a-z0-9]//g' | tr -d '[:space:]'
}
function extract_tn() {
echo -n "$1" | pup 'img[src^="data:"] attr{src}' | cut -c 79- | base64 -d
@46bit
46bit / oh-wow-mixins.ts
Created January 21, 2020 09:24
TypeScript's built-in mixins don't allow the mixin to have a useful constructor. I came across https://github.com/Microsoft/TypeScript/issues/14126#issuecomment-503940323 and wanted to check that it really works. It does!
type ComposableConstructor<T, U> =
[T, U] extends [new (a: infer O1) => infer R1,new (a: infer O2) => infer R2] ? {
new (o: O1 & O2): R1 & R2
} & Pick<T, keyof T> & Pick<U, keyof U> : never
function MixA<T extends new (o: any) => any>(Base: T) {
class MixA extends (Base as new (...a: any[]) => {}) {
a_value: number;
constructor(options: { a_value: number }) {
super(options)
apiVersion: v1
kind: ServiceAccount
metadata:
name: grafana-agent
namespace: ${NAMESPACE}
---
kind: ConfigMap
metadata:
name: grafana-agent
namespace: ${NAMESPACE}
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
use std::mem;
use rand::prelude::*;
#[derive(Copy, Clone, Debug, Default)]
pub struct Vector {
pub x: f32,
pub y: f32,
}
impl Vector {
import { Vector } from '../../vector';
export interface IEntity2 {
id: string;
player?: Player;
positioning: IPositioning;
lifecycle?: ILifecycle;
behaviour?: IBehaviour;
engineering?: IEngineering;
sidecars?: {[name: string]: IEntity2};