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
@andreasvirkus
andreasvirkus / train-time-bookmarklet.js
Last active December 1, 2019 16:42
train-time-bookmarklet.js
javascript:(()=>{const e=new Date,t=(e.getDate()+'').padStart(2,'0'),l=e.getMonth()+1;let n=`https://elron.pilet.ee/et/otsing/Tondi/Pääsküla/${`${e.getFullYear()}-${l}-${t}`}`;location.href=n})();
onKeydown(e) {
const { toggleSidebar, next, previous } = this.props;
const keyMapping = new Map([
[ 83, toggleSidebar ], // user presses the s button
[ 37, next ], // user presses the right arrow
[ 39, previous ] // user presses the left arrow
]);
if (keyMapping.has(e.which)) {
@andreasvirkus
andreasvirkus / array.js
Created October 11, 2019 12:47
A collection of utility functions to manipulate arrays
/**
* Uses the Durstenfeld shuffle algorithm,
* a modern optimized version of the Fisher-Yates
* (aka Knuth) shuffle.
*
* http://en.wikipedia.org/wiki/Fisher-Yates_shuffle#The_modern_algorithm
*
* @param {Array} Array to shuffle
* @return {Array} Shuffled array
*/
console.log('%c 👋 Salutations, hax0r.\nFeel free to look around. FYI, you\'ll have a better view of the code over at GitHub: \nhttps://github.com/andreasvirkus/cottage', 'background: #223; color: #bada55');
// Needs spread operator (... notation)
export const promisify = (fn) => {
return (...args) => {
return new Promise((resolve, reject) => {
fn(...args, (err, res) => {
if (err) return reject(err)
return resolve(res)
})
})
}
/**
* Medium-strength regex checks if the password contains 2 of:
* - lowercase alphabetical char
* - uppercase alphabetical char
* - numerical character
* - minimum of 6 characters
*
* Strong-strength regex checks if the password contains all of:
* - lowercase alphabetical char
* - uppercase alphabetical char
// See an excellent explanation over at
// https://medium.com/hackernoon/the-100-correct-way-to-split-your-chunks-with-webpack-f8a9df5b7758
optimization: {
runtimeChunk: 'single',
splitChunks: {
chunks: 'all',
maxInitialRequests: Infinity,
// Default is 30kB, let's set it to 5kB
minSize: 5000,
cacheGroups: {

Extension reloader

This will watch a Chrome extension's file directory, compile a hash based on the file names and date and reload the extension/add-on when the directory undergoes changes.

Compatible with Webpack and any other type of build setup! 📦

Usage

Add the script to your extension's manifest.json

<body>
<blockquote>
<p>Photos by <a href="https://source.unsplash.com/">random photographers</a> on <a href="https://unsplash.com/">Unsplash</a></p>
</blockquote>
<main>
<img lazy data-src="https://source.unsplash.com/random/800x600">
<img lazy data-src="https://source.unsplash.com/random/800x600">
<img lazy data-src="https://source.unsplash.com/random/800x600">
<img lazy data-src="https://source.unsplash.com/random/800x600">
// Minimal jQuery
const $$ = document.querySelectorAll.bind(document);
const $ = document.querySelector.bind(document);