Skip to content

Instantly share code, notes, and snippets.

View kingishb's full-sized avatar
🤗
hi!

Brian King kingishb

🤗
hi!
View GitHub Profile
function dbg(msg: any) {
const e = new Error();
const regex = /\((.*):(\d+):(\d+)\)$/;
if (e.stack) {
const match = regex.exec(e.stack.split("\n")[2]);
if (match) {
const f = match[1].split("/")
console.log(`${f[f.length-1]}:${match[2]}: ${JSON.stringify(msg, null, 2)}`);
}
}
@kingishb
kingishb / main.go
Created December 26, 2020 19:57
resize images
// go mod init x && go get github.com/nfnt/resize
// go run main.go
package main
import (
"image/jpeg"
"log"
"os"
@kingishb
kingishb / day_1.zig
Created December 1, 2020 19:40
aoc day 1
const expect = @import("std").testing.expect;
const std = @import("std");
pub fn main() !void {
// read numbers into an arraylist
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer {
const l = gpa.deinit();
}
var nums = std.ArrayList(i32).init(&gpa.allocator);
@kingishb
kingishb / Riddler.ipynb
Created September 15, 2020 04:11
Riddler!
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kingishb
kingishb / f.py
Created August 27, 2020 01:22
File finder
#!/usr/bin/env python3
"""
File finding utility.
Usage:
# scan current directory for files with the regex foo
f foo
# scan /bar for regex foo, ignoring subdirectory baz
f --ignore baz --root /bar foo
@kingishb
kingishb / xmlfmt
Created April 10, 2020 01:54
format xml docs
#!/usr/bin/env python3
"""
Formats xml documents.
Usage:
xmlfmt docs/
"""
import os
import argparse
import xml.dom.minidom
@kingishb
kingishb / main.go
Last active February 29, 2020 01:10
Celsius to Fahrenheit table
package main
import (
"fmt"
"os"
"text/tabwriter"
)
func c2f(c float64) float64 {
return float64(c*9/5 + 32)
@kingishb
kingishb / day10.rs
Created December 13, 2019 10:52
advent day 10 in rust
use itertools::Itertools;
use std::cmp::{Eq, PartialEq, PartialOrd};
use std::collections::HashSet;
use std::env;
use std::fs::read_to_string;
use std::iter::FromIterator;
fn main() {
// read asteroid file
let f = env::args().nth(1).expect("missing filename");
@kingishb
kingishb / main.go
Created December 13, 2019 04:38
gen permutations with heap's algorithm - https://en.wikipedia.org/wiki/Heap%27s_algorithm
package main
import "fmt"
// swap swaps elements in a slice
func swap(i, j int, slice []int) {
v1 := slice[i]
v2 := slice[j]
slice[i] = v2
slice[j] = v1
@kingishb
kingishb / example.json
Last active November 2, 2019 16:55
Some example json
[
{
"id": 9284,
"name": "brian",
"numbers": [
1,
2,
3,
4,
5