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
@aethercowboy
aethercowboy / ExampleGame.cs
Last active February 23, 2024 06:34
Monogame with IHostedService DI
public class ExampleGame : Game, IGame
{
public Game Game => this;
private readonly ISomeDependency _someDependency;
public ExampleGame(ISomeDependency someDependency)
{
_someDependency = someDependency;
}
# 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
@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++
@numberoverzero
numberoverzero / 00_base.py
Last active July 26, 2019 17:23
support integral base string representations, especially for lexicographical sorting
def in_base(n: int, alphabet: str) -> str:
b = len(alphabet)
s = []
while n > 0:
d = n % b
s.append(alphabet[d])
n //= b
return "".join(reversed(s))
@numberoverzero
numberoverzero / pep487.py
Last active March 24, 2017 13:27
PEP 487 is insane, holy fuck this is awesome
from typing import Any, Dict, List, NamedTuple, Optional, Tuple, TypeVar, Generic, Type
T = TypeVar("T")
class Field(Generic[T]):
key: str
t: Type[T]
readonly: bool
def __init__(self, t: Type[T], readonly: bool=True) -> None:
@Chlumsky
Chlumsky / msdf-preview.shadron
Last active August 27, 2021 07:41
MSDF Preview
#include <math_constants>
#include <median>
#include <billboard>
#include <affine_transform>
glsl float linearStep(float a, float b, float x) {
return clamp((x-a)/(b-a), 0.0, 1.0);
}
@othyn
othyn / factorio_headless_guide.md
Last active April 15, 2024 08:27
How to setup a Factorio Headless Server

[LINUX] Factorio Headless Server Guide

So, with credit to the Factorio wiki and cbednarski's helpful gist, I managed to eventually setup a Factorio headless server. Although, I thought the process could be nailed down/simplified to be a bit more 'tutorialised' and also to document how I got it all working for my future records.

The specific distro/version I'm using for this guide being Ubuntu Server 16.04.1 LTS. Although, that shouldn't matter, as long as your distro supports systemd (just for this guide, not a Factorio headless requirement, although most distros use it as standard now). The version of Factorio I shall be using is 0.14.20, although should work for any version of Factorio 0.14.12 and higher.

Just a note to newcomers: If there are any issues with the installation steps, people in the comments are doing a good job