Skip to content

Instantly share code, notes, and snippets.

View fgandellini's full-sized avatar
🏠
Working from home

Federico Gandellini fgandellini

🏠
Working from home
View GitHub Profile
@fgandellini
fgandellini / machine.js
Last active January 27, 2020 08:53
Generated by XState Viz: https://xstate.js.org/viz
const portCallMachine = Machine({
id: 'port-call',
initial: 'settled',
states: {
hovered: {
on :{
MOUSE_LEAVE: 'settled.hist',
ITEM_SELECTED: 'selected',
MOUSE_CLICK: 'selected',
},
@fgandellini
fgandellini / machine.js
Last active January 24, 2020 15:34
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@fgandellini
fgandellini / machine.js
Last active December 3, 2019 09:17
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@fgandellini
fgandellini / restore-dotfiles.sh
Last active March 3, 2019 16:53
Script needed to restore dotfiles from https://github.com/fgandellini/dotfiles
#!/bin/sh
git clone --bare https://github.com/fgandellini/dotfiles $HOME/.dotfiles
function dotfiles {
/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME $@
}
mkdir -p .dotfiles-backup
dotfiles checkout
@fgandellini
fgandellini / index.js
Created December 11, 2017 08:31
refactoring-video-store-js
const arraySum = prop => arr =>
arr.reduce((acc, r) => acc + r[prop], 0)
const amountByCode = r => ({
'regular': 2 + (r.days > 2 ? ((r.days - 2) * 1.5) : 0),
'new': r.days * 3,
'childrens': 1.5 + (r.days > 3 ? ((r.days - 3) * 1.5) : 0),
})
const frequentRenterPointsByCode = r => ({
@fgandellini
fgandellini / keybase.md
Created November 21, 2017 09:25
keybase.md

Keybase proof

I hereby claim:

  • I am fgandellini on github.
  • I am gandellinux (https://keybase.io/gandellinux) on keybase.
  • I have a public key ASBIWg54AEvksRABPByq5AAZkFuaVd-iCJiStBnkLwN0lgo

To claim this, I am signing this object:

@fgandellini
fgandellini / streams.js
Created September 12, 2016 15:44
streams everywhere!
const Rx = require('rxjs/Rx')
const getB = (a, cb) => setTimeout(a => cb(null, a+'b'), 10000)
const getbAsObservable = Rx.Observable.bindNodeCallback(getB)
const a$ = Rx.Observable.from([1, 2, 3])
const b$ = a$.map(a => getbAsObservable(a))
const c$ = a$.zip(b$.mergeAll())
c$.subscribe(data => console.log(data))
@fgandellini
fgandellini / cycle-pouchdb.js
Created September 5, 2016 10:15
Cycle.js PouchDB driver (WIP)
import xs from 'xstream'
import XStreamAdapter from '@cycle/xstream-adapter'
export function makePouchDBDriver(PouchDB, dbName, dbOptions) {
PouchDB.plugin(require('relational-pouch'))
const db = new PouchDB(dbName, dbOptions)
const api = ['put', 'get', 'allDocs' , 'destroy', 'setSchema', 'rel.save', 'rel.find', 'rel.del']
return (sinks, streamAdapter) =>
var url = require('url');
var request = require('superagent');
var debug = require('debug')('url-utils');
function parse(link) {
return new Promise(function(resolve, reject) {
try {
var parsedUrl = url.parse(link, true, true);
if (isValid(parsedUrl)) {
return isAvailable(parsedUrl)
@fgandellini
fgandellini / check.js
Last active August 29, 2015 14:25
check link
function check(link) {
var errorMessage = 'Mumble mumble... this seems to be an invalid link! :(';
return new Promise(function(resolve, reject) {
try {
http.request(link, function(res) {
debug('link status is ', res.statusCode);
if (res.statusCode !== 404) {
resolve(link);
} else {
reject(errorMessage);