Skip to content

Instantly share code, notes, and snippets.

View ear7h's full-sized avatar
🚲
now on a bike

Julio ear7h

🚲
now on a bike
View GitHub Profile
@ear7h
ear7h / list-drop-test.dhall
Last active June 15, 2022 23:08
dhall-list-drop
let drop = https://prelude.dhall-lang.org/List/drop
let generate = https://prelude.dhall-lang.org/List/generate
let f = \(g : Natural) -> generate g Natural (\(x : Natural) -> x)
in \(g : Natural) -> \(n : Natural) -> drop n Natural (f g)
enum_discrim_align_threshold = 70
error_on_line_overflow = true
error_on_unformatted = true
format_code_in_doc_comments = true
format_macro_matchers = true
format_strings = true
imports_layout = "HorizontalVertical"
match_block_trailing_comma = true
max_width = 80
imports_granularity = "Module"
@ear7h
ear7h / todo
Created June 15, 2021 19:13
A command line todo application
#!/usr/bin/env sh
alias isodate='date +"%Y-%m-%d"'
if [ $# -eq 0 ]; then
cat ~/todo/$(isodate).txt
exit 0
fi
if [ $# -gt 1 ]; then
@ear7h
ear7h / Stats.hs
Created April 12, 2021 10:09
simple stats function implementations
import Data.List
mean x = (sum x) / (fromIntegral $ length x)
med xs = med' $ sort xs
med' [x] = x
med' [x, y] = (x + y) / 2
med' xs = med' $ drop 1 $ take (length xs - 1) xs
@ear7h
ear7h / ring_buf.rs
Created February 1, 2021 19:24
Ring buffer of utf8 strings
/// Ring buffer of utf8 strings
struct RingBuf {
ptr : *mut u8,
start : usize,
len : usize,
cap : usize,
}
impl RingBuf {
@ear7h
ear7h / runpeg
Created December 2, 2020 06:15
Run a pegjs grammar on an input without compiling it first
#!/usr/bin/env node
const pegjs = require("pegjs");
const fs = require("fs");
const file = fs.readFileSync(process.argv[2], "utf-8");
const parser = pegjs.generate(file);
const input = fs.readFileSync(0, "utf-8");
console.log(parser.parse(input));
@ear7h
ear7h / wildcard_tst.rs
Created September 15, 2020 17:52
A ternary search tree that handles wildcards
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(dead_code)]
#![allow(unused_mut)]
use std::cmp::{Ord, Ordering};
use std::collections::HashMap;
use std::convert::TryFrom;
use std::fmt;
@ear7h
ear7h / git-decolonize.go
Created June 25, 2020 04:32
Replace instances of the string "master" with "main" in a git binary executable
package main
import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"regexp"
)
@ear7h
ear7h / geohash2bits.go
Last active June 23, 2020 21:38
geohash into 32 bits
package main
import (
"fmt"
)
func main() {
geohash := "u4pruydqqvj"
for i := range geohash {
fmt.Println(geohash[:i+1], "\t", geohash2bits(geohash[:i+1]))
@ear7h
ear7h / main.rs
Created May 20, 2020 02:56
rust async/await toy executor and http handler trait
// The executor part was directly copied from the async book
// the http handler trait was written through trial and error
// and reading documentation
//
// Thre's two different handlers that I wrote, which behave the
// same way. The difference is that one is written with the
// async_trait macro and the other is hand written.
//
// The handlers pretty much look like the example code, in async_trait
// but the error message when the lifetime parameter on w and r were