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
// ----
// Sass (v3.4.21)
// Compass (v1.0.3)
// ----
// _colors.scss
$white: #FFFFFF;
$black: #000000;
$navy: #003C5A;
@andreasvirkus
andreasvirkus / fileName.html
Created April 2, 2018 11:00
Prepending a file name to a pre/code element
<style>
.file-desc::before {
content: "\2193 \00a0";
color: rgba(239,187,53,.6);
}
</style>
<p class="file-desc">someFile.js</p>
@andreasvirkus
andreasvirkus / momentLocale.js
Created March 19, 2018 14:10
Force webpack to use only the locale you need (reduces moment's bundle from ~90kB -> ~20kB)
new ContextReplacementPlugin(/moment[\/\\]locale$/, /uk/),
@andreasvirkus
andreasvirkus / print.css
Last active March 17, 2018 06:02
A decent boilerplate for print CSS
/* TODO: Add support for page, chapter and figure counters */
/* Built with the help of https://www.smashingmagazine.com/2015/01/designing-for-print-with-css/ */
@media print {
main {
width: 100%;
margin: 0;
}
@page { margin: 2cm }
@andreasvirkus
andreasvirkus / confirm.js
Last active February 7, 2018 07:49
jAlert confirm example
$(document).ready(function () {
$.jAlert({
'type': 'confirm',
'confirmQuestion': 'Do you want to add this?',
'onConfirm': function(e, btn){
e.preventDefault();
//do something here
btn.parents('.jAlert').closeAlert();
return false;
@andreasvirkus
andreasvirkus / platformSniff.js
Created February 1, 2018 08:13
Find out (somewhat successfully) whether your user is on a mobile (tablet included) or desktop platform.
const supportsTouch = 'ontouchstart' in window || navigator.msMaxTouchPoints;
const agentSniff = typeof window.orientation !== "undefined" ||
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
export default supportsTouch && agentSniff;
// Determine if an element matches a selector
export const matches = (el, selector) => {
if (!isElement(el)) {
return false
}
// https://developer.mozilla.org/en-US/docs/Web/API/Element/matches#Polyfill
// Prefer native implementations over polyfill function
const proto = Element.prototype
const Matches = proto.matches ||
function fetchStream(url) {
const req = new Request(url)
return fetch(req).then(rs => {
const reader = rs.body.getReader()
return reader.read().then(({ done, value }) => {
const decoder = new TextDecoder('utf-8')
return decoder.decode(value)
}).catch(err => console.log(`Could not fetch from ${url}!`, err))
const date = new Date()
const day = date.getDate()
const month = date.getMonth() + 1
const year = date.getFullYear()
const time = `${month}/${day}/${year}`
@andreasvirkus
andreasvirkus / trunc.js
Created September 29, 2017 07:40
Truncate strings
String.prototype.trunc = String.prototype.trunc || function(n) {
return (this.length > n) ? this.substr(0, n-1) + '&hellip;' : this;
};