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
function *pollForWeatherInfo(){
while (true) {
yield fetch('/api/currentWeather', {
method: 'get'
}).then(res => res.json())
}
}
function runPolling(generator){
if (!generator) {
@andreasvirkus
andreasvirkus / DropdownLink.vue
Last active April 21, 2018 04:41
Dropdown in Vue
import nprogress from 'nprogress'
export default {
// ...
// configure progress bar
nprogress.configure({ showSpinner: false })
this.$router.beforeEach((to, from, next) => {
if (to.path !== from.path && !Vue.component(pathToComponentName(to.path))) {
// ----
// 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 ||