Skip to content

Instantly share code, notes, and snippets.

View andreasvirkus's full-sized avatar
🙊
made you look

andreas andreasvirkus

🙊
made you look
View GitHub Profile
const styleEl = document.createElement('style')
styleEl.setAttribute('id', '_unique-id-outline-styles')
document.head.appendChild(styleEl)
// Inject outline preventing styles only for non-keyboard users
document.addEventListener('mousedown', () => {
styleEl.innerHTML = 'a,a:focus,button,button:focus,input,input:focus,textarea,textarea:focus,div:focus {outline:none}'
})
document.addEventListener('keydown', () => {
@andreasvirkus
andreasvirkus / serializeWithStyles.js
Created July 19, 2018 07:14
Get the whole DOM of an element with its styles (defaults excluded) inlined.
/**
* Usage:
*
* document.getElementById('app').serializeWithStyles()
*
* Credits go to https://stackoverflow.com/a/6310120/2803743
*/
Element.prototype.serializeWithStyles = (function () {
// Mapping between tag names and css default values lookup tables. This allows to exclude default values in the result.
@andreasvirkus
andreasvirkus / .slate
Created July 18, 2018 06:50
Slate config from lmullen
# GLOBAL CONFIGURATIONS
# -------------------------------------------------------------------
# See https://github.com/jigish/slate/wiki/Global-Configs
config defaultToCurrentScreen true
config secondsBeforeRepeat 0.4
config secondsBetweenRepeat 0.1
config keyboardLayout "qwerty"
config nudgePercentOf screenSize
config resizePercentOf screenSize
@andreasvirkus
andreasvirkus / tally.js
Created July 8, 2018 16:34
Takes an array and returns a tally of its unique items
const nums = [3, 5, 6, 82, 1, 4, 3, 5, 82]
const result = nums.reduce((tally, amt) => {
tally[amt] ? tally[amt]++ : tally[amt] = 1
return tally
}, {})
console.log(result)
@andreasvirkus
andreasvirkus / installPeerDeps.sh
Created July 3, 2018 10:33
Install peerDependencies on UNIX machines
(
export PKG=eslint-config-airbnb;
npm info "$PKG@latest" peerDependencies --json | command sed 's/[\{\},]//g ; s/: /@/g' | xargs npm install --save-dev "$PKG@latest"
)
export default (bytes) => {
const thresh = 1024;
if (Math.abs(bytes) < thresh) {
return bytes + ' B';
}
const units = ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
let u = -1;
@andreasvirkus
andreasvirkus / readBattery.js
Last active July 2, 2018 05:55
Get navigator's battery data (current percentage, power source, usage time remaining and time to fully charge)
(function() {
let battery;
function toTime(sec) {
sec = parseInt(sec, 10)
let hours = Math.floor(sec / 3600)
let minutes = Math.floor((sec - (hours * 3600)) / 60)
let seconds = sec - (hours * 3600) - (minutes * 60)
<!--[if lte IE 9]>
<div class="legacy-warning">
<div class="container">
Seems like your browser is quite outdated.
Why not <a href="http://browsehappy.com/">upgrade to a modern one</a>
for free and improve your experience?
</div>
</div>
<![endif]-->
@andreasvirkus
andreasvirkus / certificates.sh
Created June 8, 2018 03:15
LetsEncrpyt setup for docker
# Set the Domain variable
export DOMAIN=NAME_OF_THE_DOMAIN
# Pull the docker image for certbot:
docker pull deliverous/certbot
# Obtain the certificates
docker run -it --rm -v /home/$(whoami)/vue-people/nginx/certs:/etc/letsencrypt:rw -v /home/$(whoami)/vue-people/nginx/certs-data:/data/letsencrypt:rw deliverous/certbot certonly --webroot --webroot-path=/data/letsencrypt -d $DOMAIN
# copy the certbot certs:
@andreasvirkus
andreasvirkus / _spacings.scss
Last active June 6, 2018 08:51
A loop to generate util classes for paddings and margins
// ----
// Sass (v3.4.25)
// Compass (v1.0.3)
// ----
$spaceamounts: (auto, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 80, 100);
$sides: (
t: top,
b: bottom,
l: left,