Skip to content

Instantly share code, notes, and snippets.

View kaosat-dev's full-sized avatar

Mark Moissette kaosat-dev

View GitHub Profile
@kaosat-dev
kaosat-dev / svg-to-png.js
Created October 29, 2016 09:25 — forked from caged/svg-to-png.js
Convert SVG's to PNGs. This works OK if the SVG's styles are inline. The SVG element must contain an xmlns attribute. Webkit also requires you specify a font size on `text` elements.
var svg = document.getElementById('graph'),
xml = new XMLSerializer().serializeToString(svg),
data = "data:image/svg+xml;base64," + btoa(xml),
img = new Image()
img.setAttribute('src', data)
document.body.appendChild(img)
@kaosat-dev
kaosat-dev / limitFlow.js
Created October 17, 2016 19:44 — forked from axefrog/limitFlow.js
Flow control limiter for most.js. Unlike `throttle`, which drops events indiscriminately, `limitFlow` retains the most recent event and ensures that it is emitted when the specified period elapses.
// Limit the rate of flow to an event every 250ms:
// const stream$ = other$.thru(limitFlow(250));
export function limitFlow(period) {
return function limitFlow(stream) {
const source = new RateLimitSource(stream.source, period);
return new stream.constructor(source);
};
}
@kaosat-dev
kaosat-dev / main.js
Created March 6, 2016 09:43 — forked from staltz/main.js
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)
@kaosat-dev
kaosat-dev / listening-client.js
Created February 21, 2016 09:53 — forked from johnnyman727/listening-client.js
Simple MQTT Server. Tessel acts as an MQTT client sending temperature data to a host
var mqtt = require('mqtt')
// Make sure to change this to the IP address of your MQTT server
, host = '192.168.128.204' // or localhost
client = mqtt.createClient(1883, host, {keepalive: 10000});
// Subscribe to the temperature topic
client.subscribe('temperature');
// When a temperature is published, it will show up here
client.on('message', function (topic, message) {

Folder Structure

Motivations

  • Clear feature ownership
  • Module usage predictibility (refactoring, maintainence, you know what's shared, what's not, prevents accidental regressions, avoids huge directories of not-actually-reusable modules, etc)
@kaosat-dev
kaosat-dev / gridstyle.css
Created January 1, 2016 07:51 — forked from buzzdecafe/gridstyle.css
sudoku solver
#grid {
border: 1px solid #000;
border-spacing:0;
}
#grid tr:nth-child(3) td,
#grid tr:nth-child(6) td {
border-bottom: 1px solid #000;
}
@kaosat-dev
kaosat-dev / 0-ouroboros.js
Created December 10, 2015 11:30 — forked from benjyhirsch/0-description.md
Inspired by Cycle.js and Motorcycle.js
/*****************************************************************************
This is the function doing all the heavy lifting.
It takes a function and returns a stream generated by feeding its output
back into itself as input. (It doesn't start consuming the stream.)
It's basically a pared-down version of Cycle.run that forgets about the
application architecture of separating out a pure main from the effectful
drivers and just resolves a single circularly dependent stream. The other
files just build up more API-compatible versions of Cycle.run from this.
@kaosat-dev
kaosat-dev / README.md
Created December 7, 2015 11:04 — forked from bsergean/README.md
offscreen rendering with three.js and headless-gl, in coffee-script

Getting the code

mkdir -p $HOME/src/offscreen_sample # or anywhere you'd like
cd $HOME/src/offscreen_sample
cp package.json and offscree_sample.coffee in here

Executing the code

$ npm install # maybe npm start will take care of it but just in case

$ npm start && open out.png

@kaosat-dev
kaosat-dev / introrx.md
Last active August 29, 2015 14:23 — forked from staltz/introrx.md

The introduction to Reactive Programming you've been missing

(by @andrestaltz)

So you're curious in learning this new thing called Reactive Programming, particularly its variant comprising of Rx, Bacon.js, RAC, and others.

Learning it is hard, even harder by the lack of good material. When I started, I tried looking for tutorials. I found only a handful of practical guides, but they just scratched the surface and never tackled the challenge of building the whole architecture around it. Library documentations often don't help when you're trying to understand some function. I mean, honestly, look at this:

Rx.Observable.prototype.flatMapLatest(selector, [thisArg])

Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.

// ES7 Observables + WHATWG Streams
//
// https://github.com/jhusain/asyncgenerator
// https://github.com/whatwg/streams
//
// Continuation from file:
// https://github.com/jhusain/asyncgenerator/blob/master/src/observable.js
Observable.fromStream = function(readable) {
return new Observable(function(generator) {