Skip to content

Instantly share code, notes, and snippets.

View thcolin's full-sized avatar

Thomas Colin thcolin

View GitHub Profile
{"lastUpload":"2020-08-10T12:50:56.755Z","extensionVersion":"v3.4.3"}

Keybase proof

I hereby claim:

  • I am thcolin on github.
  • I am thcolin (https://keybase.io/thcolin) on keybase.
  • I have a public key ASCbLDHXuxXB_B5j7DpT3CgPvzT8L5qbvRZt16-mWcgmXwo

To claim this, I am signing this object:

@thcolin
thcolin / index.js
Last active March 29, 2018 21:34
🦖 Duno - First attempt to create an Immutable lib with easy API
function duno(root, diff, index) {
let dunoed = Object.assign({}, root)
for (let key in diff) {
switch (typeof diff[key]) {
case 'function':
dunoed[key] = diff[key](dunoed[key], dunoed)
break
default:
dunoed[key] = diff[key]
@thcolin
thcolin / index.js
Last active November 3, 2017 23:29
Min delay between values in rxjs
import Rx from 'rxjs/Rx'
function delayBetween(delay, first = false){
let past = Date.now()
return this.mergeMap((next, index) => {
const present = Date.now()
const futur = Math.max(past + (index === 0 && !first ? 0 : delay), present)
past = futur
return Rx.Observable.of(next).delay(futur - present)
@thcolin
thcolin / index.js
Created September 11, 2017 14:08
Recursive Promise delayed
var promise = Promise.resolve()
var values = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
values.forEach(function(id) {
promise = promise.then(function() {
return new Promise(function(resolve, reject) {
setTimeout(function() {
resolve(id)
}, 2000)
})
@thcolin
thcolin / SCHEMA.md
Last active August 23, 2017 12:40
Reflections about virutal list (or scroll)
          ┌───────────────┐     ┌─────────────┐      ┌─────────────┐      ┌─────────────┐
          │ ┌───────────┐ │     │┌───────────┐│      │┌───────────┐│      │┌───────────┐│
          │ │     0     │ │     ││     0     ││      ││     0     ││      ││     1     ││
          │ └───────────┘ │     │└───────────┘│      │└───────────┘│      │└───────────┘│
 viewport │               │     ├─────────────┤      ├─────────────┤      ├─────────────┤
          │ ┌───────────┐ │     │┌───────────┐│      │┌───────────┐│      │┌───────────┐│
          │ │     1     │ │     ││     1     ││      ││     1     ││      ││     2     ││
          │ └───────────┘ │     │└───────────┘│      │└───────────┘│      │└───────────┘│
          └┬─────────────┬┘    ┌┴─────────────┴┐     ├─────────────┤     ┌┴─────────────┴┐
@thcolin
thcolin / index.js
Last active April 19, 2017 09:22
RxJS 5 pausableBuffered
// Inspired from : [RxJS 5 pausableBuffered operation declaration](http://codepen.io/elhigu/pen/jqZmpV)
// Simplified (but loosing in readability) and improved by sending final buffer on source$.complete with flusher$.next(1)
import Rx from 'rxjs/Rx'
function pausableBuffered(pauser$) {
return Rx.Observable.create(subscriber$ => {
var source$ = this
var buffer$ = new Rx.Subject()
var flusher$ = new Rx.Subject()
@thcolin
thcolin / index.js
Created April 14, 2017 13:00
RxJS pauseable
import Rx from 'rxjs/Rx';
var pauser = new Rx.Subject();
var source = Rx.Observable.interval(1000);
var pauseable = pauser.switchMap(paused => paused ? Rx.Observable.never() : source);
pauseable.subscribe(n => console.log('next', n), e => console.log('error', e), c => console.log('complete', c));
pauser.next(false);
@thcolin
thcolin / index.js
Created March 26, 2017 15:17
Javascript deep array merge and map exercise
var e = {
itag: ['a', 'b'],
s: ['a', 'b'],
url: ['a', 'b']
}
var f = {
itag: ['c', 'd'],
s: 's',
url: ['c', 'd']