Skip to content

Instantly share code, notes, and snippets.

View mx-rk-quyenl's full-sized avatar
💬

Quyen Luu mx-rk-quyenl

💬
View GitHub Profile
const arrays = [[10], 50, [100, [2000, 3000, [40000]]]];
arrays.flat(Infinity);
// results:
// [ 10, 50, 100, 2000, 3000, 40000 ]
@mx-rk-quyenl
mx-rk-quyenl / notes_for_regex.md
Created January 17, 2021 05:38 — forked from anon5r/notes_for_regex.md
正規表現メモ

正規表現メモ

項目 表記
改行を検索 \n
タブ文字を検索 \t
半角カナを検索 [ア-ンァ-ョッー゚゙・]
全角ひらがなを検索 [あ-んが-ぼぁ-ょゎっー]
全角カタカナを検索 [ア-ンガ-ボァ-ョヮッー]
半角英字を検索 [a-zA-Z]
@mx-rk-quyenl
mx-rk-quyenl / number-pad-zero.js
Created October 12, 2020 04:37 — forked from endel/number-pad-zero.js
Simplest way for leading zero padding in JavaScript
Number.prototype.pad = function(size) {
var s = String(this);
while (s.length < (size || 2)) {s = "0" + s;}
return s;
}
(1).pad(3) // => "001"
(10).pad(3) // => "010"
(100).pad(3) // => "100"
@mx-rk-quyenl
mx-rk-quyenl / splice-object-array.js
Created March 6, 2020 04:07 — forked from scottopolis/splice-object-array.js
Remove object from array of objects in Javascript
// source: http://stackoverflow.com/questions/16491758/remove-objects-from-array-by-object-property
// we have an array of objects, we want to remove one object using only the id property
var apps = [{id:34,name:'My App',another:'thing'},{id:37,name:'My New App',another:'things'}];
// get index of object with id:37
var removeIndex = apps.map(function(item) { return item.id; }).indexOf(37);
// remove object
apps.splice(removeIndex, 1);
@mx-rk-quyenl
mx-rk-quyenl / gist:29cb3b5e1c20a0c42f0b0016b72545db
Created February 14, 2020 04:13 — forked from rxaviers/gist:7360908
Complete list of github markdown emoji markup

People

:bowtie: :bowtie: 😄 :smile: 😆 :laughing:
😊 :blush: 😃 :smiley: ☺️ :relaxed:
😏 :smirk: 😍 :heart_eyes: 😘 :kissing_heart:
😚 :kissing_closed_eyes: 😳 :flushed: 😌 :relieved:
😆 :satisfied: 😁 :grin: 😉 :wink:
😜 :stuck_out_tongue_winking_eye: 😝 :stuck_out_tongue_closed_eyes: 😀 :grinning:
😗 :kissing: 😙 :kissing_smiling_eyes: 😛 :stuck_out_tongue:
@mx-rk-quyenl
mx-rk-quyenl / center-select.js
Created January 7, 2020 10:04
Align center select option using javascript (Jquery)
function getTextWidth(txt) {
let $elm = $('<span class="tempforSize">'+txt+'</span>').prependTo('body');
let elmWidth = $elm.width();
$elm.remove();
return elmWidth;
}
function centerSelect($elm) {
const optionWidth = getTextWidth($elm.children(':selected').html());
const emptySpace = $elm.width() - optionWidth;
$elm.css('text-indent', (emptySpace/2));
@mx-rk-quyenl
mx-rk-quyenl / download-file.js
Created December 12, 2019 03:04 — forked from javilobo8/download-file.js
Download files with AJAX (axios)
axios({
url: 'http://localhost:5000/static/example.pdf',
method: 'GET',
responseType: 'blob', // important
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'file.pdf');
document.body.appendChild(link);
@mx-rk-quyenl
mx-rk-quyenl / decimal.js
Last active October 1, 2019 07:58
Javascript decimal, calc
let DECIMAL_SEPARATOR = '.'
let asInteger = (number) => {
number = String(number)
// var value, exp, tokens = number.split(DECIMAL_SEPARATOR), integer = tokens[0], fractional = tokens[1];
let value = number.split(DECIMAL_SEPARATOR)
let exp = value
let tokens = value
let integer = tokens[0]
let fractional = tokens[1]
// Classification is adopted eight regional division
var regions = [
{id:1, name:"北海道", kana:"ホッカイドウ", en:"hokkaido", neighbor:[2]},
{id:2, name:"東北", kana:"トウホク", en:"tohoku", neighbor:[1]},
{id:3, name:"関東", kana:"カントウ", en:"kanto", neighbor:[2, 4]},
{id:4, name:"中部", kana:"チュウブ", en:"chubu", neighbor:[2, 3, 5]},
{id:5, name:"近畿", kana:"キンキ", en:"kinki", neighbor:[4, 6, 7]},
{id:6, name:"中国", kana:"チュウゴク", en:"chugoku", neighbor:[5, 7, 8]},
{id:7, name:"四国", kana:"シコク", en:"shikoku", neighbor:[5, 6, 8]},
{id:8, name:"九州", kana:"キュウシュウ", en:"kyusyu", neighbor:[6, 7]}
@mx-rk-quyenl
mx-rk-quyenl / remove_duplicates.js
Created December 10, 2018 03:22 — forked from lmfresneda/remove_duplicates.js
Remove duplicates from an array of objects in javascript
// FUN METHOD
/**
* Remove duplicates from an array of objects in javascript
* @param arr - Array of objects
* @param prop - Property of each object to compare
* @returns {Array}
*/
function removeDuplicates( arr, prop ) {
let obj = {};
return Object.keys(arr.reduce((prev, next) => {