Skip to content

Instantly share code, notes, and snippets.

View federicofazzeri's full-sized avatar

Federico Fazzeri federicofazzeri

  • canada
View GitHub Profile
@federicofazzeri
federicofazzeri / angular.aria-live.js
Last active February 21, 2017 14:58
aria-live-announcements an angular service for running aria live announcements Take a look at example.html for an example of how to use it in a directive
(function(window, angular) {
'use strict';
/**
*
* The `ariaLive` module provides a service for running aria live announcements.
* It creates an empty paragraph only "visible" to screen readers.
*
*/
@federicofazzeri
federicofazzeri / list-filter.factory.js
Created February 24, 2017 18:38
Simple list filter without "bothering" angular $scope
(function(window, angular) {
'use strict';
/**
* Simple list filter without "bothering" angular $scope
* I used OLOO as a OO Js style (instead of the classic prototypal inheritance)
*/
var listFilter = angular.module('listFilter', []);
@federicofazzeri
federicofazzeri / controls.js
Created February 24, 2017 18:44
Drag and drop bouncing ball in RxJs
(function(Observable, eleId, dom) {
var ball = dom.getElementById(eleId),
mouseOverBall = Observable.fromEvent(ball, 'mousedown'),
mouseUp = Observable.fromEvent(dom, "mouseup"),
dragBall = Observable.fromEvent(dom, 'mousemove'),
resize = Observable.fromEvent(window, 'resize'),
stylesheet = dom.styleSheets[0],
baseY = ((css) => {
try {
@federicofazzeri
federicofazzeri / composer.factory.js
Created February 24, 2017 18:47
A simple Angular service for function composition
(function(window, angular) {
'use strict';
/****
* Simple composition factory for Angular 1x
*****/
var composer = angular.module('composerModule', []);
composer.factory('Composer', Composer);
@federicofazzeri
federicofazzeri / Gruntfile.js
Created February 24, 2017 18:50
A Grunt task with no dependencies to serve static files (optionally set port and staticBasePath: server: { port: 3300, staticBasePath: './build' })
module.exports = function(grunt) {
var config = {
watch: {},
server: {}
};
grunt.initConfig(config);
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadTasks('tasks');
grunt.registerTask('default', ['server', 'watch']);
};
@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

@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 / 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 / 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 / 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.