Skip to content

Instantly share code, notes, and snippets.

View hmmhmmhm's full-sized avatar
๐Ÿงฏ
BURNING!!

<hmmhmmhm/> hmmhmmhm

๐Ÿงฏ
BURNING!!
View GitHub Profile
@Alex4386
Alex4386 / babyshark-localize.js
Created February 8, 2019 17:39
Automatic Localization of babyshark song by SmartStudy Inc. via window.navigator.language
/* Written for MintNetwork Yukari Cluster - 500 page handling */
const bs = document.getElementById('babyshark');
/* Localize babyshark */
function localize(langCode) {
const country = window.navigator.userLanguage || window.navigator.language;
let ytCode = "";
const lang = langCode || country.split('-')[0];
switch (lang) {
@Rich-Harris
Rich-Harris / diff.md
Created November 28, 2018 01:32
Concept diff

A concept diff from Svelte 2 to 3

-A component must have a default export, but the default export is not the component
-The default export and its properties must be structured a certain way, you can't just use JavaScript
-Components, actions, animations, transitions, custom events etc must be registered, not just imported
-Components can be registered with a shorthand, because the normal way is cumbersome
-methods are attached to the prototype, and `this` is the component, even though it looks (including to linters and typecheckers) as though the `methods` object itself is the context
-Events must be method calls, not arbitrary expressions
-`event` has a special meaning in method calls, as does `this`, as does `refs`, as do `console` and other special names
@Rich-Harris
Rich-Harris / README.md
Last active December 20, 2019 15:19
Optimising CSS modules

WICG/webcomponents#759

Suppose you have an app like this, and your bundler turns .css files into strings:

// main.js
import './x-foo.js';
import './x-bar.js';

document.body.innerHTML = ``;
@Rich-Harris
Rich-Harris / README.md
Last active December 20, 2019 15:19
Source bytes: React vs Ember Octane vs Svelte

I'm procrastinating instead of working on a conference talk, so I decided to implement this component in Svelte to see which framework is most expressive:

Screen Shot 2019-03-30 at 16 42 16

Ember Octane

Here's the original, with the addition of an import for dataUriAsSrc (and updated per @chriskrycho's comment):

<img
@hmmhmmhm
hmmhmmhm / cors_pattern.ts
Last active May 31, 2020 14:59
Code to allow CORS only for valid domain patterns, ์œ ํšจํ•œ ๋„๋ฉ”์ธ ํŒจํ„ด๋งŒ CORS ํ—ˆ์šฉํ•˜๋Š” ์ฝ”๋“œ
import matcher from 'matcher'
import CORS from 'cors'
let corsOptions = {
origin: (origin, callback) => {
let allow = false
for (let allowAccessDomain of settingsData.allowAccessDomains) { // [ "*.mydomain.com"]
if (matcher.isMatch(origin, allowAccessDomain)) {
allow = true
break
@hmmhmmhm
hmmhmmhm / moment_diff.ts
Last active June 1, 2020 05:17
๋ชจ๋ฉ˜ํŠธ๋ฅผ ํ†ตํ•œ์‹œ๊ฐ„ ๊ฐ’ ๋น„๊ต ์‹œ format ์ ์šฉ๋ฐฉ๋ฒ•
import moment from 'moment'
import 'moment-duration-format'
let currentMoment = moment()
let currentMinuteNum = Number(currentMoment.format('mm'))
let nextMin = 1
let _nextContractTime = moment(currentMoment)
.add(nextMin, 'minute')
@sonbyungjun
sonbyungjun / paginate.ts
Last active June 2, 2020 02:31
TypeScript(Javascript) Paginate Calculation Function (ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ(์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ) ํŽ˜์ด์ง€๋„ค์ด์…˜ ๊ณ„์‚ฐ ํ•จ์ˆ˜)
export const paginate = (array: any, index: any, size: any) => {
// transform values
index = Math.abs(parseInt(index));
index = index > 0 ? index - 1 : index;
size = parseInt(size);
size = size < 1 ? 1 : size;
// filter
return [
...array.filter((value: any, n: any) => {
@sonbyungjun
sonbyungjun / duplicateCheck.ts
Created June 2, 2020 02:32
TypeScript(Javascript) duplicateCheck Function (ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ(์ž๋ฐ”์Šคํฌ๋ฆฝ) ์ค‘๋ณต์ฒดํฌ ํ•จ์ˆ˜)
export function duplicateCheck(array: any[]) {
return array.reduce((t, a) => {
t[a] = (t[a] || 0) + 1;
return t
}, {})
}
@sonbyungjun
sonbyungjun / emailSecurity.ts
Created June 2, 2020 02:33
Typescript(Javascript) Email Security Function (ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ(์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ) ์ด๋ฉ”์ผ ๋ธ”๋Ÿฌ์ฒ˜๋ฆฌ ํ•จ์ˆ˜)
export function emailSecurity(userEmail: string){
const id = userEmail.split('@')[0];
const mail = userEmail.split('@')[1];
const maskingId = function(id: string) {
let splitId = id.substring(0,4);
for(let i = 4; i < id.length; i++) {
splitId += '*';
}
return splitId;
};
@nnnnnoel
nnnnnoel / LineChart.js
Created June 2, 2020 02:36
Line Chart Formula
const getLineChartD = ({ data, size, width, padding, topSpacing }) => {
const min = Math.min(...data);
const max = Math.max(...data);
const d = data
.map((v, i) => {
return `${i === 0 ? 'M' : 'L'} ${(i * (width - padding * 5)) / data.length},${
size - (v / (max - min)) * size + (topSpacing || 0)
}`;
}).join(' ');