Skip to content

Instantly share code, notes, and snippets.

@prantlf
prantlf / deepClone.js
Last active September 2, 2018 00:12
JavaScript deepClone + integration to Undescore.js and Backbone.js
// Performs a deep clone of primitive values, arrays, object literals,
// and arbitrary objects, if requested. It is supposed to clone object
// literals, which are going to be modified, but the original should
// stay intact.
//
// The default behaviour works well with JSON REST API responses and
// and other objects, which contain only values of native types.
// If functions or HTML elements are encountered, they will not be
// actually cloned; they will be just copied, which works well with
// the typical options objects for Backbone constructors.
@prantlf
prantlf / require.config.js
Last active September 2, 2018 00:12
Loads JSON file, parses it to an object and passes it to require.config
// Loads JSON file, parses it to an object and passes it to require.config
//
// https://gist.github.com/prantlf/a7972320307580573eb715ed65e85a2b
// Copyright (c) 2016 Ferdinand Prantl
// Licensed under the MIT license.
//
// If you have a couple of pages and apply the same RequireJS configuration
// on them, you would like to maintain the configuration content at a single
// place. You could put the require.config statement to a script file and
// load it on the page by the script element before your main application
@prantlf
prantlf / jquery.parseParams.js
Last active September 2, 2018 00:12
Reverses the $.param effect - parses the URL query part into an object
// jQuery.parseParams 0.1.0
// https://gist.github.com/prantlf/061e3911cd450491f84aac40292b7e7c
//
// Copyright (c) 2015-2017 Ferdinand Prantl
// Licensed under the MIT license.
//
// Reverses the $.param effect - parses the URL query part into an object
// with parameter names as keys pointing to parameter values; normalizes
// all parameter names to lower-case and saves multiple parameters with
// the same name to arrays
@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
@prantlf
prantlf / selenium.test.js
Last active March 28, 2018 01:04
Script to reproduce the chromedriver process not stopping for https://github.com/vvo/selenium-standalone/issues/351
const selenium = require('selenium-standalone')
const webdriverio = require('webdriverio')
const configuration = {
version: '3.8.1',
baseURL: 'http://selenium-release.storage.googleapis.com',
drivers: {
chrome: {
version: '2.37',
arch: process.arch,
@prantlf
prantlf / npm.log
Created June 18, 2018 06:19
vnu-jar@dev cannot be found
ferdipr@de08365:~/0 npm i vnu-jar@dev --verbose --no-color
npm info it worked if it ends with ok
npm verb cli [ '/home/ferdipr/.nvm/versions/node/v8.11.2/bin/node',
npm verb cli '/home/ferdipr/.nvm/versions/node/v8.11.2/bin/npm',
npm verb cli 'i',
npm verb cli 'vnu-jar@dev',
npm verb cli '--verbose',
npm verb cli '--no-color' ]
npm info using [email protected]
npm info using [email protected]
@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 / 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 / japanese-font-family.md
Last active January 3, 2025 17:36 — 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 / 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