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
@GianlucaGuarini
GianlucaGuarini / local-storage.js
Last active May 2, 2017 11:59
A simple script to deal safely with the localStorage
/**
* Deal with the localStorage avoiding odd issues due to paranoids that have disabled it by default
*/
const ls = window.localStorage
/**
* Call any method on the localStorage avoiding to throw errors
* @param {string} method - method we want to call
* @param {array} args - serialized params that will be proxied to the method we are going to call
* @returns {null|string} whatever the method call will return
@GianlucaGuarini
GianlucaGuarini / main.tag
Last active March 1, 2018 21:11
Simple example to demonstarte how to use es2015 imports with the default riot cli. Install riot via `npm i riot -g` and then run `npm run build`
<main-tag>
<h1>I got the power!</h1>
<h2>The answer is { answer }</h2>
<script>
import something from './something'
this.answer = something.answer
</script>
</main-tag>
@GianlucaGuarini
GianlucaGuarini / data.json
Last active May 2, 2017 12:00
Cache a whole SPA website and its assets via app cache, service workers and localstorage
{
"secret-message": "hello"
}
@GianlucaGuarini
GianlucaGuarini / read-cookie.js
Last active December 12, 2016 14:37
Simple function to read a named cookie from the document.cookie string
@GianlucaGuarini
GianlucaGuarini / a.js
Last active April 18, 2019 14:17
Use always `module.exports = Object.freeze({})`
const b = require('./b')
b.b = 'c'
module.exports = {
a: 'a'
}
//** Dependencies **//
const path = require('path');
const webpack = require('webpack');
//** Options **//
const paths = require('./paths.js').paths;
const envUtil = require('../util/env');
<cool>
<p>Hi { message() }</p>
<script>
message() {
return 'there'
}
</script>
<style type="postcss" scoped>
<bar>
<p>bar</p>
</bar>
@GianlucaGuarini
GianlucaGuarini / promisify-everything.js
Last active July 25, 2016 06:19
Simple script to promisify the API of any javascript Object - It's an experiment don't use it in production!!!!
Object.defineProperty(Object.prototype, 'promise', {
get: function() {
return new Proxy({}, {
get: (target, name) => {
return new Promise((resolve) => {
this[name] = resolve
})
}
})
},