Skip to content

Instantly share code, notes, and snippets.

Avatar

Austin Hyde austinhyde

View GitHub Profile
@austinhyde
austinhyde / adt-5.6.php
Last active Aug 29, 2015
PHP: Algebraic Data Types, Functors, and Applicative Functors
View adt-5.6.php
<?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 / convert-percentage
Created Jun 22, 2015
CLI convert percentage to Unicode box
View convert-percentage
$ 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*")'
View active-docker-machine-ps1.sh
function __dm {
DM="$(docker-machine active 2>&1)" && printf "$1" "$DM"
}
export PS1='… $(__dm '%s ') …'
@austinhyde
austinhyde / LICENSE
Last active Jun 5, 2020
3D Bar Chart
View LICENSE
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
@austinhyde
austinhyde / README.md
Last active Jun 28, 2020
KO Content Component
View README.md

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 / .bashrc
Created Jan 25, 2021
Fuzzy Git Checkout - For when you have too many branches
View .bashrc
# 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 Feb 23, 2021
Run Script, with dev docker image
View README.md

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

@austinhyde
austinhyde / js-observables-binding.md
Last active Apr 14, 2021
Vanilla JavaScript Data Binding
View js-observables-binding.md

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);