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:74fe6c753f56ecfed4ee9bf7185189ad
Last active April 8, 2018 07:00
Preventing generation of onPress event of MapView when touching Markers in React Native Maps,
// This issue happened only on iOS.
// In React Native Maps, touching a marker should generate only marker's onPress event.
// However, in iOS, MapView's onPress event is generated with marker's onPress event.
// I solved this issue by referencing this issue: https://github.com/react-community/react-native-maps/issues/758
// React Native Maps 를 사용할 때 iOS에서만 마커를 클릭할 때 MapView의 onPress 이벤트가 같이 발생한다.
// 이 이슈를 해결하기 위해서는 MapView.Marker의 onPress props의 이벤트 핸들러에
// e.stopPropagation(); 을 추가하여 MapView 로 이벤트가 전파되지 않도록 해야 한다.
// Previous code:
@HerbertLim
HerbertLim / gist:f6b26d5235418d37883b1d97a86350e8
Last active June 30, 2018 07:22
Slide in and out animation at React Native
/*
* Not so good way to slide in, show for 4 seconds, and then hide window
*/
Animated.parallel([ // 윈도우를 슬라이드인, 페이드인 한다.
Animated.timing(
this.state.fadeAnim,
{
toValue: 1,
duration: isAndroid ? androidDuration : iosDuration,
easing: Easing.in(),
/*
* Better way to show and hide window
*/
Animated.sequence([
Animated.parallel([ // 윈도우를 슬라이드인, 페이드인 한다.
Animated.timing(
this.state.fadeAnim,
{
toValue: 1,
@HerbertLim
HerbertLim / gist:b39bddf40d987ba24dbe78d7149a8e1d
Created June 30, 2018 07:37
slide in and out animation at React Native (the first bad example)
// the first code
Animated.parallel([ // 윈도우를 슬라이드인, 페이드인 한다.
Animated.timing(
this.state.fadeAnim,
{
toValue: 1,
duration: isAndroid ? androidDuration : iosDuration,
easing: Easing.in(),
useNativeDriver,
@HerbertLim
HerbertLim / gist:c70276317f7be06f9cc886be8b8200e5
Created August 22, 2018 07:29
Common axios.get with timeout in React Native's action creator. This works well at iOS.
export function myActionCreator() {
return async dispatch => {
try {
req = await axios.get(url, {timeout: 4000});
dispatch ({
type: ACTION_TYPE,
payload: req.data,
})
} catch (e) {
@HerbertLim
HerbertLim / gist:48e6a77474bc06c466fede89a30b4ce9
Last active August 22, 2018 07:57
In React Native Android, axios.get should use CancelToken for timeout.
export function myActionCreator() {
return async dispatch => {
const CancelToken = axios.CancelToken
const source = CancelToken.source()
try {
let req = null;
setTimeout(() => {
if (req == null) {
console.log(`Request Timeout with req == null.`)
@HerbertLim
HerbertLim / gist:fe9a5b610a97a6724a90184387340ef6
Last active October 1, 2018 05:11
기상청의 동네예보 조회 (Korea Meteorological Administration's API for three days of weather forecast)
// API Request:
// http://newsky2.kma.go.kr/service/SecndSrtpdFrcstInfoService2/ForecastSpaceData?ServiceKey=SERVICE_KEY
// &base_date=20181001
// &base_time=1100
// &nx=55&ny=127 // NOTE: This is not latitude and longitude. It is KMA defined grid number.
// &_type=json
// &numOfRows=1000
// Response JSON:
{
@HerbertLim
HerbertLim / gist:241375d165e001059e01e9603235eaa3
Created October 1, 2018 05:00
기상청의 초단기실황 조회. 현재 날씨를 알려줌. (Korea Meteorological Administration's API for weather now)
// API Request:
// http://newsky2.kma.go.kr/service/SecndSrtpdFrcstInfoService2/ForecastGrib?ServiceKey=SERVICE_KEY
// &base_date=20181001
// &base_time=1200
// &nx=60&ny=127
// &pageNo=1&numOfRows=20
// &_type=json
// JSON Response:
{
@HerbertLim
HerbertLim / gist:ebccc6362e7526183dfd92261aa7b77a
Created October 1, 2018 05:08
기상청의 초단기예보 조회 (Korea Meteorological Administration's API for three hours of weather forecast)
// API Request:
// http://newsky2.kma.go.kr/service/SecndSrtpdFrcstInfoService2/ForecastTimeData?ServiceKey=SERVICE_KEY
// &base_date=20181001
// &base_time=1230
// &nx=55&ny=127
// &pageNo=1&numOfRows=60
// &_type=json
// JSON Response:
{
@HerbertLim
HerbertLim / gist:a28c490025a45e476862ef6a49f49331
Last active February 11, 2019 06:14
Get UTC hours and minutes from local time format, "08:15"
// parameter hmTime is a string containing 5 characters,
// first two is hours, last to is minutes, which are divied with ':',
// e.g., "08:15", "17:43"
const _ = require('lodash');
function localHhMmToUtc(hmTime) {
const splitted = _.split(hmTime, ':')
const localHours = splitted[0];
const localMinutes = splitted[1];