Skip to content

Instantly share code, notes, and snippets.

View austinhyde's full-sized avatar

Austin Hyde austinhyde

  • Pittsburgh, PA
View GitHub Profile
@austinhyde
austinhyde / .bashrc
Created January 25, 2021 22:23
Fuzzy Git Checkout - For when you have too many branches
# requires fzf
# co -: check out last branch
# co -anything at all: just does a plain git checkout
# co foo: check out the branch with the closest name to "foo"
function co() {
if [[ $1 == -* ]]; then
git checkout "$@";
else
git checkout "$(git for-each-ref --format='%(refname:short)' refs/heads/** | fzf -f "$1" | head -1)";
@austinhyde
austinhyde / README.md
Last active September 5, 2022 03:23
Run Script, with dev docker image

One of the biggest barriers to starting in an unfamiliar repo is understanding how to start up the development environment, build the code, and other common tasks. Once a developer is established in a codebase, it's important to minimize development friction with common tasks.

The run script here is a very minimal script that makes it easy to see how to get started, what common tasks are available, and automates those tasks, no matter how trivial. Importantly for long-term maintainability, it allows the "repo maintainers" to change details about, say, starting a dev database, without most other engineers needing to care how that gets done (maybe we use docker-compose, maybe we use raw docker, maybe vagrant). And if they do care, they can just read the script or watch its output.

Importantly, the script is just plain old bash. Most developers are probably familiar with the syntax, and it's ubiquitous, meaning there's no dependencies to install and no esoteric shell-like syntaxes (like make) or librarie

function __dm {
DM="$(docker-machine active 2>&1)" && printf "$1" "$DM"
}
export PS1='… $(__dm '%s ') …'
@austinhyde
austinhyde / convert-percentage
Created June 22, 2015 18:52
CLI convert percentage to Unicode box
$ echo 0 | ruby -ne 'puts (n=($_.to_f*8).ceil)==0?" ":[[8,[0,n].max].min+0x2580].pack("U*")'
$ echo .25 | ruby -ne 'puts (n=($_.to_f*8).ceil)==0?" ":[[8,[0,n].max].min+0x2580].pack("U*")'
$ echo .3 | ruby -ne 'puts (n=($_.to_f*8).ceil)==0?" ":[[8,[0,n].max].min+0x2580].pack("U*")'
$ echo .4 | ruby -ne 'puts (n=($_.to_f*8).ceil)==0?" ":[[8,[0,n].max].min+0x2580].pack("U*")'
@austinhyde
austinhyde / adt-5.6.php
Last active August 29, 2015 14:11
PHP: Algebraic Data Types, Functors, and Applicative Functors
<?php
function b($b) { return $b ? 'true' : 'false'; }
function implodekv($ks, $es, $arr) {
return implode($es, array_map(function($k,$v)use($ks){return "$k$ks$v";},array_keys($arr),$arr));
}
interface Functor {
public function fmap(callable $func);
}
@austinhyde
austinhyde / js-observables-binding.md
Last active August 16, 2023 18:19
Vanilla JavaScript Data Binding

Observables

You don't really need a framework or fancy cutting-edge JavaScript features to do two-way data binding. Let's start basic - first and foremost, you need a way to tell when data changes. Traditionally, this is done via an Observer pattern, but a full-blown implementation of that is a little clunky for nice, lightweight JavaScript. So, if native getters/setters are out, the only mechanism we have are accessors:

var n = 5;
function getN() { return n; }
function setN(newN) { n = newN; }

console.log(getN()); // 5

setN(10);

@austinhyde
austinhyde / README.md
Last active June 28, 2020 15:30
KO Content Component

Using the changes in Knockout PR #1463, we can make a component that can inject the contents of a parent component into its template:

<my-component>Your name is <span data-bind="name"></span></my-component>
+
<template id="my-component">
  <strong><content></content></strong>
</template>
=
<strong>Your name is <span data-bind="name"></span></strong>
@austinhyde
austinhyde / LICENSE
Last active June 5, 2020 12:23
3D Bar Chart
Copyright 2020 Austin Hyde
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER