Skip to content

Instantly share code, notes, and snippets.

View Elevista's full-sized avatar

Elevista

  • Yanolja
  • Seoul
View GitHub Profile
@Elevista
Elevista / Deferred.js
Last active November 7, 2017 02:14
ES6-Defer
export function Deferred () {
this.promise = new Promise((resolve, reject) => Object.assign(this, {resolve, reject}))
}
@Elevista
Elevista / vueLodashArray.js
Last active December 19, 2017 16:36
lodash로 vue 모델의 배열을 다룰때 뮤테이션 감지를 시키기 위해 기본 함수를 래핑합니다.
let lodash = _.runInContext()
export let wrapLodashArrForVue = _(['pull', 'pullAll', 'pullAllBy', 'pullAllWith', 'pullAt', 'remove'])
.map(fnName => {
let fn = lodash[fnName]
return [
fnName,
function (v, …args) {
let ret = fn(v, …args)
if (v instanceof Array) v.push()
return ret
@Elevista
Elevista / seq.js
Last active January 9, 2018 04:09
seq(1)(fn1)(fn2)(fn3).value
const _ = require('lodash')
function isPromise(result) {
return result && (typeof result.then === 'function')
}
function seq(init) {
let result = typeof init === 'function' ? init() : init
let properties = {value: {get() { return result }}}
_.forEach(['then', 'catch', 'finally'], x => { properties[x] = {get() { return (...args) => result[x](...args) }} })
@Elevista
Elevista / decodeEntities.js
Created April 21, 2020 04:41
Decode HTML entities
const entities = {
lt: '<',
gt: '>',
amp: '&',
quot: '"',
apos: `'`,
cent: '¢',
pound: '£',
yen: '¥',
euro: '€',
function dfsXyConv (code, v1, v2) {
const { PI, tan, log, cos, pow, floor, sin, sqrt, atan, abs, atan2 } = Math
//
// LCC DFS 좌표변환을 위한 기초 자료
//
const RE = 6371.00877 // 지구 반경(km)
const GRID = 5.0 // 격자 간격(km)
const SLAT1 = 30.0 // 투영 위도1(degree)
const SLAT2 = 60.0 // 투영 위도2(degree)
const OLON = 126.0 // 기준점 경도(degree)
const htmlparser2 = require('htmlparser2')
const define = (src, ...args) => {
if (!args.length) args.push(src)
const [configurable, enumerable] = [true, false]
args.forEach(obj => {
const keys = Object.entries(obj)
.map(([key, value]) => ({ [key]: { value, configurable, enumerable } }))
Object.defineProperties(src, Object.assign(...keys))
})
return src