Skip to content

Instantly share code, notes, and snippets.

@numberoverzero
numberoverzero / 00. selinux.md
Last active June 17, 2022 16:31
hardened nginx conf, multiple subdomains under different certs using SNI

SELinux, oh god.

Context

You generated some certs, some dhparams, set up cloudflare origin certs, copied all the settings below, added some content to /var/www/ and set up your nginx.conf, and nginx -t says everything's fine.

Let's load some content! Nope, just kidding, nothing works.

@numberoverzero
numberoverzero / 00.bloop_multitable.py
Created November 10, 2021 23:31
Small class to map multiple Bloop models onto a shared table
# bloop 3.0.0
import copy
from typing import Union
from bloop import BaseModel, Column
from bloop.models import subclassof, instanceof
from bloop.types import Type
__all__ = ["Mapper"]
@numberoverzero
numberoverzero / run_forked.rs
Created November 6, 2021 07:44
execute a function in a detached process and exit
// fork = "0.1"
use fork::{self, Fork};
use std::process;
/// no error handling, no logging, just one shot to run in a forked process
fn run_forked<R>(f: fn() -> R) -> bool
{
match fork::fork() {
Ok(Fork::Parent(_)) => {
// we're in the parent process, must have forked successfully
@numberoverzero
numberoverzero / 00. costFactorForDuration.ts
Created March 15, 2021 09:18
compute an optimal bcrypt costfactor for a target hash time on the current machine
import assert from 'assert'
import bcrypt from 'bcrypt'
import crypto from 'crypto'
import { PerformanceObserver, performance } from 'perf_hooks'
const MINIMUM_BCRYPT_COST_FACTOR = 10
const RECOMMENDED_BCRYPT_COST_FACTOR = costFactorForDuration(250)
/**
* Calculate a cost factor based on a target duration (in milliseconds) for hashing.
@numberoverzero
numberoverzero / 00. 32bit key
Last active May 23, 2020 00:50
Monogame RenderQueue designs
MSB LSB
00 06 14 15 26 32
┣━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━╋━━━╋━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━┫
┃pass 64┃layer 256┃ 0 ┃effect 512┃texture 256┃ BATCHED MATERIAL
┣━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━╋━━━╋━━━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━┫
┃pass 64┃layer 256┃ 1 ┃data ~2 bytes┃ DYNAMIC MATERIAL
┣━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━╋━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
00 06 14 15 32
MSB LSB
@numberoverzero
numberoverzero / 00_hash_naming.cs
Created April 18, 2020 09:05
utility functions for filename nonces
byte[] Sha256(string s)
{
using (var hash = SHA256.Create())
{
return hash.ComputeHash(Encoding.UTF8.GetBytes(s));
}
}
byte[] Fold(byte[] input)
{
@numberoverzero
numberoverzero / 01 sample_api.py
Last active March 31, 2020 20:35
accordian api change
Namespace
.signal(name) -> Signal
Signal
.connect(async fn) -> async fn
.send(*a, **kw) -> Set[Task]
async .join(*a, **kw) -> List[Any]
_global = Namespace()
signal = _global.Signal
# fragments from evaluating some toolkit classes to build shared models as used
# in DAT401: Advanced Design Patterns for DynamoDB
# https://www.youtube.com/watch?v=HaEPXoXVf2k
import functools
from typing import Type
from bloop.conditions import Condition, iter_columns
from bloop.models import BaseModel, Column, IMeta, bind_column
# fragments from evaluating some toolkit classes to succinctly build common queries in bloop
class QueryBuilder:
def __init__(self, engine):
self.engine = engine
self.index_cache = {}
def by_key(self, key_condition, *, index=None, **kwargs):
if isinstance(key_condition, AndCondition):
model = key_condition.values[0].model
@numberoverzero
numberoverzero / compile_stockfish.sh
Created February 11, 2019 05:26
compile stockfish from github on RHEL into /opt/stockfish
#!/usr/bin/env bash
# assumes bmi2 arch: "x86 64-bit with pext support"
# compiled binary ends in /opt/stockfish/$MAJOR_VERSION/bin/stockfish
set -e
set -x
sudo yum update -y
sudo yum install -y git gcc gcc-c++