Skip to content

Instantly share code, notes, and snippets.

View GianlucaGuarini's full-sized avatar
🎸
Rocking the world with few lines of code

Gianluca Guarini GianlucaGuarini

🎸
Rocking the world with few lines of code
View GitHub Profile
name: Main
on:
schedule:
- cron: 30 12 * * *
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Setup node
@GianlucaGuarini
GianlucaGuarini / login.js
Created January 8, 2020 21:10
programming like a modern artist
;(async function() {
// puppeteer boilerplate code
const browser = await puppeteer.launch({
args: ['--no-sandbox', '--disable-setuid-sandbox'],
// notice the small device size
defaultViewport: {
width: 375,
height: 812
}
@GianlucaGuarini
GianlucaGuarini / riot+compiler.js
Created June 29, 2019 17:43
Riot.js 4 + compiler polyfilled for IE11 - This code is only for demo purpose!!!
This file has been truncated, but you can view the full file.
function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__pr
:root {
@import '@design-system/colors.json';
--root-colors--primary: #{$primary};
--root-colors--secondary: #{$secondary};
}
@GianlucaGuarini
GianlucaGuarini / wait.js
Last active January 19, 2018 10:41
Functional advanced async (cancellable/abortable) `setTimeout` helper
/**
* Advanced async (cancellable/abortable) `setTimeout` helper
*/
function wait(delay) {
return (val) => {
let timer
let abort
const p = new Promise(function(resolve, reject) {
abort = reject
@GianlucaGuarini
GianlucaGuarini / curry.js
Last active November 18, 2017 21:55
Function to curry any javascript method
/**
* Function to curry any javascript method
* @param {Function} fn - the target function we want to curry
* @param {...[args]} acc - initial arguments
* @returns {Function|*} it will return a function until the target function
* will receive all its arguments
*/
function curry(fn, ...acc) {
return (...args) => {
args = [...acc, ...args]
@GianlucaGuarini
GianlucaGuarini / accessible-overlays.js
Last active November 1, 2017 10:57
Simple function to make your overlays element accessible
// forked by a script of https://github.com/nilssolanki
import { add } from 'bianco.events'
/**
* A list of all the open overlays, tooltips, sidebars etc.
* @type {Map}
*/
const openOverlays = new Map()
/**
@GianlucaGuarini
GianlucaGuarini / real-device-px-ratio.js
Created October 9, 2017 12:48
Because devicePixelRatio is not relyable enough
const resolutions = [
'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=',
'data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAA=',
'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==',
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVQYV2P4DwABAQEAWk1v8QAAAABJRU5ErkJggg==',
];
const img = document.createElement('img');
img.src = resolutions[0];
img.srcset = resolutions.map((itm, i) => `${itm} ${i + 1}x`).join(',');
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"riot": "^3.4.2"
},
"devDependencies": {
"coffee-script": "^1.12.5",
@GianlucaGuarini
GianlucaGuarini / promise-sequence.js
Created May 5, 2017 15:08
Run promises as sequence
function sequence(promises) {
return new Promise((resolve, reject) => {
const rets = []
const gen = (function*() {
// loop as long as we have promises in the queue
while (promises.length) {
// take always the first promise
const promise = promises.shift()
// wait until it's resolved to step to the next iteration
promise