Skip to content

Instantly share code, notes, and snippets.

View dmgolembiowski's full-sized avatar

David M. Golembiowski dmgolembiowski

View GitHub Profile
@dmgolembiowski
dmgolembiowski / macros_rule.rs
Created June 9, 2024 20:07
Beginning to consolidate/revise some of my favorite macros, crafted either by me or someone respectable
//! This crate contains various macros and functions for the Rust programming language.
#[macro_export]
macro_rules! runtime_globals {
( $($constant:meta => $value:meta $(; $fallback_value:expr )? $(,)? )* ) => {
$(
::paste::paste! {
#[::lazy_fn::lazy_fn]
fn [< lazy_fn_ $constant:lower >]() -> &'static str {
@dmgolembiowski
dmgolembiowski / alt_allocator_read_to_end.rs
Created June 4, 2024 16:45
The argument in the standard library's File API's File::read_to_end method does not support vectors backed by non-Global allocators. This recipe addresses that.
#![feature(allocator_api, core_io_borrowed_buf, read_buf)]
#![allow(unused)]
#[rustfmt::skip]
use {
tmfalloc as tm,
std::{
cmp,
io::{prelude::*, BorrowedRef, ErrorKind},
path::Path,
},
@dmgolembiowski
dmgolembiowski / auto-automate
Created May 19, 2024 01:50
2nd Order Automation
#!/usr/bin/env python
import textwrap
from string import Template
def template(dir: str, full_pkg: str, ver: str = "0.1.0") -> str:
backslash = '\\'
backslash_newline = '\\n'
pkg_src = full_pkg + '_SOURCES=' + full_pkg + '.c'
it = textwrap.dedent('''\
#!/bin/bash
// ==UserScript==
// @name Cookie-Clicker for Alley Eddys
// @namespace http://tampermonkey.net/
// @version 0.1
// @description answsers requests from customers
// @author Me
// @require https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/7.21.2/babel.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/Detect.js/2.2.2/detect.min.js
// @run-at document-idle
// @match https://mystore.allenedmonds.com/backoffice
#!/usr/bin/env python3
# Use version 3.11.6
import click
import os
import time
@click.command()
@click.option('--model', default='openai/whisper-base', help='ASR model to use for speech recognition. Default is "openai/whisper-base". Model sizes include base, small, medium, large, large-v2. Additionally, try appending ".en" to model names for English-only applications (not available for large).')
@click.option('--device', default='cuda:0', help='Device to use for computation. Default is "cuda:0". If you want to use CPU, specify "cpu".')
@click.option('--dtype', default='float32', help='Data type for computation. Can be either "float32" or "float16". Default is "float32".')
@dmgolembiowski
dmgolembiowski / checkpoint.sh
Created January 16, 2024 21:23
Checkpoint script for when you do not want Git history
#!/bin/bash
cwd=$(dirname $(readlink -f $0))
checkpoint_dir="$cwd/backup"
mkdir -p "$checkpoint_dir"
infix=$(date '+%F_%T')
output="$checkpoint_dir/checkpoint-$infix.tar"
tar \
--exclude='dist' \
--exclude='__pycache__' \
--exclude='node_modules' \
To From Method
string of code literal code std::stringify!{}
string of code syntax tree !quote(#syntax_tree).to_string()
string of code TokenStream .to_string()
string of syntax literal code format!("{:?}",parse2::<SynType>(quote! {...}).expect(...)
string of syntax syntax tree format!("{:?}"),…), format!("{:#?}"),…)
string of tokens literal code format!("{:?}",quote! {...})
string of tokens TokenStream format!("{:?}"),…), format!("{:#?}"),…)
syn::Error TokenStream .to_compile_error() [see Rule #7]
syntax tree literal code parse_quote!(…)
function crunchtime(input) {
// time should be a delta from some time Xa-Ya,
// Xa-Y, Xp-Yp
// This function parses the first non-numeric character
// as an indication of whether it's receiving AM or PM,
// followed by a `-` to delimit between the starting time
// and ending time. Our expected inputs, less formally, resemble
// 4:45a-11a, 5p-12:30p, 6:45a-2p
input = input.trim();
if (input.toLowerCase() == "off") {
@dmgolembiowski
dmgolembiowski / build.rs
Created July 27, 2023 18:26 — forked from Ciantic/build.rs
Some in-memory stuff I threw away
use std::io::Write;
use std::{env, path::Path};
use std::{fs::OpenOptions, path::PathBuf};
use regex::Regex;
fn main() {
let dir = Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()).join("lib");
println!("cargo:rustc-link-search=native={}", dir.display());
@dmgolembiowski
dmgolembiowski / pi3_browser-only.md
Created June 17, 2023 00:00 — forked from bheisig/pi3_browser-only.md
Run Raspberry 3 in digital signage mode with Chromium Web browser on a TV screen