Skip to content

Instantly share code, notes, and snippets.

Nicolas Carlo nicoespeon

Block or report user

Report or block nicoespeon

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@nicoespeon
nicoespeon / observables-fourth-shot.js
Last active Mar 23, 2017
Blog - Using Observables to make our app work with barcode scanners
View observables-fourth-shot.js
const ENTER_KEY_CODE = 13
const MAX_INTERVAL_BETWEEN_EVENTS_IN_MS = 50
const keyCode$ = Rx.Observable.fromEvent(document, "keypress")
.pluck('keyCode')
const keyCodesBuffer$ = keyCode$
.buffer(keyCode$.debounce(MAX_INTERVAL_BETWEEN_EVENTS_IN_MS))
.filter(isFromScan)
@nicoespeon
nicoespeon / observables-third-shot.js
Last active Mar 23, 2017
Blog - Using Observables to make our app work with barcode scanners
View observables-third-shot.js
const ENTER_KEY_CODE = 13
const MAX_INTERVAL_BETWEEN_EVENTS_IN_MS = 50
const keyCode$ = Rx.Observable.fromEvent(document, "keypress")
.pluck('keyCode')
const keyCodesBuffer$ = keyCode$
.buffer(keyCode$.debounce(MAX_INTERVAL_BETWEEN_EVENTS_IN_MS))
.filter(isFromScan)
@nicoespeon
nicoespeon / observables-second-shot.js
Last active Mar 23, 2017
Blog - Using Observables to make our app work with barcode scanners
View observables-second-shot.js
const MAX_INTERVAL_BETWEEN_EVENTS_IN_MS = 50
const keyCode$ = Rx.Observable.fromEvent(document, "keypress")
.pluck('keyCode')
const keyCodesBuffer$ = keyCode$
// --(43)-(64)----(32)-----(65)-(77)-(13)--->
.buffer(keyCode$.debounce(MAX_INTERVAL_BETWEEN_EVENTS_IN_MS))
// --([43,64])----([32])-----([65,77,13])--->
@nicoespeon
nicoespeon / observables-first-shot.js
Last active Mar 22, 2017
Blog - Using Observables to make our app work with barcode scanners
View observables-first-shot.js
const keyCode$ = Rx.Observable.fromEvent(document, "keypress")
// ---(ev)--(ev)--------(ev)--->
.pluck('keyCode')
// ---(43)--(51)--------(13)--->
@nicoespeon
nicoespeon / imperative-third-shot.js
Created Mar 21, 2017
Blog - Using Observables to make our app work with barcode scanners
View imperative-third-shot.js
const ENTER_KEY_CODE = 13
const MAX_INTERVAL_BETWEEN_EVENTS_IN_MS = 50
let keyCodesBuffer = []
let cleanBufferTimeout
document.addEventListener("keypress", (event) => {
const keyCode = event.keyCode
stopCleanBufferTimeout()
if(keyCode === ENTER_KEY_CODE) {
@nicoespeon
nicoespeon / imperative-second-shot.js
Last active Mar 21, 2017
Blog - Using Observables to make our app work with barcode scanners
View imperative-second-shot.js
const ENTER_KEY_CODE = 13
const MAX_INTERVAL_BETWEEN_EVENTS_IN_MS = 50
let keyCodesBuffer = []
document.addEventListener("keypress", (event) => {
const keyCode = event.keyCode
if(keyCode === ENTER_KEY_CODE) {
fillInputWithKeyCodesBuffer()
cleanBuffer()
@nicoespeon
nicoespeon / imperative-first-shot.js
Last active Mar 21, 2017
Blog - Using Observables to make our app work with barcode scanners
View imperative-first-shot.js
const ENTER_KEY_CODE = 13
let keyCodesBuffer = []
document.addEventListener("keypress", (event) => {
const keyCode = event.keyCode
if(keyCode === ENTER_KEY_CODE) {
fillInputWithKeyCodesBuffer()
cleanBuffer()
} else {
@nicoespeon
nicoespeon / withLatestFrom-marble.txt
Created Jul 19, 2016
Blog - How I implemented a download button with Cycle.js - Marble diagram of withLatestFrom() operator
View withLatestFrom-marble.txt
downloadClicks$: -------x------x----------------x---------->
csvData$: ---A---------------B----C--D-------E------>
withLatestFrom((clicks, data) => data)
downloadData$: -------A------A----------------D---------->
@nicoespeon
nicoespeon / ExportToCsv.js
Last active Dec 4, 2016
Blog - How I implemented a download button with Cycle.js - ExportToCsv driver
View ExportToCsv.js
import R from 'ramda';
// Export a driver to be used in our Cycle.js app.
// It takes an `input$` stream that contains `data` to be download.
function exportToCSVDriver(input$) {
// `data` should be formatted as an Array of Arrays (= lines of CSV).
// -> `[["name1", "city1", "other info"], ["name2", "city2", "more info"]]`
input$.subscribe((data) => {
// Parse data to create a CSV file.
// See: http://stackoverflow.com/questions/14964035/how-to-export-javascript-array-info-to-csv-on-client-side
@nicoespeon
nicoespeon / lead-time-lodash-refactored.js
Last active Apr 14, 2016
Blog - Achieving point-free JavaScript - lodash refactored
View lead-time-lodash-refactored.js
import {pipe, pluck, over, head, last, spread} from 'lodash/fp';
import {daysSpent} from './utils/dates';
// leadTime : [{date: Date}] -> Number
const leadTime = pipe(
pluck( 'date' ), // first convert input into [Date]
over( [ head, last ] ), // then turns them to our arguments array [ FirstDate, LastDate ]
spread( daysSpent ) // finally spread arguments to the function
);
You can’t perform that action at this time.