Skip to content

Instantly share code, notes, and snippets.

View jhunterkohler's full-sized avatar
🇺🇸
Working from the USA

Hunter Kohler jhunterkohler

🇺🇸
Working from the USA
  • United States
View GitHub Profile
@jhunterkohler
jhunterkohler / openapi-types.ts
Last active January 31, 2022 21:30
Relatively good; hand written Types for OpenAPI 3.1
/**
* Copyright (C) 2021 Hunter Kohler <[email protected]>
*/
type Dict<T> = { [P: string]: T | undefined };
export type SpecificationExtension = any;
export type OpenAPI = {
components?: Components;
@jhunterkohler
jhunterkohler / templates.js
Created October 23, 2021 20:11
Simple template-literal helpers for dynamic DOM manipulation.
/*
* Copyright (C) 2021 John Hunter Kohler <[email protected]>
*
* Simple template-literal helpers for dynamic DOM manipulation.
*/
const emptyTagNames = new Set([
"area", "base", "br",
"col", "embed", "hr",
"img", "input", "link",
@jhunterkohler
jhunterkohler / globals.css
Created October 24, 2021 19:21
Interproject default global styles
/*
* Copyright (C) 2021 Hunter Kohler <[email protected]>
*/
/*
* Global variables
*/
:root {
}
@jhunterkohler
jhunterkohler / memory-store.ts
Created November 2, 2021 21:24
Writable stream with options to cap in-memory store on internal buffer. Stores in array, then concats last.
import { WritableOptions, Writable } from "stream";
export interface MemoryStoreOptions extends WritableOptions {
objectMode?: false | undefined;
maxBufsize?: number;
}
export const DEFAULT_MAX_BUFSIZE = 1024 ** 2;
export class MemoryStore extends Writable {
@jhunterkohler
jhunterkohler / iterator.h
Created December 2, 2021 01:52
STL Container iterator wrapper
/*
* Wraps the template parameter without changing any semantics. Good
* for wrapping pointers.
*/
template <typename Iterator>
class normal_iterator {
public:
using difference_type = typename std::iterator_traits<Iterator>::difference_type;
using value_type = typename std::iterator_traits<Iterator>::value_type;
using pointer = typename std::iterator_traits<Iterator>::pointer;
@jhunterkohler
jhunterkohler / .gitignore
Last active April 3, 2022 08:26
General .gitignore base for all projects.
# System Files
.DS_Store
# Editor Files
.vscode/
# Build Directories
bin/
build/
dist/
@jhunterkohler
jhunterkohler / pip-upgrade-all
Last active December 24, 2021 21:53
Update all global pip dependencies with a simple script
#!/usr/bin/env python3
import pathlib
import subprocess
import tempfile
def main():
result = subprocess.run(
["pip3", "freeze"], text=True, capture_output=True, check=True)
@jhunterkohler
jhunterkohler / reljmp.c
Last active January 8, 2022 07:17
Replace functions by loading library symbols and writing a unconditional jump. (x86 only)
/*
* Copyright (C) 2021 Hunter Kohler <[email protected]>
*/
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include "reljump.h"
size_t page_size()
{
@jhunterkohler
jhunterkohler / .eslintrc.json
Created January 25, 2022 08:12
Personal ESLint Config
{
"$schema": "https://json.schemastore.org/eslintrc",
"env": {
"es6": true,
"node": true
},
"plugins": [],
"extends": [],
"globals": {},
"ignorePatterns": [],
@jhunterkohler
jhunterkohler / fs.ts
Created January 31, 2022 20:47
Alright file system walker
/*
* Copyright (C) 2021 Hunter Kohler <[email protected]>
*/
import fs from "fs";
import path from "path";
interface WalkdirOptions {
withFileTypes?: boolean;
followlinks?: boolean;
files?: boolean;