Skip to content

Instantly share code, notes, and snippets.

@pinealan
pinealan / encode_web_safe_color.js
Last active December 8, 2021 02:56
PixelMap compression contest submission
/* Pair of compress/decompress functions for hex-triplet encoded web safe 16x16 image.
*
* Uses max Brotli quality for max compression ratio, trading off computation
* time. Assumes lower case image string input and produces lower case output.
*
* Uses the first byte to lookup the encoding/compression strategy.
*/
const base91 = require('node-base91')
const stream = require('stream') // needed for zlib
@pinealan
pinealan / encode_web_safe_color.py
Last active September 3, 2021 00:48
Compressed encoding for web safe color.
import base64
import itertools
import zlib
# look up table for web safe color rgb hex
allowed_hex = ['0', '3', '6', '9', 'c', 'f']
code_to_hex = {idx: ''.join(s)
for idx, s in enumerate(itertools.product(allowed_hex, repeat=3))}
@pinealan
pinealan / eval-outer-top-list.vim
Created April 13, 2021 14:50
Select second top form within comment
" from vim-sexp
function! s:get_visual_marks()
return [getpos("'<"), getpos("'>")]
endfunction
function! s:set_visual_marks(marks)
call setpos("'<", a:marks[0])
call setpos("'>", a:marks[1])
endfunction
@pinealan
pinealan / direnv-export-summary.bash
Created February 19, 2021 02:22
Direnv hook with summary on exported env variables
direnv_hook() {
local previous_exit_status=$?;
# eval "$(direnv export bash)";
eval "$(direnv export bash 2> >( \
awk '
$0 !~ /^direnv: export/
$0 ~ /^direnv: export/ {
plus = gsub("\\+", "");
minus = gsub("-", "");
change = gsub("~", "");
@pinealan
pinealan / nix-env-diff.bash
Last active September 12, 2023 12:04
Diff installed packages between nix generations
#!/usr/bin/env bash
# From https://github.com/pinealan/dotfiles
nix-list() {
nix-env --list-generations
}
get_current_gen() {
if [ -z $1 ] ; then
# default to current generation of nix-env
@pinealan
pinealan / react-component.md
Created April 1, 2020 02:36
Brain dump on React concepts of element, component, instance

React: Element, Component, Instance

Element.

<Text>Hello, gini</Text>

Element with clothes off.

{

type: Text,

@pinealan
pinealan / venv.bash
Created January 23, 2020 11:16
Bash snippet for easy access to venv
venv() {
# use global venvs from $HOME if arg is provided
if [[ -n $1 ]]; then
. ~/venv/$1/bin/activate
return
fi
# look for a venv in current directory
for dir in "venv" ".venv" "env" ".env"; do
if [[ -d $dir ]]; then
@pinealan
pinealan / tmux.md
Last active February 6, 2018 14:32
Tmux cheatsheet (custom)

Tmux cheatsheet

The prefix key is C-a

From terminal:

tmux new -s <session-name>                          Create and attach to new session
tmux attach -t <session-name>                       Attach to existing session
tmux new -t <target-session> -s <session-name>      Create new <session-name> that is grouped with <target-session>
@pinealan
pinealan / plotcandle.py
Created January 27, 2018 20:18
Plots candlestick chart from a JSON formatted tick data file
#!/home/alan/miniconda3/bin/python3
import sys
import json
from datetime import datetime
from recordclass import recordclass
from matplotlib import pyplot as plt
Candle = recordclass('Candle', ['open', 'close', 'hi', 'low', 'ts', 'volume'])
@pinealan
pinealan / gitchanges.sh
Last active December 21, 2023 03:41
Parse git log stats and give an overview of daily repo changes
#!/bin/bash
OPT=""
AUTHOR=""
for i in "$@"; do
case $i in
-a|--all)
OPT+="--all"
OPT+=" "