Skip to content

Instantly share code, notes, and snippets.

@non
non / grep.tal
Last active February 10, 2022 03:52
Regex implementation in Uxntal. Includes a simple grep implementation was well as a REPL for testing.
( grep.tal )
( )
( by d_m )
( print a character to STDOUT )
%emit { #18 DEO }
( the first argument to grep is the regex )
( arguments are passed on STDIN, so we just )
( assume the first "line" is the argument )
;; tal-mode.el
;;
;; by d_m
;; use rx for regular expressions
(require 'rx)
;; set up a mode hook (currently unused)
(defvar tal-mode-hook nil)
@non
non / rng.tal
Created November 26, 2021 06:46
( rng.tal )
( simple 16-bit xorshift RNG )
( based on http://b2d-f9r.blogspot.com/2010/08/16-bit-xorshift-rng-now-with-more.html )
%<<5 { #50 SFT2 }
%>>1 { #01 SFT2 }
%>>3 { #03 SFT2 }
%RTN { JMP2r }
%EMIT { #18 DEO }
%DIGIT { #00 SWP ;digits ADD2 LDA EMIT }
@non
non / csv.scala
Last active November 5, 2020 03:52
package cats.parse
package examples
import cats.implicits._
import Parser.{char, charWhere, charsWhile, string1}
object Csv {
def mkString(p: Parser1[Char]): Parser[String] =
@non
non / Wild.scala
Last active April 9, 2020 00:26
Interesting trick to lift existentials into values, so we can later refer to them.
package demo
import cats.{Applicative, Functor, Id, Semigroupal, Traverse}
import cats.arrow.FunctionK
/**
* Type-lifting operation to replace the wildcard type (i.e. _).
*
* In some cases we end up with code like: List[Option[_]]. This is
* fine unless you later need to write code in terms of a particular
@non
non / massdel.py
Created January 9, 2020 18:15
Script to delete all issues for a repo. This is different than just closing all of them. It uses the v4 GraphQL Github API.
#!/usr/bin/env python
#
# by Erik Osheim
#
# STEPS TO USE
#
# 0. install deps
# - pip install requests
#
# 1. generate personal access token
@non
non / sizes.txt
Last active October 16, 2019 10:09
Size of various JVM data structures in bytes (top column is number of elements).
COLLECTION 0 1 5 10 50 100 500 1000
Array[Int] 16 24 40 56 216 416 2016 4016
immutable.BitSet 24 24 24 24 24 32 96 160
immutable.IntMap[Int] 16 40 328 688 3568 7168 35968 71968
immutable.List[Int] 16 56 216 416 2016 4016 20016 40016
immutable.Map[Int,Int] 16 40 304 720 4856 9680 53504 111760
immutable.Queue[Int] 40 80 240 440 2040 4040 20040 40040
immutable.Set[Int] 16 32 264 480 3016 5840 27696 57952
immutable.SortedMap[Int,Int] 40 88 280 520 2440 4840 30008 62008
immutable.SortedSet[Int] 40 104 296 536 2456
#!/bin/sh
#
# simple streaming from the command line:
#
# ./cast.sh send *.mp3 # stream some files
#
# ./cast.sh recv # listen to the stream
#
# currently hardcodes localhost port 9999.
#
@non
non / ints.scala
Last active March 24, 2019 14:25
Type-level integers. Like shapeless' Nat, but supports negative numbers. Oh, and I've never actually run the code (but it compiles).
package quantity
// like Nat, but for integers
trait Z
// Pos means positive-or-zero, and Neg means negative-or-zero
trait Pos extends Z { type P <: Pos }
trait Neg extends Z { type N <: Neg }
class Zero extends Pos with Neg { type N = Zero }
package cats.collections
sealed abstract class LogicalBitSet { lhs =>
import LogicalBitSet.{Absent, Present}
def apply(n: Int): Boolean =
this match {
case Present(bits) => bits(n)
case Absent(bits) => !bits(n)