Skip to content

Instantly share code, notes, and snippets.

View orlp's full-sized avatar
⚠️
This user's social credit score is unknown.

Orson Peters orlp

⚠️
This user's social credit score is unknown.
  • Leiden, Netherlands
View GitHub Profile
@orlp
orlp / minimal-random.cpp
Last active April 19, 2016 09:59
Minimal fast random number generation, for simulation purposes. Not cryptographically secure.
#include <cstdint>
// Random 32-bit unsigned integer.
uint32_t pcg32(uint64_t& rng) {
rng = rng * 6364136223846793005ULL + 1;
int rot = rng >> 59u;
uint32_t r = (rng >> 18u) ^ rng;
return (r >> rot) | (r << (32 - rot));
}
@orlp
orlp / build_python_windows.txt
Last active April 8, 2016 17:49
Compilation notes for Python on Windows.
Install VS2015 Express, Mercurial and `hg clone https://hg.python.org/cpython`.
Patch cpython/PC/python_ver_rc.h (why is this necessary?):
- # include <pythonnt_rc_d.h>
+ # include <pythonnt_rc.h>
cd cpython/PCbuild
get_externals
build -d -c Debug
build -c Release
; Install the Fontin font http://www.exljbris.com/fontin.html.
; Edit log_file to your Client.txt path.
; Edit overlay_x, overlay_y to fit your desire. Default is right under the timer for 1920x1080.
; Your game needs to be in windowed fullscreen mode.
log_file = C:\Program Files\Steam\SteamApps\common\Path of Exile\logs\Client.txt
overlay_x := 340
overlay_y := 975
; Shouldn't need to edit below this line.
filehandle := FileOpen(log_file, "r")
@orlp
orlp / configure.py
Last active October 15, 2022 21:39
A template for a ninja configuration file.
import os
import sys
import fnmatch
__doc__ = """Build configurator.
Usage:
configure.py [options] [-D var[=val]]...
import math
def clamp(c):
return min(max(c, 0), 1)
def less_angry_rainbow(t, gamma=1):
"""Given an interpolation value on [0, 1], this returns a RGB tuple ([0, 1])
of the "less-angry rainbow" by Mike Bostock. The gamma can be used to make
the rainbow lighter or darker."""
@orlp
orlp / ascii_ctype.h
Last active June 26, 2018 11:16
An ASCII only ctype.h implementation (C11/C++11 char32_t).
#ifndef ASCII_CTYPE_H
#define ASCII_CTYPE_H
#define ASCIIRANGE(c, start, len) (char32_t((c) - (start)) < char32_t(len))
inline bool aislower(char32_t c) { return ASCIIRANGE(c, 0x61, 26); }
inline bool aisupper(char32_t c) { return ASCIIRANGE(c, 0x41, 26); }
inline bool aisdigit(char32_t c) { return ASCIIRANGE(c, 0x30, 10); }
inline bool aisbdigit(char32_t c) { return ASCIIRANGE(c, 0x30, 2); }
inline bool aisodigit(char32_t c) { return ASCIIRANGE(c, 0x30, 8); }
inline bool aisxdigit(char32_t c) { return ASCIIRANGE(c | 32, 0x61, 6) || aisdigit(c); }
@orlp
orlp / fast_sin.c
Last active May 2, 2017 19:03
Fast sin implementation for IEEE754 doubles.
inline double fast_sin(double x) {
// Polynomial constants generated with sollya.
// fpminimax(sin(x), [|1,3,5,7|], [|D...|], [-pi/2;pi/2]);
// Both relative and absolute error is 9.39e-7.
const double magicround = 6755399441055744.0;
const double negpi = -3.14159265358979323846264338327950288;
const double invpi = 0.31830988618379067153776752674502872;
const double a = -0.00018488140186756154724131984146140;
const double b = 0.00831189979755905285208061883395203;
const double c = -0.16665554092439083255783316417364403;
@orlp
orlp / index.html
Last active November 6, 2015 21:53
<!DOCTYPE html>
<meta charset="utf-8">
<style>
</style>
<body>
<h1>Copy/paste weapon stats here:</h1>
<form id="user-input">
<textarea id="weapon-data"></textarea>
</form>
<pre id="out"></pre>

Enter Vim clean-sheet (vim -u NONE) and write the following text:

a a
a
a

Go to the beginning of the file, search for a, go back to the first result and do a search/replace with a*, repeating it once:

gg*Ncgna*<Esc>.

If you have a number x of the form:

a.bc

Where a is the integer part, b is the non-repeating fractional part, and c is the repeating fractional part, then the resulting fraction has value:

a.b + c / ((10^num_digits(c) - 1) * 10^num_digits(b))

So for 0.333333... we have: