Skip to content

Instantly share code, notes, and snippets.

View federicofazzeri's full-sized avatar

Federico Fazzeri federicofazzeri

  • canada
View GitHub Profile
@federicofazzeri
federicofazzeri / main.dart
Last active December 5, 2019 18:47
Flutter reactive UI without class based widgets (...but don't do this)
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
MyAppModel myAppModel = MyAppModel();
myAppModel.addListener(() => runApp(myApp(myAppModel)));
myAppModel.updateUI(1);
}
@federicofazzeri
federicofazzeri / main.dart
Last active December 5, 2019 15:14
Flutter simple circle canvas animation (DartPad link https://dartpad.dev/905d84f36ebd0ee4b9bab2552564bf44)
import 'package:flutter/material.dart';
import 'dart:math';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@federicofazzeri
federicofazzeri / .babelrc
Last active February 7, 2022 14:45
Node Express-based REST API (CRUD) using Firebase cloud Functions and FireStore cloud database + Babel config (The current Node version running in Cloud Functions is 6.10)
{
"presets": [
["env", {
"targets": {
"node": "6.10"
}
}]
]
}
@federicofazzeri
federicofazzeri / app.js
Last active November 2, 2017 14:41
Workbox setup to alert your users that a new version of your PWA is available on their device
function checkForNewVersions() {
if( ! 'BroadcastChannel' in window) return;
const assetsUpdates = new BroadcastChannel('precache-updates');
const dataUpdates = new BroadcastChannel('data-updates');
assetsUpdates.addEventListener('message', (event) => {
/*alert the user to reload the page to get the new app version*/
});
dataUpdates.addEventListener('message', (event) => {
/*alert the user to reload the page to get the new app data*/
});
@federicofazzeri
federicofazzeri / app.js
Last active October 16, 2017 16:07
Service worker setup for a PWA that shows cached data and replace it with fresh network data when available. If network data comes first, the view won't be updated with the old cached data. Cache/network data flows are managed with observables.
const dataUrl = ''; //your data api url
(function(dataUrl, Observable) {
'use strict';
/******** your impure functions: ***********/
//bind data to the view here
@federicofazzeri
federicofazzeri / README.md
Last active October 6, 2017 16:25
Component based SPA with dependency injection, redux state management, code splitting and tree shaking WITHOUT using a framework

Redux - component based - SPA with dependency injection WITHOUT using frameworks.

The app is built entirely with browsers native Web Components (Custom Elements, Shadow DOM, HTML Imports and HTML Template)

The app works in older browsers thank to the web component polyfill loader that dynamically loads the necessary polyfills using features detection.

webpack.config.js builds the app using a custom template (app.template.html) where the root component is set, the components templates are imported (components-templates.html) and the Polyfills detector is loaded.

index.js is the app entry script, it waits until the necessary polyfills are loaded then instantiates the dependencies and bootstrap the app.

@federicofazzeri
federicofazzeri / transducer.js
Last active September 27, 2017 18:44
List transformations chaining maps can be optimized with a transducer, here an example in plain Javascript
var test = require('tape');
const double = n => n*2;
const addOne = n => n+1;
const excludeTen = n => n !== 10;
const listPush = (list, v) => {
list.push(v);
return list;
}
const mapReducer = mapFn =>
@federicofazzeri
federicofazzeri / directories-crawler.js
Last active September 18, 2017 15:05
async/await + recursion = concise and highly expressive async code
/*
Crawl a directory and return a list containing all subdirectories paths
*/
const fs = require('fs-extra');
const { promisify } = require('util');
const { resolve } = require('path');
const EventEmitter = require('events');
const isDir = folder => fs.lstatSync( folder ).isDirectory();
@federicofazzeri
federicofazzeri / swipe-event.directive.ts
Last active March 4, 2021 18:20
Angular 2 state-less directive to add cross device left/right swipe gesture to a UI list
import { Directive, HostListener, ElementRef, Output, Input, EventEmitter, AfterContentInit } from '@angular/core';
import { Observable } from 'rxjs/Rx'
import 'rxjs/add/observable/fromEvent';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/filter';
import 'rxjs/add/operator/takeUntil';
import 'rxjs/add/operator/concatMap';
import { Subject } from 'rxjs/Subject';
@Directive({
@federicofazzeri
federicofazzeri / README.md
Last active March 20, 2017 20:21
Angular2 app that saves data on an any in-browser database (thanks to PouchDb) and syncs it with a remote couchDb as soon as the connection is restored

Angular2 app that saves data on an any in-browser database (thanks to PouchDb) and syncs it with a remote couchDb as soon as the connection is restored

1 - Install pouchdb and pouchdb types

npm install pouchdb --save
npm install @types/pouchdb --save --save-exact

2 - fix CORS issues