Instantly share code, notes, and snippets.

View sameline.sc
# experimenting with making a section conditional without using indentation
fn test1 ()
print "hello"
print "world"
print "what's up"
print "?"
fn test2 ()
print "hello"
View speakable_number_kj.py
# partial katakana romaji, base 65
syllables = [
"ka", "ki","ku","ke","ko", #"kya","kyu","kyo",
"sa","su","se","so", #"sha","shu","sho","shi",
"ta","te","to", #"cha","chu","cho","chi","tsu",
"na","ni","nu","ne","no", #"nya","nyu","nyo",
"ha","hi","fu","he","ho", #"hya","hyu","hyo",
"ma","mi","mu","me","mo", #"mya","myu","myo",
"ya","yu","yo",
"ra","ri","ru","re","ro", #"rya","ryu","ryo",
View scrambler.cpp
// based on https://preshing.com/20121224/how-to-generate-a-sequence-of-unique-random-integers/
static uint32_t permute(uint32_t x, uint32_t prime) {
if (x >= prime)
return x;
uint32_t residue = ((uint64_t) x * x) % prime;
return (x <= prime / 2) ? residue : prime - residue;
}
static uint64_t scramble(uint64_t x) {
// find msb
View speakable_numbers.py
even_letters = "bcdfghlmnprstwx"
odd_letters = "aeiou"
def format_uid_digit (n, level):
if n != 0:
letters = odd_letters if (level & 1) else even_letters
base = len(letters)
s = format_uid_digit(n / base, level + 1)
return s + letters[(n % base)]
return ""
View PAEK_reverse_engineering.py
from math import *
# a performant solution would store a prefix sum of line lengths to
# a sidechannel and then use that to do a bsearch; on the GPU,
# you'd do a sum tree / histopyramid as a preprocessing step
def find_point(points, d):
d = d
for i in range(1, len(points)):
x0,y0 = points[i-1]
x1,y1 = points[i]
View borrow_inference.md

Borrow Inference

by Leonard Ritter, Duangle GbR

This is a description of borrow inference, an alternative to borrow checking that requires no declarative annotations to support proper management of unique values and borrowed references at compile time.

We are trying to infer whether a value is borrowed or has to be unique, applying this constraint going backwards through the function, as we also need to prevent

View result.hpp
/*
The Scopes Compiler Infrastructure
This file is distributed under the MIT License.
See LICENSE.md for details.
*/
#ifndef SCOPES_RESULT_HPP
#define SCOPES_RESULT_HPP
#include <assert.h>
View randomwalk.cpp
#include <stdio.h>
#include <stdlib.h>
void measure(int maxsteps) {
const int tries = 1000000;
int success = 0;
for (int attempts = 0; attempts < tries; ++attempts) {
int x = 0;
int y = 0;
for (int i = 0; i < maxsteps; ++i) {
View key_is_value.cpp
static const Type *ReturnLabel(ReturnLabelType::Mode mode, const Args &values) {
struct Equal {
bool operator()( const ReturnLabelType *lhs, const ReturnLabelType *rhs ) const {
return
(lhs->mode == rhs->mode)
&& (lhs->values == rhs->values);
}
};
struct Hash {
View perfect_spatial_hashing.txt
# forays into
Perfect Spatial Hashing (Lefebvre & Hoppe)
http://hhoppe.com/perfecthash.pdf
how it works:
There are two parts: a slow encoding step, and a fast decoding step.
Encoding