Skip to content

Instantly share code, notes, and snippets.

@prantlf
prantlf / trust-npm.sh
Last active March 20, 2022 17:33
Look for unreliable package authors
#!/bin/sh
# Look for NPM modules of the authors below in the local node_modules.
# Author of left-pad unpublished their modules from the NPM registry,
# which broke a lot of packages.
# https://www.theregister.com/2016/03/23/npm_left_pad_chaos/
# https://medium.com/@mproberts/a-discussion-about-the-breaking-of-the-internet-3d4d2a83aa4d
# https://blog.npmjs.org/post/141577284765/kik-left-pad-and-npm
# https://www.reddit.com/r/programming/comments/4bjss2/an_11_line_npm_package_called_leftpad_with_only/
@prantlf
prantlf / package.json
Last active October 1, 2019 08:46
Serves files from the current directory and subdirectories over HTTP for local development purposes using multiple workers.
{
"name": "dev-http-server",
"version": "0.0.1",
"description": "Development HTTP server serving the current duirectory.",
"license": "MIT",
"author": "Ferdinand Prantl <prantlf@gmail.com> (http://prantl.tk/)",
"contributors": [],
"homepage": "https://gist.github.com/prantlf/2514e4b43b8c6ef6ab08a4d2084a69ba",
"repository": "https://gist.github.com/prantlf/2514e4b43b8c6ef6ab08a4d2084a69ba",
"bugs": "https://gist.github.com/prantlf/2514e4b43b8c6ef6ab08a4d2084a69ba",
@prantlf
prantlf / har2paths.js
Last active September 29, 2019 10:06
Extract URL paths from a HAR file
// Useful for generating a list of paths for performance testing using `wrk`
// and https://github.com/timotta/wrk-scripts/blob/master/multiplepaths.lua.
const description = `Usage: node har2paths (file.har) > paths.txt
Prints URL paths of all server calls made while loading the first page
from the HAR file, which has been created for a SPA.`
const harName = process.argv[2]
if (!harName) {
@prantlf
prantlf / nginx.conf
Last active September 29, 2019 12:15 — forked from foxxyz/nginx.conf
Serve current directory via nginx
# Simple development setup to serve a directory at http://localhost:9001.
# Start nginx in the directory to serve with `nginx -c ~/nginx.conf`.
# When using a laptop with an above average equipment. 2 workers
# significantly increase the throughput. 4 workers still help
# noticeably. The server slows down With more than 6 workers.
worker_processes 2;
events {
accept_mutex off;
}
@prantlf
prantlf / install_ruby_with_rbenv.md
Last active December 3, 2018 16:23 — forked from stonehippo/install_ruby_with_rbenv.md
Installing a new Ruby with rbenv on Mac OS

Install a new Ruby with rbenv on Mac OS (and make yourself a superhero)

If you're doing stuff with Ruby on a Mac, e.g. installling Jekyll or something, by default you'll end up having to use the sudo command to do stuff, since the permission to modify the default config is not available to your user account.

This sucks and should be avoided. Here's how to fix that.

Installing a new Ruby

To make this better, we are going install a new, custom Ruby. This used to be a big, scary thing, but thanks to the awesome tools Homebrew and rbenv, it's a snap.*

A word of warning: you will have to use Terminal to install this stuff. If you are uncomfortable with text, words, and doing stuff with your computer beyond pointing and hoping, this may not work well for you. But if that's the case, I'm not sure why you were trying to use Ruby in the first place.

@prantlf
prantlf / can-be-seen.js
Last active September 2, 2018 00:10
Check, that an element can be really seen in the browser window
// Checks, that the element is not only visible in DOM,
// but that it can be really seen either in the window,
// or only in the visible part of the windows (viewport).
// The centre of the element has to be seen, at least.
function canBeSeen (element, inViewPort) {
// Filter out hidden elements
if (element.offsetHeight === 0) {
return false
}
// Get extents of the viewport
@prantlf
prantlf / japanese-font-family.md
Last active November 7, 2022 09:02 — forked from vanquang9387/japanese-font-family.md
Japanese default css font family

Most Japanese websites use default font sets provided on Windows, Mac or Ubuntu. The latest ones are Meiryo, Hiragino Kaku Gothic Pro and Noto. For older versions such like Windows XP, it is good to add former default fonts MS Gothic(or MS Mincho)/Osaka. Older Linux versions may include Takao fonts.

Some old browsers could not understand those font names in English, some others do not recognize the names in Japanese, so it is safe to write both in Japanese and English.

Meiryo and Hiragino's order is, because Mac users may have Meiryo from MS-Office, and Hiragino is more familiar and matching well on Mac, better by starting Hiragino series.

So the current recommended practice is like this:

font-family: "ヒラギノ角ゴ Pro W3", "Hiragino Kaku Gothic Pro", Osaka, メイリオ, Meiryo, "MS Pゴシック", "MS PGothic", "MS ゴシック" , "MS Gothic", "Noto Sans CJK JP", TakaoPGothic, sans-serif;
@prantlf
prantlf / ttc2ttf
Created July 19, 2018 04:35 — forked from lilydjwg/ttc2ttf
Convert .ttc to several .ttf files into the current directory
#!/usr/bin/env python2
import sys
import fontforge
def main(file):
for font in fontforge.fontsInFile(file):
f = fontforge.open(u'%s(%s)' % (file, font))
f.generate('%s.ttf' % font)
@prantlf
prantlf / upgrade-npms.sh
Created June 18, 2018 21:50
Upgrade npm dependencies semi-automatically
git pull --all && ncu -au && npm i && npm test
git commit -a -m "chore: Upgrade development npm module dependencies" && git push --all
@prantlf
prantlf / jquery.ajaxIntercept.js
Last active July 17, 2020 22:13
Intercepts AJAX calls issued against a base URL and redirect them to other service
// jQuery.ajaxIntercept 0.2.0
// https://gist.github.com/prantlf/316c8dc3b80c3b2a0aad3be2d0d01a86
//
// Copyright (c) 2017 Ferdinand Prantl
// Licensed under the MIT license.
//
// Allows intercepting AJAX calls issued against a base URL
// and either redirect them to some other service, or compose
// the response by a custom asynchronous callback