Skip to content

Instantly share code, notes, and snippets.

Avatar
👋

Maximilian Hoffmann maxhoffmann

👋
View GitHub Profile
@maxhoffmann
maxhoffmann / index.js
Last active May 26, 2016
requirebin sketch
View index.js
const most = require('most');
const stream = most.just(Array(170000));
const dest = [];
stream.forEach(bigArray =>
dest.push.apply(dest, bigArray)
);
@maxhoffmann
maxhoffmann / index.js
Created Apr 26, 2016
requirebin sketch
View index.js
var most = require('most');
const init = most.fromEvent('click', window)
.scan(function(last) { return !last }, false);
init
.filter(Boolean)
.flatMap(function() {
return most.create(function(add, end, error) {
@maxhoffmann
maxhoffmann / index.js
Created Apr 26, 2016
requirebin sketch
View index.js
var most = require('most');
const init = most.fromEvent('click', window)
.scan(function(last) { return !last }, false);
init
.filter(Boolean)
.flatMap(function() {
return most.create(function(add, end, error) {
@maxhoffmann
maxhoffmann / index.js
Last active Mar 14, 2016
requirebin sketch
View index.js
var most = require('most');
const root = most.just(true).multicast(); // remove multicast and stream 1 doesn’t throw
// STREAM 1 (listens to root)
root
.forEach(function(value) {
document.body.innerHTML += 'first: ' + value + '<br>';
})
@maxhoffmann
maxhoffmann / index.js
Created Mar 10, 2016
requirebin sketch
View index.js
var most = require('most');
var visibility = most.fromEvent('visibilitychange', document)
.map(function() { return !document.hidden; })
.startWith(!document.hidden)
.multicast(); // removing this will fix sampleWith
visibility
.forEach(function(value) {
document.body.innerHTML += 'first stream: ' + value + '<br>';
@maxhoffmann
maxhoffmann / index.js
Last active Mar 1, 2016
requirebin sketch
View index.js
var most = require('most');
var stream = most.just(1);
var promise = Promise.resolve(2);
var sampledStream = most.just(3);
// works when promise(s) come first
stream
.sample(function() { return [].slice.call(arguments); }, most.fromPromise(promise), sampledStream)
.forEach(function(value) {
@maxhoffmann
maxhoffmann / index.js
Last active Feb 24, 2016
requirebin sketch
View index.js
var most = require('most');
var clicks = most.fromEvent('click', document)
.map(function() { return 'click' })
.debounce(200)
.startWith('init')
.sampleWith(most.periodic(1000));
clicks.forEach(function(value) { document.body.innerHTML += value + '<br>'});
View jsbin.pevaw.css
.scrollable {
overflow: auto;
}
.scrollableWrapper {
position: relative;
}
.scrollableWrapper:before {
content: '';
position: absolute;
top: 0;
View fullText.js
function fullText() {
var elements = [].slice.call(document.querySelectorAll('[data-full-text]'));
elements.forEach(function(element) {
var REGEX_NUMBER = /\d+/;
var REGEX_NO_NUMBER = /[^\d]+/;
element.style.display = "inline";
element.style.fontSize = '';
var width = element.getBoundingClientRect().width;
var containerWidth = element.parentNode.getBoundingClientRect().width;
var fontSize = getComputedStyle(element).fontSize;
@maxhoffmann
maxhoffmann / gist:7373563
Last active Dec 27, 2015
run local php server and open browser
View gist:7373563
# local PHP Server
server() {
url="localhost:${2:-8000}"
if [ -z "$1" ]; then
php -S $url & # run server in background
else
php -S $url -t $1 &
fi
sleep 0.3s # wait for server to start