Skip to content

Instantly share code, notes, and snippets.

View staltz's full-sized avatar

André Staltz staltz

View GitHub Profile
staltz / example.js
Created March 18, 2019 20:59
Build your own RxJS
function createObservable(subscribe) {
return {
pipe: function(operator) {
return operator(this);
const numberObservable = createObservable(function(observer) {
staltz / readme.ts
Created April 25, 2018 17:31
* Callbag loves TypeScript
* Copy-paste this into
// A Callbag dynamically receives input of type I
// and dynamically delivers output of type O
type Callbag<I, O> = {
(t: 0, d: Callbag<O, I>): void;

Logic composability problems of lifecycle hooks in React

Suppose I have these components in my project:

class MessageHeader extends React.Component { /* ... */ }

class NiceButton extends React.Component { /* ... */ }

class FridgeContents extends React.Component { /* ... */ }
function xstreamToPullStream<T>(stream: Stream<T>): Readable<T> {
let hasBufferVal: boolean;
let bufferVal: T;
let bufferEndOrErr: any;
let callback: Callback<T>;
const listener: Listener<T> = {
next: t => {
console.log('pull stream Listener for xstream', t);
if (callback) {
console.log('pull stream direct', t);
staltz / .bashrc
Created October 16, 2017 12:42
Put this in your ~/.bashrc (or equivalent) file. Then run `reactnativedev ""`
# Tweak tap coordinates as you wish
function reactnativedev() {
adb shell input keyevent 82;
sleep 0.1;
adb shell input tap 150 1401;
sleep 0.1;
adb shell input tap 150 1401;
sleep 0.1;
adb shell input text "$1";
sleep 0.1;
export function drained$<T>(pullStream: Function): Rx.Observable<T> {
return Rx.Observable.create(function subscribe(observer: Rx.Observer<T>) {
const drain = function drain(read: Function) {
read(null, function more(end: any | boolean, data: T) {
if (end === true) {
if (end) {
staltz /
Created March 15, 2017 15:27
Nested Pick<T, K> in TypeScript 2.2

TypeScript supports Pick to allow you to get a "subset" object type of a given type, but there is no built-in Pick for deeper nested fields.

If you have a function that takes a large object as argument, but you don't use all of its fields, you can use Pick, Pick2, Pick3, etc to narrow down the input type to be only just what you need. This will make it easier to test your function, because when mocking the input object, you don't need to pass all fields of the "large" object.

staltz / .bashrc
Created March 7, 2017 13:08
Show a macOS notification when a terminal task is done
# Name it whatever you want. I like `y` because in my keyboard layout it's close to `;`
function y() {
if [ $previous -eq 0 ]; then
osascript -e "display notification \"Done\" with title \"Terminal Task\"" && say "it is done";
osascript -e "display notification \"Failed\" with title \"Terminal Task\"" && say "it went to the trees";
staltz /
Last active September 29, 2023 15:42
coding music

Not for everyone. Each programmer has their own appreciation of what is good coding music.

For when I need to think deep, debug something, or design

(From most influential to least)

staltz / adnetworks.txt
Created November 20, 2016 10:34
Ban these domains of ad networks,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,