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 / 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 / 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 / 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 / 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 / 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 / exif-orientation.js
Created May 16, 2019 10:12
EXIF image orientation
/**
* Get image orientation from EXIF header
*
* Referenced:
* - https://gist.github.com/nezed/d536ccdace84c6f2ef13da47a8fd6bdb
* - https://gist.github.com/wonnage/9d2e73d9228f5a0b300d75babe2c3796
* - https://github.com/blueimp/JavaScript-Load-Image/blob/master/js/load-image-meta.js
*
* @param {String} imageUrl
* @return {Promise}
@laziel
laziel / youtube.js
Created November 17, 2018 10:52 — forked from max-te/youtube.js
Download Youtube-Video in node.js
var http = require('http')
var fs = require('fs')
var argv = require('optimist').argv
var rxVideoID = /v=([\]\[!"#$%'()*+,.\/:;<=>?@\^_`{|}~-\w]*)/
var link = argv._.toString()
var videoID = link.match(rxVideoID)[1]
http.get("http://www.youtube.com/get_video_info?video_id="+videoID, function(res) {
var chunks = []
@laziel
laziel / draggable.js
Created July 3, 2018 08:37
Pure JavaScript Draggable
(function () {
const wrapper = document.querySelector(`#test`);
const pos = {};
const moveDrag = evt => {
// const { scrollLeft, scrollTop } = document.scrollingElement;
const o = {
top: wrapper.offsetTop - (pos.clientY - evt.clientY),
left: wrapper.offsetLeft - (pos.clientX - evt.clientX)
@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 / 094607.md
Created April 6, 2016 07:13 — forked from marocchino/094607.md
ES6์‹œ๋Œ€์˜ JavaScript

ES6์‹œ๋Œ€์˜ JavaScript

์•ˆ๋…•ํ•˜์„ธ์š”. ์‚ฌ์›์‚ฌ์—…๋ถ€์˜ ๋งˆ๋ฃจ์•ผ๋งˆ@h13i32maru์ž…๋‹ˆ๋‹ค. ์ตœ๊ทผ์˜ Web ํ”„๋ก ํŠธ์—”๋“œ์˜ ๋ณ€ํ™”๋Š” ๋งค์šฐ ๊ฒฉ๋ ฌํ•ด์„œ, ์กฐ๊ธˆ ๋ˆˆ์„ ๋• ์‚ฌ์ด์— ์ ์  ์ƒˆ๋กœ์šด ๊ฒƒ์ด ๋‚˜์˜ค๊ณ  ์žˆ๋”๋ผ๊ตฌ์š”. ๊ทธ๋Ÿฐ ๊ฒฉ๋ ฌํ•œ ๋ณ€ํ™”์ค‘ ํ•˜๋‚˜๊ฐ€ ES6์ด๋ผ๋Š” ์ฐจ์„ธ๋Œ€ JavaScript์˜ ์‚ฌ์–‘์ž…๋‹ˆ๋‹ค. ์ด ES6๋Š” ํ˜„์žฌ ์žฌ์ •์ค‘์œผ๋กœ ์ง‘ํ•„์‹œ์ ์—์„œ๋Š” Draft Rev31์ด ๊ณต๊ฐœ๋˜์–ด์žˆ์Šต๋‹ˆ๋‹ค.

JavaScript๋Š” ECMAScript(ECMA262)๋ผ๋Š” ์‚ฌ์–‘์„ ๊ธฐ๋ฐ˜์œผ๋กœ ๊ตฌํ˜„๋˜์–ด์žˆ์Šต๋‹ˆ๋‹ค. ํ˜„์žฌ ๋ชจ๋˜ํ•œ Web ๋ธŒ๋ผ์šฐ์ €๋Š” ECMAScript 5.1th Edition์„ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•œ JavaScript์‹คํ–‰ ์—”์ง„์„ ํƒ‘์žฌํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๋‹ค์Œ ๋ฒ„์ „์ธ ECMAScript 6th Edition์ด ํ˜„์žฌ ์žฌ์ •์ค‘์œผ๋กœ, ์•ฝ์นญ์œผ๋กœ ES6์ด๋ผ๋Š” ๋ช…์นญ์ด ์‚ฌ์šฉ๋˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.