Skip to content

Instantly share code, notes, and snippets.

View robertoentringer's full-sized avatar
🖥️
Working from home

Roberto Entringer robertoentringer

🖥️
Working from home
View GitHub Profile
@robertoentringer
robertoentringer / web-servers.md
Created April 13, 2018 02:08 — forked from willurd/web-servers.md
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@robertoentringer
robertoentringer / README.md
Created April 13, 2018 15:09 — forked from hofmannsven/README.md
My simply Git Cheatsheet
@robertoentringer
robertoentringer / package.json
Created April 16, 2018 14:19 — forked from addyosmani/package.json
npm run-scripts boilerplate
{
"name": "my-app",
"version": "1.0.0",
"description": "My test app",
"main": "src/js/index.js",
"scripts": {
"jshint:dist": "jshint src/js/*.js",
"jshint": "npm run jshint:dist",
"jscs": "jscs src/*.js",
"browserify": "browserify -s Validating -o ./dist/js/build.js ./lib/index.js",
@robertoentringer
robertoentringer / shuffle.js
Created May 30, 2018 10:33 — forked from guilhermepontes/shuffle.js
Shuffle array element ES2015, ES6
// original gist
const shuffleArray = arr => arr.sort(() => Math.random() - 0.5);
// fully random by @BetonMAN
const shuffleArray = arr => (
arr
.map(a => [Math.random(), a])
.sort((a, b) => a[0] - b[0])
.map(a => a[1]);
);
@robertoentringer
robertoentringer / dnsmasq OS X.md
Created November 24, 2018 11:11 — forked from ogrrd/dnsmasq OS X.md
Setup dnsmasq on OS X

Never touch your local /etc/hosts file in OS X again

To setup your computer to work with *.dev domains, e.g. project.dev, awesome.dev and so on, without having to add to your hosts file each time.

Requirements

Install

@robertoentringer
robertoentringer / sw.js
Created February 4, 2019 09:29 — forked from ireade/sw.js
Handle broken images with the service worker
self.addEventListener('install', (e) => {
e.waitUntil(
caches.open("precache").then((cache) => cache.add("/broken.png"))
);
});
function isImage(fetchRequest) {
return fetchRequest.method === "GET" && fetchRequest.destination === "image";
}
@robertoentringer
robertoentringer / Array.move.js
Created February 13, 2019 21:39
JavaScript Array move
// Append a move method to the Array prototype
Array.prototype.move = function(from, to) {
this.splice(to, 0, this.splice(from, 1)[0]);
return this;
};
// Start with an existing array
var orig = ["Sam", "Tom", "Ben", "Sophie"];
// Use the new method to move the last item in the array to the first position
@robertoentringer
robertoentringer / download-file.js
Created March 1, 2019 16:54 — forked from javilobo8/download-file.js
Download files with AJAX (axios)
axios({
url: 'http://localhost:5000/static/example.pdf',
method: 'GET',
responseType: 'blob', // important
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'file.pdf');
document.body.appendChild(link);
@robertoentringer
robertoentringer / gist:85b5706f193b31b81a6e046102e16b87
Created March 1, 2019 19:43 — forked from borismus/gist:1032746
Convert a base64 string into a binary Uint8 Array
var BASE64_MARKER = ';base64,';
function convertDataURIToBinary(dataURI) {
var base64Index = dataURI.indexOf(BASE64_MARKER) + BASE64_MARKER.length;
var base64 = dataURI.substring(base64Index);
var raw = window.atob(base64);
var rawLength = raw.length;
var array = new Uint8Array(new ArrayBuffer(rawLength));
for(i = 0; i < rawLength; i++) {
@robertoentringer
robertoentringer / LICENSE.txt
Created March 1, 2019 23:42 — forked from jed/LICENSE.txt
generate random UUIDs
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE