Skip to content

Instantly share code, notes, and snippets.

View HerbertLim's full-sized avatar

Herbert Lim HerbertLim

  • Korea
View GitHub Profile
@HerbertLim
HerbertLim / gist:2cf57971fd3da927cf5c9633307c0412
Created September 15, 2020 05:26
GuideTips React Native component
import React, {Component} from 'react';
import {
View,
StyleSheet,
TouchableOpacity,
} from 'react-native';
import {
dispRate, isAndroid,
} from '../config';
@HerbertLim
HerbertLim / gist:a3c726b4b43d1e2bd93b26c1ac86ff0b
Created July 20, 2020 08:15
코라이나 API: /trends/daily/agoafter3/{region} 의 리턴 포맷은 어떻게 하는 것이 효율적일까?
// 코라이나의 예전 API가 다음과 같은 객체의 배열을 리턴한다.
// 즉, 날짜별로 데이터를 정리해준 것이다
[
{
"forecast_date": "2020-07-16",
"temp": 21,
"temp_min": 19,
"temp_max": 24,
"humidity": 85,
"sky": 3,
@HerbertLim
HerbertLim / gist:1575a841781cc3b7417ef82c22913657
Created June 22, 2020 08:51
AWS Lambda 에서도 log4js를 사용하기 위한 configuration
// 어떤 프로그램은 상황에 따라 serverless로 실행해야 하다가도 다시 EC2에서 실행해야 할 수도 있다.
// 그런데, EC2에서 실행될 때에는 로그를 별도의 파일에 기록해야 하는 반면, AWS Lambda의 경우는 CloudWatch 에서 확인하면 된다.
// EC2 에서 실행되는 경우에는 log4js 를 통해 로그를 기록하는 것이 좋고,
// AWS Lambda 에서는 기본적으로 console.log 로 출력하는 것이 좋다.
// 2 가지 경우에 대해 유연하게 대처하기 위해서는 AWS Lambda 일 때에도 log4js 를 사용하되
// 아래와 같이 appenders 의 type 을 'console' 로 지정하면, console.log로 출력한 것과 동일해진다
import log4js from 'log4js';
log4js.configure({
appenders: { 'out': { type: 'console', layout: { type: 'messagePassThrough' } } },
@HerbertLim
HerbertLim / gist:c6e51485b6dc690f0d0e73de2d2e6b1c
Created December 29, 2019 10:59
A regular expression when removing space, comman, (, and ) from given string
const newString = _.replace(givenString, /\(|\)|\s|,/g, '')
const newString2 = givenString.replace(/\(|\)|\s|,/g, '')
@HerbertLim
HerbertLim / gist:4a9756e50dbdfd5328a13c1ddb2b6dfc
Created October 12, 2019 00:52
Modified version expo-localization's Localization.js
// caused error when running with iOS Simulator
// because iOS Simulator does not provide locale and timezone
import ExpoLocalization from './ExpoLocalization';
// Web, Android, and some iOS values use `-`. This will convert the iOS values that use `_`
// https://github.com/expo/expo/blob/21ae94bae2e8369992050c433a00699d425b35bd/packages/expo/src/Localization.ts#L112-L114
const parseLocale = (locale) => locale.replace('_', '-'); <-- Original
const parseLocale = (locale) => {if (!locale) return null; return locale.replace('_', '-')}; <-- Modified
@HerbertLim
HerbertLim / gist:25f0ffb31162dbf0e97e602ba2d01379
Created September 22, 2019 05:54
Simple example of converting CSV to JSON object
import parse from 'csv-parse/lib/sync';
import fs from 'fs'
const csv = fs.readFileSync('src/countries.csv')
const records = parse(csv.toString('utf-8'), {
columns: true,
skip_empty_lines: true
})
fs.writeFileSync('src/countrycode.js', JSON.stringify(records, null, 2))
@HerbertLim
HerbertLim / gist:2c15700a17611f42eb650e6e5dbf79f1
Created September 22, 2019 05:44
JSON object including country name, ISO codes, telephone code, area (km2), GDP(USD), and population.
// Original data from https://countrycode.org/
// I translated the table to csv, and then converted csv to JSON by using csv-parse.
[
{
"name": "Afghanistan",
"telCode": "93",
"population": "29,121,286",
"area": "647,500",
"gdp": "20.65 Billion",
@HerbertLim
HerbertLim / gist:0fc695ab231f15896861e7b4a632d6d8
Created September 13, 2019 04:35
Get max available ID by using DynamoDB: increase an attribute value at a DynamoDB table and returns increased value.
// MY_META DynamoDB table has a primary key "name" and a attribute "value"
// Added a record with "lastUsedSid" as name, and a Number as value.
export function getNextValidSid (callback) {
const params = {
TableName: MY_META,
Key: {
'name': 'lastUsedSid',
},
UpdateExpression: 'set #v = #v + :val',
@HerbertLim
HerbertLim / gist:cf1d08a2d2a103bcfbc1802057daf509
Created September 1, 2019 05:16
Japan's regions and prefectures as JSON object
// Reference: https://en.wikipedia.org/wiki/Prefectures_of_Japan#By_English_name
[
{
name: 'Hokkaido',
jpName: '北海道',
id: '01',
prefs: [ // prefs means Prefectures
{
name: 'Hokkaido',
@HerbertLim
HerbertLim / gist:579f67c99a328247f95cccf18f80aa77
Created September 1, 2019 01:52
.babelrc for async/await (babel 7 with 4 packages: @babel/core @babel/cli @babel/preset-env @babel/node)
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "10"
}
}
]