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 / gen.py
Last active July 26, 2018 00:50
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)
@orlp
orlp / peg.py
Last active July 3, 2018 02:10
PEG parser in Python.
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
@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); }
local driver = CreateFrame("Button", "casthack_driver", nil, "SecureHandlerClickTemplate")
local executor = CreateFrame("Button", "casthack_executor", nil, "SecureActionButtonTemplate")
driver:SetAttribute("_onclick", [[
local executor = self:GetFrameRef("executor")
if math.random() < 0.5 then
executor:SetAttribute("type", "spell")
executor:SetAttribute("spell", "Concussive Shot")
else
@orlp
orlp / gf.py
Created November 18, 2017 11:57
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
#include <stdint.h>
#include <string.h>
#define ROTL32(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
#define LOAD_LE32(x) \
(((x)[0] << 0) | \
((x)[1] << 8) | \
((x)[2] << 16) | \
((x)[3] << 24))
// 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.
#include <stdio.h>
#include <sodium.h>
int main(int argc, char **argv) {
int tries = 1;
sodium_init();
while (1) {
unsigned char zero_public_key[crypto_sign_PUBLICKEYBYTES] = {0};
@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 / genfilter.py
Last active February 7, 2017 20:30
# Standard, Hardcore, tmpstandard, tmphardcore
league = "tmpstandard"
categories = [
"DivinationCards",
"Essence",
"UniqueMap",
"UniqueFlask",
"UniqueWeapon",
"UniqueArmour",
"UniqueMap",