Skip to content

Instantly share code, notes, and snippets.

[fg-386] ~ > cat sanity.cpp
#include <iostream>
#include <unordered_set>
using namespace std;
int main(int argc, char* argv[])
{
auto myset = unordered_set<int>{1,2,3};
@packrat386
packrat386 / list.go
Last active April 25, 2020 19:22
Q: Can I build a "pure" functional map in Go without using builtin map? A: Maybe
package mymap
type List func() (frontFunc, restFunc, emptyFunc)
type frontFunc func() (string, string)
type restFunc func() List
type emptyFunc func() bool
func NewList() List {
front := func() (string, string) {
@packrat386
packrat386 / cloj.go
Created April 24, 2020 05:46
Cuteness intensifies
package cloj
import (
"sync"
)
// Map is an example of a type I might need that has some
// inner bits that need to be in harmony for the whole thing
// to function. In this case, what we're imagining is a kv store
// of string -> string that is safe to concurrently access.
@packrat386
packrat386 / wat.go
Created February 19, 2020 23:01
A map that errors out if you attempt to marshal JSON with duplicate keys
package wat
import (
"bytes"
"encoding/json"
"fmt"
)
type noDupMap map[string]string
@packrat386
packrat386 / example.go
Created January 11, 2020 07:00
melian example
package main
import (
"crypto/tls"
"fmt"
"net/http"
"os"
"github.com/packrat386/melian"
)
@packrat386
packrat386 / aidan.txt
Created October 29, 2019 17:55
Character rolls
STR - 13
DEX - 14
CON - 11
INT - 14
WIS - 15
CHA - 17
@packrat386
packrat386 / clients.go
Created October 10, 2019 20:13
How to dependency inject for a function in go
package main
import "fmt"
func handle(f func(input string) string) { fmt.Println(f("foo")) }
func main() {
handle(func(input string) string {
return handler(input, &ic{42}, &sc{"bar"})
})
@packrat386
packrat386 / index.go
Created July 3, 2019 03:00
Dumb impl of `bytes.Index`
package index
func Index(s, sep []byte) int {
pos := 0
for {
if pos+len(sep) > len(s) {
return -1
}
@packrat386
packrat386 / builder.go
Created April 26, 2019 19:12
Regex parser because I was bored on a plane
package re
import "fmt"
type builderEdge struct {
from int64
to int64
on rune
}
@packrat386
packrat386 / 0001-Override-the-RB_TEST-macro-to-check-falsiness.patch
Created February 10, 2019 16:01
Git patch to override RB_TEST to attempt to check class instead of specific values. Didn't work very well.
From ee8b5f5c1f4072affd1c3d68209e39889831c56e Mon Sep 17 00:00:00 2001
From: Aidan Coyle <packrat386@gmail.com>
Date: Sun, 10 Feb 2019 15:54:21 +0000
Subject: [PATCH] Override the RB_TEST macro to check falsiness
Rather than only accepting the exact values Qnil and Qfalse, instead
check the class of the VALUE passed to see if it is FalseClass.
---
eval.c | 16 ++++++++++++++++
include/ruby/ruby.h | 12 ++++++------