Skip to content

Instantly share code, notes, and snippets.

Avatar
:shipit:
shippin' it

Austin Hyde austinhyde

:shipit:
shippin' it
  • Uber ATG
  • Pittsburgh, PA
View GitHub Profile
View active-docker-machine-ps1.sh
function __dm {
DM="$(docker-machine active 2>&1)" && printf "$1" "$DM"
}
export PS1='… $(__dm '%s ') …'
@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*")'
@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 / js-observables-binding.md
Last active Sep 22, 2020
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);
@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 / 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
You can’t perform that action at this time.