Skip to content

Instantly share code, notes, and snippets.

@heyimalex
heyimalex / autosave.py
Last active Jan 30, 2020
Nexhealth toy project
View autosave.py
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 Dec 19, 2019
Combine a bunch of pngs into an ico file.
View main.rs
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 Jun 18, 2019
CRA build with gzip
View compress.js
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 Mar 13, 2019
Looking at npm projects that are good candidates for being re-written in rust / webassembly!
View rust-js.md
@heyimalex
heyimalex / PromiseState.ts
Last active Jun 21, 2019
Primitives for representing promise states
View PromiseState.ts
// 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 Sep 21, 2018
batching channel implementation
View batchchan.go
package batchchan
import "github.com/cheekybits/genny/generic"
import (
"fmt"
)
type T generic.Type
@heyimalex
heyimalex / runtime-env-build.js
Created Jun 7, 2017
create-react-app build script with optional runtime env var injection
View runtime-env-build.js
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
reselect-map typescript types
View reselect-map-types-gen.js
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 Dec 9, 2020
Functions for querying directly into map[string]interface{}
View sqlmap.go
// 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 Mar 17, 2017
Script for signing GitHub powershell scripts with code signing certificate on Windows
View github_desktop_ps_sign.py
#!/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