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
/**
* Fixes the content shift caused by disappearing/appearing scrollbars
*
* Inspired by https://aykevl.nl/2014/09/fix-jumping-scrollbar
*/
@media screen and (min-width: 25em) {
html {
margin-left: calc(100vw - 100%);
margin-right: 0;
}
/**
* Round the given number to the nearest incrementation of the provided stepper.
*/
const roundToNearest = function(number, nearest) {
const rounded = number + nearest/2 - (number+nearest/2) % nearest;
return rounded;
};
const nearest = 0.25;
That's right. I'm from the 90s.
///////////////////////////////////////////////////////////////////
/// Parimat, ///
/// With best regards, ///
///////////////////////////////////////////////////////////////////
/// Andreas J Virkus /// [email protected] ///
/// developer & /// www.andreasvirkus.me ///
/// web designer /// +372 52 80 234 ///
// Nifty way to get all the dependencies from your package.json file
const vendors = Object.keys(require(__dirname + '/../package').dependencies);
module.exports = function DefaultError(message, extra) {
Error.captureStackTrace(this, this.constructor);
this.name = this.constructor.name;
this.message = message;
this.extra = extra;
};
require('util').inherits(module.exports, Error);
@andreasvirkus
andreasvirkus / build.js
Last active May 22, 2017 18:04
This plugin loops over a markdown file's headings and creates a ToC in the metadata. Example template and build file included.
var Metalsmith = require('metalsmith'),
markdown = require('metalsmith-markdown'),
layouts = require('metalsmith-layouts'),
tocTask = require('./metalsmithTableOfContentsTask.js');
var ms = Metalsmith(__dirname)
.source('./src')
.use(markdown())
.use(tableOfContentsTask())
.use(layouts({
/**
* A quick (and rather sexy) way to loop over a NodesList and add event listeners to all elements
*/
[].forEach.call(nodeList, function(e) {
e.addEventListener('click', callback, false);
});
// drop-in vanilla ajax navigation
(function() {
var main = document.querySelectorAll('main')[0], // Selector to load
state = history.state || location.pathname,
navLinks = document.querySelectorAll('header a');
[].forEach.call(navLinks, function(e) {
e.addEventListener('click', toggleActive);
});
#!/bin/bash
# Loop through all script files and minify them individually
# to leverage that sweet HTTP/2 performance
#
# Alternative is to minify them into one file:
# uglifyjs ./dist/assets/js/*.js -c -m -o ./dist/assets/js/script.min.js
FILES=./dist/assets/js/*
@andreasvirkus
andreasvirkus / cleancss.min.css
Created May 31, 2017 18:42
Example of inline source map
.blog__menu-link{text-transform:uppercase}.blog__title-divider{background-image:var(--blog-post-divider)}code{border:1px solid #d8e0e4;border-radius:2px;color:#c25;font-size:.8em;line-height:1em;white-space:pre-wrap;vertical-align:middle;padding:.2rem .3rem .1rem;font-family:Consolas,monaco,monospace}pre code{display:block;overflow-x:auto;padding:.5em;color:#333;background:#fff}footer{margin-bottom:1.5rem}footer p{text-align:right;padding-right:.8em;margin:0}.social__link{position:relative}.social__link::after{content:'';position:absolute;width:3em;height:3em;-webkit-transition:border-color .2s;transition:border-color .2s;border:1px dashed transparent;top:-.65em;left:-.62em;z-index:0}.social__link:hover::after{border-color:#444}@media screen and (min-width:35em){footer{padding-right:3em}}@media screen and (max-width:35em){.social{padding-right:1em}}*,::after,::before{-webkit-box-sizing:inherit;box-sizing:inherit}html{-webkit-box-sizing:border-box;box-sizing:border-box}body{margin:0;padding:0;display:-webkit-b