Skip to content

Instantly share code, notes, and snippets.

View staltz's full-sized avatar

André Staltz staltz

View GitHub Profile
@staltz
staltz / readme.ts
Created April 25, 2018 17:31
callbag-typescript-proof-of-concept
/**
* Callbag loves TypeScript
*
* Copy-paste this into http://www.typescriptlang.org/play/index.html
*/
// 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;
@staltz
staltz / main.js
Created June 22, 2016 15:06
A-Frame + Cycle.js demo
import xs from 'xstream';
import Cycle from '@cycle/xstream-run';
import {h, makeDOMDriver} from '@cycle/dom';
require('aframe');
function main(sources) {
let vdom$ = xs.periodic(16).startWith(0).map(i =>
h('a-scene', [
h('a-sphere', {
attrs: {
@staltz
staltz / router.js
Last active August 5, 2019 08:42 — forked from axefrog/router.js
Simple router driver for Cycle.js utilising Router5 for routing functionality and adapting some of the code from VisionMedia's Page.js for automatic link click intercepting
'use strict';
import {Router5, RouteNode} from 'router5';
import logger from '../logger';
// The set of valid sink functions includes synchronous state-affecting router functions that do not require a callback
// and which do not have a significant return value other than the router object itself.
const validSinkFuncs = ['add','addNode','canActivate','deregisterComponent','navigate','registerComponent','setOption','start','stop'];
function validateAndRemapSinkArgument(arg) {
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) {
observer.complete();
return;
}
if (end) {
@staltz
staltz / main.js
Created March 4, 2016 21:22
Cycle.js demo with MIDI and Web Audio
import {Observable, Disposable} from 'rx';
import {run} from '@cycle/core'
const jsondiffpatch = require('jsondiffpatch').create({
objectHash: function(obj) {
return obj.name;
}
});
function generateCurve(steps){
var curve = new Float32Array(steps)
@staltz
staltz / gist:7473252
Last active March 6, 2018 05:23
Code glossary

Code glossary

A useful list of programming jargon to solve your naming problems.

Adapter: a design pattern that translates one interface for a class into a compatible interface.

Admin: short for 'administrator'; very commonly used in speech or online to refer to the systems person in charge on a computer. Common constructions on this include sysadmin and site admin (emphasizing the administrator's role as a site contact for email and news).

Counter: a variable or user interface that counts occurrences or repetitions of some phenomena or event.

@staltz
staltz / _set_local_env_vars.py
Last active February 22, 2018 10:13
Call this from your Django settings file to import environment variables from '.env'. Useful if you use PyCharm and want an automatic solution to recognize your env variables.
import os
ENV_VARS_FILENAME = '.env'
def import_env_vars(project_root):
"""Imports some environment variables from a special .env file in the
project root directory.
"""
if len(project_root) > 0 and project_root[-1] != '/':
@staltz
staltz / app.kt
Last active January 26, 2018 01:20
Cycle giving baby steps into Kotlin
import kotlin.browser.document
import kotlin.browser.window
// Type definitions
native("Cycle")
val Cycle : dynamic = noImpl
native("Cycle.h")
fun h(tagName: String) : VTree = noImpl
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
staltz / how.md
Last active October 26, 2017 17:53
How to debug Mocha tests written in Babel, running only in Node.js

Run this in one shell

./node_modules/.bin/mocha --debug-brk --compilers js:babel-register test/node

Then this in another shell

node-inspector

Then open the browser