Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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) {
[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 / albert.cc
Created October 15, 2020 14:49
How to use remove_if
#include <iostream>
#include <vector>
#include <algorithm>
using std::vector;
using std::remove_if;
using std::cout;
using std::endl;
bool smol(vector<int> vec);
@packrat386
packrat386 / namer.py
Created November 23, 2020 01:53
Unit test mocking example in python
def name_replay(we, they):
return timestamp()+ '_' + we + '_vs_' + they
def timestamp():
# not yet implemented
return
@packrat386
packrat386 / output.txt
Last active December 21, 2020 21:04
tricking sorbet
[acoyle01] wat > bundle exec srb tc
village.rb:13: This code is unreachable https://srb.help/7006
13 | raise "gtfo #{participant}"
^^^^^^^^^^^^^^^^^^^^^
Errors: 1
[acoyle01] wat > bundle exec ruby village.rb
time for the festival
#<Human:0x000055d9d0f03598> got wine
Traceback (most recent call last):
3: from village.rb:53:in `<main>'
@packrat386
packrat386 / output.txt
Created January 5, 2021 23:12
YAML to JSON is harder than you might think
[acoyle01] wat > go run yamltojson.go
lets turn YAML into JSON
here's the naive data structure
(map[string]interface {}) (len=1) {
(string) (len=3) "top": (map[interface {}]interface {}) (len=4) {
(string) (len=5) "super": (map[interface {}]interface {}) (len=1) {
(string) (len=5) "duper": (map[interface {}]interface {}) (len=1) {
(string) (len=4) "deep": (string) (len=3) "map"
}
},