Skip to content

Instantly share code, notes, and snippets.

View espretto's full-sized avatar

Marius espretto

  • Oldenburg
View GitHub Profile
@espretto
espretto / typr.js
Last active August 29, 2015 14:21
JavaScript: typr - deep type checking with error reports
/**
* typr - deep type checking with error reports
* MIT licence
*/
;(function (root) {
'use strict';
/* ---------------------------------------------------------------------------
@espretto
espretto / requirejs-css.js
Created July 1, 2015 12:13
JavaScript: requirejs-css-loader
/**
* amd plugin for loading css specifically for components that
* have a custom tag-name. the stylesheet has to include
* the css-property `cursor` with a value different from `auto` within a css-rule
* for the tag-name.
*
* the `display: block` property might have served well this purpose since it
* has to be set just like the html5shiv does. however, then again we might
* actually want a custom tag that is `display: inline` which is the default
@espretto
espretto / csson.js
Last active November 5, 2015 20:14
JavaScript: css parser
;(function (window, jQuery){
/* ---------------------------------------------------------------------------
* utilities
*/
var document = window.document;
var location = window.location;
@espretto
espretto / trim-transparent-borders.py
Last active June 12, 2019 08:58 — forked from nojvek/PNGAlphaTrim.py
trim transparent border from all png files in a folder
import Image
import sys
import glob
# Trim all png images with alpha in a folder
# Usage "python PNGAlphaTrim.py ../someFolder"
try:
folderName = sys.argv[1]
except :
@espretto
espretto / asyncio_cors.py
Created April 28, 2017 18:45
cors middleware for asyncio
from aiohttp import web
web.Application(middlewares=[cors_factory])
ALLOWED_HEADERS = ','.join((
'content-type',
'accept',
'origin',
'authorization',
'x-requested-with',
@espretto
espretto / bash-snippets.sh
Last active September 21, 2022 16:02
bash: snippets
#!/bin/bash
# ------------------------------------------------------------------------------
# strict mode
set -euo pipefail; IFS=$'\n\t'
# ------------------------------------------------------------------------------
# notes
#
# - `[` represents the command `test`, use `[[` builtin instead.
# - `-a` and `-o` are deprecated, use `&&` and `||` instead.
@espretto
espretto / slugify.js
Last active July 28, 2023 06:54
js: slugify
const latin1 = (
'A,A,A,A,Ae,A,AE,C,E,E,E,E,I,I,I,I,D,N,O,O,O,O,Oe,-,Oe,U,U,U,Ue,Y,Th,ss,' +
'a,a,a,a,ae,a,ae,c,e,e,e,e,i,i,i,i,d,n,o,o,o,o,oe,-,oe,u,u,u,ue,y,th,y'
).split(',');
function slugifyChar(chr) {
return latin1[chr.charCodeAt(0) - 0xC0];
}
function slugify(str) {
@espretto
espretto / zoomer.js
Last active January 8, 2020 12:54
js: magnifying glass for images
/**
* magnifying glass for images
* @licence MIT
*/
(function () {
/** avoid subpixel rendering */
function px (n) {
return Math.floor(n) + 'px'
@espretto
espretto / nginx.conf
Created May 19, 2020 21:03
nginx:reverse-proxy
# example nginx config
# ------------------------------------------------------------------------------
# serve static files from volume mounted at /public
# serve backend api expsosed by container "backend" on port 5000
# ------------------------------------------------------------------------------
user nginx;
worker_processes 1;
events {
@espretto
espretto / measureText.ts
Last active October 9, 2020 08:01
ts: measure text with offline canvas
const canvasContext = document
.createElement("canvas")
.getContext("2d") as CanvasRenderingContext2D;
/**
* measures text with the [canvas API](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/measureText)
* [avoiding expensive reflows](https://gist.github.com/Yukiniro/876826e1450b1f8cf755d2cea83cda65).
*/
export function measureText(text: string, font: string = "normal 16px serif") {
canvasContext.font = font;