Skip to content

Instantly share code, notes, and snippets.

Avatar

Dustin Knopoff dustinknopoff

View GitHub Profile
View init.vim
set runtimepath^=~/.vim runtimepath+=~/.vim/after
let g:python2_host_prog = '/usr/local/bin/python'
let g:python3_host_prog = '/usr/local/bin/python3'
let &packpath = &runtimepath
" Linter
" only lint on save
let g:ale_lint_on_text_changed = 'never'
let g:ale_lint_on_insert_leave = 1
let g:ale_lint_on_save = 0
View pillbox.uno
/*
Based off of
http://www.arduino.cc/en/Tutorial/Tone
*/
#include "pitches.h"
#include <Adafruit_NeoPixel.h>
View datestring.ts
type Day28 = '01'|'02'|'03'|'04'|'05'|'06'|'07'|'08'|'09'|10
|11|12|13|14|15|16|17|18|19|20
|21|22|23|24|25|26|27|28;
type Month = '01'|'02'|'03'|'04'|'05'|'06'|'07'|'08'|'09'|'10'|'11'|'12'
type Digit = 0|1|2|3|4|5|6|7|8|9;
type Year = `${19 | 20}${Digit}${Digit}`
type IsDivide4<S extends string | number> = `${S}` extends '0' | '4' | '8' ? true :
`${S}` extends `${number | ''}${`${0|2|4|6|8}${0|4|8}`|`${1|3|5|7|9}${2|6}`}` ? true : false;
type IsLeapYear<S extends string | number> =
View README.md

Requirements:

View sound-plane.ts
// music.setVolume(100)
enum PlaneState {
Idle, // No Sound
Liftoff, // playTone Note.D
Cruising, // playTone Note.CSharp
Left, // playTone Note.G
Right, // playTone Note.B
Turbulence, //music.playMelody("G B C C -- F F G", 300)
Landing, //playTone Note.C
@dustinknopoff
dustinknopoff / pdf_split.py
Created Dec 20, 2020
Split pdf into separate pages
View pdf_split.py
# Answer from https://stackoverflow.com/a/490203
from PyPDF2 import PdfFileWriter, PdfFileReader
inputpdf = PdfFileReader(open("document.pdf", "rb"))
for i in range(inputpdf.numPages):
output = PdfFileWriter()
output.addPage(inputpdf.getPage(i))
with open("document-page%s.pdf" % i, "wb") as outputStream:
output.write(outputStream)
View WebView.swift
import SwiftUI
import WebKit
import Combine
class WebViewData: ObservableObject {
@Published var loading: Bool = false
@Published var scrollPercent: Float = 0
@Published var url: URL? = nil
@Published var urlBar: String = "https://nasa.gov"
@dustinknopoff
dustinknopoff / schema.pest
Created Oct 30, 2020
If I ever decide to go back to generating rust structs/definitions for Schema.org
View schema.pest
WHITESPACE = _{NEWLINE | " " | "\n" | "\t"}
SchemaString = {"\"" ~ (("\\" ~ "\"") | (!"\"" ~ ANY))+ ~ "\"" ~ ("@" ~ ASCII_ALPHA+)? }
UrlNode = {(!(">" | "<") ~ ANY)+}
TAG = { "<" ~ UrlNode ~ ">"}
// Use url = "2.1" to parse out URLs...need to extract protocol, hostname, path, search, fragment
// A UrlNode is "subClassOf" "http://www.w3.org/2000/01/rdf-schema" "http://www.w3.org/2000/01/rdf-schema#subClassOf"
TRIPLE = { TAG ~ TAG ~ (TAG | SchemaString) ~ "." }
parse = {
SOI ~ TRIPLE*
}
View flowmachine.ts
type TypeState = Distribute<keyof FlowMachineSchema["states"], FlowMachineContext> // assuming same context
export type Send = Interpreter<FlowMachineContext, FlowMachineSchema, FlowEvents, TypeState>['send']
export type Context = [
State<FlowMachineContext, FlowEvents, FlowMachineSchema, TypeState>,
Send,
Interpreter<FlowMachineContext, FlowMachineSchema, FlowEvents, TypeState>
];
type Distribute<U, C> = U extends any ? { value: U; context: C } : never // util
View query_system.rs
use core::hash::Hash;
use std::sync::Arc;
use core::any::Any;
use core::any::TypeId;
use std::collections::HashMap;
use async_trait::async_trait; // 0.1.36
use tokio; // 0.2.21
use tokio::sync::RwLock;
// Our trait. The async part is not necessary, I just wanted to see how it behaves :)