Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View nicoespeon's full-sized avatar

Nicolas Carlo nicoespeon

View GitHub Profile
@nicoespeon
nicoespeon / imperative-second-shot.js
Last active March 21, 2017 08:38
Blog - Using Observables to make our app work with barcode scanners
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-third-shot.js
Created March 21, 2017 08:38
Blog - Using Observables to make our app work with barcode scanners
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 / ExportToCsv.js
Last active December 4, 2016 16:03
Blog - How I implemented a download button with Cycle.js - ExportToCsv driver
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 / withLatestFrom-marble.txt
Created July 19, 2016 07:24
Blog - How I implemented a download button with Cycle.js - Marble diagram of withLatestFrom() operator
downloadClicks$: -------x------x----------------x---------->
csvData$: ---A---------------B----C--D-------E------>
withLatestFrom((clicks, data) => data)
downloadData$: -------A------A----------------D---------->
@nicoespeon
nicoespeon / lead-time-lodash-refactored.js
Last active April 14, 2016 09:19
Blog - Achieving point-free JavaScript - lodash refactored
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
);
@nicoespeon
nicoespeon / lead-time-naive.js
Last active April 12, 2016 21:08
Blog - Achieving point-free JavaScript - naive solution
import {pipe, prop, head, last} from 'ramda';
import {daysSpent} from './utils/dates';
// leadTime : [{date: Date}] -> Number
const leadTime = (items) => daysSpent(
pipe( head, prop('date') )(items),
pipe( last, prop('date') )(items)
);
@nicoespeon
nicoespeon / lead-time-ramda.js
Last active April 12, 2016 21:07
Blog - Achieving point-free JavaScript - ramda
import {converge, pipe, prop, head, last} from 'ramda';
import {daysSpent} from './utils/dates';
// leadTime : [{date: Date}] -> Number
const leadTime = converge(
daysSpent,
[ pipe( head, prop('date') ), pipe( last, prop('date') ) ]
);
@nicoespeon
nicoespeon / lead-time-ramda-refactored.js
Last active April 12, 2016 21:06
Blog - Achieving point-free JavaScript - ramda refactored
import {pipe, pluck, converge, head, last} from 'ramda';
import {daysSpent} from './utils/dates';
// leadTime : [{date: Date}] -> Number
const leadTime = pipe(
pluck('date'), // first convert input into [Date]
converge( daysSpent, [ head, last ] ) // then pick proper ones for calculation
);
@nicoespeon
nicoespeon / achieving-point-free.js
Created April 11, 2016 22:00
Blog - Achieving point-free JavaScript - achieving point-free
// What I ended up with
const getX = ( input ) => getY( parseA( input ), parseB( input ) );
// What I was trying to achieve, some sort of:
const getX = anyFunction( getY( parseA, parseB ) );
@nicoespeon
nicoespeon / dates.json
Last active April 11, 2016 21:39
Blog - Achieving point-free JavaScript - dates
[
{ "list": "Backlog", "date": "2016-04-01" },
{ "list": "Card Preparation [2]", "date": "2016-04-01" },
{ "list": "Production [3]", "date": "2016-04-02" },
{ "list": "Tests QA [2]", "date": "2016-04-05" },
{ "list": "Mise en live [1]", "date": "2016-04-05" },
{ "list": "In Production", "date": "2016-04-06" },
{ "list": "Live (April 2016)", "date": "2016-04-08" }
]