Skip to content

Instantly share code, notes, and snippets.

View electerious's full-sized avatar

Tobias Reich electerious

View GitHub Profile
@electerious
electerious / Caddyfile
Created August 20, 2016 18:15
Most complete list of mime types in the correct format for the Caddy mime directive
mime {
.atom application/atom+xml
.json application/json
.map application/json
.topojson application/json
.jsonld application/ld+json
.rss application/rss+xml
.geojson application/vnd.geo+json
.rdf application/xml
.xml application/xml
@electerious
electerious / countries.js
Last active April 1, 2024 21:09 — forked from vxnick/gist:380904
All country codes in one object.
var countries = {
AF: 'Afghanistan',
AX: 'Aland Islands',
AL: 'Albania',
DZ: 'Algeria',
AS: 'American Samoa',
AD: 'Andorra',
AO: 'Angola',
AI: 'Anguilla',
AQ: 'Antarctica',
@electerious
electerious / generateImages.js
Created August 26, 2023 14:02
Image processing with Node.js and sharp
import { parse, format } from 'path'
import Progress from 'cli-progress'
import sharp from 'sharp'
const fit = process.argv[2]
const width = parseInt(process.argv[3])
const height = parseInt(process.argv[4])
const paths = process.argv.splice(5)
const toFile = (path) => {
{
"rules": {
"color-no-invalid-hex": true,
"function-calc-no-unspaced-operator": true,
"function-linear-gradient-no-nonstandard-direction": true,
"function-max-empty-lines": 0,
"function-parentheses-space-inside": "never",
"function-url-quotes": "always",
"function-whitespace-after": "always",
"function-comma-space-after": "always",
@electerious
electerious / ackee_scriptable_views_today.js
Last active March 17, 2021 18:32
Ackee iOS widget for Scriptable.app
// On first run only, uncomment line bellow and replace '888...' with the token returned after login
// Keychain.set("ACKEE_KEY", "88888888-8888-8888-8888-888888888888")
// Ackee configuration
const ACKEE_KEY = Keychain.get('ACKEE_KEY')
const ACKEE_API = 'https://ackee.example.com/api'
const TIME_ZONE = 'Europe/Berlin'
const createWidget = async () => {
const viewsToday = await getViewsToday()
const ajaxform = (form, next) => {
let url = form.action
let xhr = new XMLHttpRequest()
let data = new FormData(form)
xhr.open('POST', url)
xhr.onload = () => next(form, xhr)
xhr.send(data)
@electerious
electerious / formatNumber.js
Created September 30, 2016 10:47
Format a number
const formatNumber = (num, delimiter = ',') => num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, delimiter)
@electerious
electerious / single.js
Last active February 15, 2021 02:33
Function that continuously executes the function it has been most recently called with
const single = (max) => {
let id
let iterations
const loop = (_id, fn) => {
if (id!==_id) return
if (max!==undefined && iterations>=max) return
@electerious
electerious / absoluteToRelativePath.js
Created November 4, 2018 12:50
Converts absolute SVG coordinates to relative ones in order to create a responsive SVG mask that can be applied using CSS clip-path
"M78,0 L78.8918331,0.216238031 C80.7796201,0.673959707 82.3332983,2.08608489 83.0043945,3.9000001 C83.0192652,3.94019419 83.0330484,3.98600042 83.0457442,4.03741878 L83.0390876,7.96097867 C83.0390545,20.7025492 93.3365052,31 106.039054,31 L268.960946,31 C281.663495,31 291.960946,20.7025492 291.960946,8 C291.960946,7.99147462 291.95879,6.71458263 291.954479,4.16932405 C291.954323,4.07746778 291.970341,3.98630146 292.001801,3.9000001 C292.667785,2.07301174 294.211271,0.676168263 296.108167,0.216238031 L297,0 L335,0 C357.09139,-4.05812251e-15 375,17.90861 375,40 L375,772 C375,794.09139 357.09139,812 335,812 L40,812 C17.90861,812 2.705415e-15,794.09139 0,772 L0,40 C-2.705415e-15,17.90861 17.90861,4.05812251e-15 40,0 L78,0 Z"
.split(' ')
.reduce((acc, entry) => {
// Remove the first character from a string
const removeChars = (str = '') => str.replace(/^[A-Z]/g,'')
// Divide a value with the current divider
const divide = (dividers) => (value, index) => value / dividers[index]
@electerious
electerious / scrollroot.js
Last active September 17, 2019 13:45
Cross-browser scroll element fetching
const scrollroot = (() => {
if ('scrollingElement' in document) return document.scrollingElement
const initial = document.documentElement.scrollTop
document.documentElement.scrollTop = initial + 1
const updated = document.documentElement.scrollTop
document.documentElement.scrollTop = initial