Skip to content

Instantly share code, notes, and snippets.

@Skrylar
Skrylar / simple mailbox generator.nim
Last active May 17, 2020 13:40
mostly complete edition
# Copyright 2020 by Joshua "Skrylar" Cearley,
# Available under the Mozilla Public License, version 2.0,
# https://www.mozilla.org/en-US/MPL/2.0/
import macros
import strformat
import sugar
macro make_postbox*(name, body: untyped): untyped =
# validate body of our macro
@Skrylar
Skrylar / gist:8c42061559e03894fb009210d0d25857
Created May 10, 2020 05:18
Using a special unlock template to ensure sync flags are up to date
# TODO protect fields with inline procs that should get optimized out in release builds, but in debug builds can do asserts to make sure you unlocked it first
import opengl
import macros
import skyhash/xxhash
import sklog
type
TextureParameterBrush* = object
xhash*: uint64
@Skrylar
Skrylar / tackystacks.nim
Created May 8, 2020 00:07
I wanted to know how `chronicle` 's stack-based parameter system for logs could work. So I pulled this out of a description of it on their README.
#- = Making a stack-based parameter system
#-
#- I wanted to know how `chronicle` 's stack-based parameter system for
#- logs could work. So I pulled this out of a description of it on their
#- README. No spoilers were read beforehand.
#-
#- Here's how it works:
#-
#- . Marker objects are defined to hold information relevant from that
#- level of the stack downward.
import printingpress
import skmap/robin
import math
type
FlowDirection* = enum
LeftToRight
TopToBottom
@Skrylar
Skrylar / worley.py
Created January 14, 2020 23:45
tytel: hmm, wonder what 1D worley noise would be like
from math import sqrt
from tqdm import tqdm
from random import random
import matplotlib
from matplotlib import pyplot as plt
point_count = 20
zoop = [0]*2048
points = [0]*point_count
import libcurl
const
feed = "https://feeds.feedburner.com/breitbart?format=xml"
var downloaded = newstringofcap(1024)
proc onwrite(buffer: cstring; size, nitems: int; outstream: pointer): int =
let total = size * nitems
for i in 0..<total:
downloaded.add buffer[i]
# not sure why this isn't built-in
template inc(self: var float; other: float) =
self = self + other
type
Averager* = object
count: int
x: float
proc feed*(self: var Averager; value: float) =
@Skrylar
Skrylar / cobweb.nim
Last active November 16, 2017 15:43
var cobweb = Cobweb()
cobweb.def_root(inflation, float)
cobweb.def_root(monies, float)
cobweb.def_root(transhumanity, bool)
cobweb.def rich, bool:
result(monies):
monies > 1000000
@Skrylar
Skrylar / fsm.nim
Created September 9, 2017 19:43
Testing syntax for a fsm generator.
import macros
macro fsm*(name, definition: untyped): untyped =
echo treeRepr definition
fsm butt:
# default actions are taken when getting an input without that state
# knowing what to do about it
default:
proc parse(input: string) =
var i = 0
template getch(): char =
if i > input.high:
break
inc i
input[i-1]