Skip to content

Instantly share code, notes, and snippets.

@heyimalex
heyimalex / autosave.py
Last active January 30, 2020 17:41
Nexhealth toy project
import subprocess as sp
import pyautogui
import time
child = sp.Popen(["write.exe"])
time.sleep(1)
pyautogui.typewrite('Dae Choi is the best.\nGive me a job!', interval=0.1)
# Save
@heyimalex
heyimalex / main.rs
Created December 19, 2019 02:52
Combine a bunch of pngs into an ico file.
use std::{env, fs, process};
use std::error::Error;
use std::convert::{TryFrom,TryInto};
use std::io::{Write,BufWriter};
static HELP_TEXT: &str = "ico-join [<PNG>...] <DEST>
<PNG> Path to png files you want to combine.
<DEST> Path to the output file.
";
@heyimalex
heyimalex / compress.js
Last active June 18, 2019 19:07
CRA build with gzip
const fs = require("fs");
const path = require("path");
const glob = require("glob");
const async = require("async");
const zlib = require("zlib");
function gzipFile(src, callback) {
console.log(`Compressing ${src}`);
const dst = `${src}.gz`;
fs.createReadStream(src)
@heyimalex
heyimalex / rust-js.md
Created March 13, 2019 07:09
Looking at npm projects that are good candidates for being re-written in rust / webassembly!
@heyimalex
heyimalex / PromiseState.ts
Last active June 21, 2019 19:45
Primitives for representing promise states
// PromiseState provides primitives for representing a promise's "state" as a
// value.
//
// That's kinda abstract so let's think through it. At any given point in time
// a promise is either pending, resolved, or rejected. There's no real
// synchronous way to access this promise "state", promises only give us `then`
// and callbacks.
//
// In react we usually care about rendering _all_ of these possible states. For
// example, we want to show a spinner when it's loading, the results when it
@heyimalex
heyimalex / batchchan.go
Created September 21, 2018 20:01
batching channel implementation
package batchchan
import "github.com/cheekybits/genny/generic"
import (
"fmt"
)
type T generic.Type
@heyimalex
heyimalex / runtime-env-build.js
Created June 7, 2017 22:28
create-react-app build script with optional runtime env var injection
const fs = require("fs");
const crypto = require("crypto");
const spawnSync = require("child_process").spawnSync;
// Load the environment using the same code react-scripts uses.
process.env.NODE_ENV = "production";
const clientEnv = require("react-scripts/config/env")().raw;
const REACT_APP_RUNTIME = /^REACT_APP_RUNTIME_/i;
@heyimalex
heyimalex / reselect-map-types-gen.js
Last active May 22, 2017 12:07
reselect-map typescript types
function genSelectorType({ count, isParametric, isArraySelector }) {
const rmap = fn => {
const results = [];
for (let i = 2; i <= count; i++) {
results.push(fn(i));
}
return results;
};
@heyimalex
heyimalex / sqlmap.go
Last active April 6, 2024 14:25
Functions for querying directly into map[string]interface{}
// Package sqlmap provides functions for querying directly into
// map[string]interface{}.
//
// In developing really simple api endpoints, I found the boilerplate needed
// to take the results of a database query and output them as JSON to be
// really fucking annoying; make a custom struct, scan into that struct, if
// there are multiple rows do the whole rows.Next() song and dance, and if
// anything changes update the three spots each column of the result is now
// dependent on. Even when using libraries like sqlx, there's still a lot of
// extraneous code that needs to be written.
@heyimalex
heyimalex / github_desktop_ps_sign.py
Created March 17, 2017 16:41
Script for signing GitHub powershell scripts with code signing certificate on Windows
#!/usr/bin/env python
# This script signs github for desktop powershell scripts.
#
# Powershell scripts are locked down here (via sysadmin decree), but the GitHub
# Desktop app uses powershell scripts when you right click > "Open in Git
# Shell". This is pretty much a requirement since the application can only
# handle fairly simple git operations.
#
# In order for these scripts to work they need to be signed. I don't remember