Skip to content

Instantly share code, notes, and snippets.

View laziel's full-sized avatar
🐳

Jihan Kim laziel

🐳
  • NAVER Corp.
  • Seoul, South Korea
View GitHub Profile
@laziel
laziel / color-comparison.js
Last active October 11, 2019 09:53
Color comparison function for RGB (isLighterThan, isDarkerThan)
/** Extracted from https://gist.github.com/alexandrudima/bda598fbed179a581986b634cc94ab8d */
/**
* Returns the number in the set [0, 1].
* - O => Darkest Black.
* - 1 => Lightest white.
* @see http://www.w3.org/TR/WCAG20/#relativeluminancedef
*
* @param {Object} color
* @param {Number} color.r
@laziel
laziel / image-orientation.css
Last active June 30, 2020 08:50
Get image orientation from EXIF header
/*
JPEG orientation transform
See https://magnushoff.com/jpeg-orientation.html
*/
img[data-orientation="2"] {
transform: rotateY(180deg);
}
img[data-orientation="3"] {
transform: rotate(180deg);
@laziel
laziel / interceptors.js
Created September 29, 2020 03:45 — forked from javisperez/interceptors.js
Axios interceptor for cache with js-cache
// Usually I use this in my app's config file, in case I need to disable all cache from the app
// Cache is from `js-cache`, something like `import Cache from 'js-cache';`
const cacheable = true,
cache = new Cache();
// On request, return the cached version, if any
axios.interceptors.request.use(request => {
// Only cache GET requests
if (request.method === 'get' && cacheable) {
@laziel
laziel / water_ripple_canvas.js
Created May 3, 2017 13:45 — forked from StuPig/water_ripple_canvas.js
Use JavaScript and canvas to create water ripple effect
/*
* Water Canvas by Almer Thie (http://code.almeros.com).
* Description: A realtime water ripple effect on an HTML5 canvas.
* Copyright 2010 Almer Thie. All rights reserved.
*
* Example: http://code.almeros.com/code-examples/water-effect-canvas/
* Tutorial: http://code.almeros.com/water-ripple-canvas-and-javascript
*/
@laziel
laziel / gen.sh
Created July 19, 2021 16:27 — forked from flotwig/gen.sh
Generate a Chrome extension ID with a desired prefix
#!/bin/bash
# https://stackoverflow.com/a/23877974/3474615
while [[ $EXT_PREFIX != "ioio" ]] # change 'ioio' to your desired prefix (can only use lowercase a-p)
do
rm key.pem manifest_key.txt extension_id.txt
2>/dev/null openssl genrsa 2048 | openssl pkcs8 -topk8 -nocrypt -out key.pem
2>/dev/null openssl rsa -in key.pem -pubout -outform DER | openssl base64 -A > manifest_key.txt
@laziel
laziel / generate_random_string.js
Created March 14, 2023 12:06
Generate random string in given length
const genRandomStr = (length = 16) {
let t = '';
while (t.length < 16) {
t = t + Math.random().toString(36).substr(2);
}
return t.substr(0, length);
};
@laziel
laziel / unlock.js
Created September 18, 2015 09:02
Unlock Web Audio in iOS 9 Safari
var ctx = null, usingWebAudio = true;
try {
if (typeof AudioContext !== 'undefined') {
ctx = new AudioContext();
} else if (typeof webkitAudioContext !== 'undefined') {
ctx = new webkitAudioContext();
} else {
usingWebAudio = false;
}
(function(){
var networks = [{
url: "https://squareup.com/login?return_to=%2Ffavicon.ico",
name: "Square"
}, {
url: "https://www.instagram.com/accounts/login/?next=%2Ffavicon.ico",
name: "Instagram"
}, {
url: "https://twitter.com/login?redirect_after_login=%2Ffavicon.ico",
name: "Twitter"