Skip to content

Instantly share code, notes, and snippets.

Orson Peters orlp

Block or report user

Report or block orlp

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Villagers.md

Villager mechanics in 1.14. All this data has been deduced by using the following commands:

/data get entity @e[type=minecraft:villager,limit=1,sort=nearest] Brain.memories
/execute as orlp at orlp run tellraw @s {"nbt":"Brain.memories","entity":"@e[type=villager,sort=nearest,limit=1]"}

A villager is awake from 0-11999 and tries to sleep between 12000 and 23999.

A villager will claim a bed if:

View quantize_with_dither.glsl
// Original idea by Mikkel Gjoel (https://computergraphics.stackexchange.com/a/5952/10515),
// simplified to one readable function.
// Demo at https://www.shadertoy.com/view/Wts3zH.
// Dithers and quantizes color value c in [0, 1] to the given color depth.
// It's expected that rng contains a uniform random variable on [0, 1].
uint dither_quantize(float c, uint depth, float rng) {
float cmax = float(depth) - 1.0;
float ci = c * cmax;
View gen.py
from collections import namedtuple, defaultdict
EarleyItem = namedtuple("EarleyItem", ["rule", "dot", "origin"])
def item_advance(item):
return EarleyItem(rule=item.rule, dot=item.dot + 1, origin=item.origin)
class Generator:
def __init__(self, G, terminals):
self.G = [["S'", G[0][0]]] + list(G)
View gf.py
import sympy as sp
import itertools as it
from sympy.physics.quantum import TensorProduct
def companion_matrix(p):
"""Gives companion matrix for polynomial p."""
p = sp.Poly(p)
assert p.is_monic
View pdqsort_boost.h
// Pattern-defeating quicksort
// Copyright Orson Peters 2017.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org/libs/sort/ for library home page.
View genfilter.py
# Standard, Hardcore, tmpstandard, tmphardcore
league = "tmpstandard"
categories = [
"DivinationCards",
"Essence",
"UniqueMap",
"UniqueFlask",
"UniqueWeapon",
"UniqueArmour",
"UniqueMap",
View zonetimer.ahk
#IfWinActive, Path of Exile ahk_class POEWindowClass
#MaxHotkeysPerInterval 500
#SingleInstance force
SendMode Input
; 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.
@orlp
orlp / peg.py
Last active Jul 3, 2018
PEG parser in Python.
View peg.py
from __future__ import unicode_literals
import sys
# We only use unicode in our parser, except for __repr__, which must return str.
if sys.version_info.major == 2:
repr_str = lambda s: s.encode("utf-8")
str = unicode
else:
repr_str = lambda s: s
View ratio_to_recurring.py
from sympy.ntheory import factorint, multiplicity
import operator as op, functools, itertools, fractions
factorlist = lambda n: sum(([p] * k for p, k in factorint(n).items()), [])
totient_factors = lambda n: sum((factorlist(p-1) + [p]*(k-1)
for p, k in factorint(n).items()), [])
divisors = lambda fs: [functools.reduce(op.mul, c, 1)
for l in range(len(fs) + 1) for c in itertools.combinations(fs, l)]
leadzero = lambda n, l: str(n).zfill(l) if l else ""
View ac.py
import bisect
import io
# We use 17-bit internal values with 15-bit probabilities.
CODE_VALUE_BITS = 17
FP_MAX = (1 << CODE_VALUE_BITS) - 1
FP_QUARTER = FP_MAX//4 + 1
FP_HALF = 2*FP_QUARTER
FP_3QUARTER = 3*FP_QUARTER
FREQ_BITS = CODE_VALUE_BITS - 2
You can’t perform that action at this time.