Skip to content

Instantly share code, notes, and snippets.

View ngoclt's full-sized avatar
:octocat:
High motivation

Nick Le ngoclt

:octocat:
High motivation
  • Helsinki
View GitHub Profile
@ngoclt
ngoclt / Test.ts
Last active January 20, 2020 08:47
const refreshAuthLogic = (failedRequest) => {
const refreshToken = (response) => {
actions.auth.signInAsync.success(response);
actions.userSetting.saveUserSettingAsync.request({
session: { uid: response.uid, token: response.token },
});
failedRequest.response.config.headers.Authorization =
'Bearer ' + response.token;
};
@ngoclt
ngoclt / AsyncStorageGenericUtils.ts
Created December 3, 2019 13:05
Generic functions for loading and saving values with AsyncStorage in React Native.
import {AsyncStorage} from 'react-native';
export function setValue(key: string, value: any): Promise<void> {
return AsyncStorage.setItem(key, JSON.stringify(value));
}
export function getValue<T>(key: string, defaultValue: T = null): Promise<T> {
return new Promise((resolve, reject) => {
AsyncStorage.getItem(key).then((value) => {
if (value !== null) {
@ngoclt
ngoclt / Genrics+CellReuse.swift
Created April 29, 2019 12:31 — forked from dubemike/Genrics+CellReuse.swift
An easier way to dequeue cells in iOS
import Foundation
import UIKit
public protocol ReusableView: class {
static var defaultReuseIdentifier: String { get }
}
extension ReusableView where Self: UIView {
public static var defaultReuseIdentifier: String {
return String(describing: self)
}
@ngoclt
ngoclt / localizable-sheet-script.gs
Last active January 30, 2020 12:38
This script is used for generating localizable file for iOS and android. It needs to be added as a Custom Export for Google Spreadsheet file
/*
localizable-sheet-script
A Google Sheets script that will take a sheet in a specific format and return iOS and Android localization files.
https://github.com/cobeisfresh/localizable-sheet-script
Created by COBE http://cobeisfresh.com/ Copyright 2017 COBE
Customized by Ngoc LE
License: MIT
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULA
@ngoclt
ngoclt / LocalizableString.swift
Last active April 17, 2019 11:48
A good way to manage localized string with swift
extension String {
func localized(tableName: String = "Localizable") -> String {
return NSLocalizedString(self, tableName: tableName, value: "**\(self)**", comment: "")
}
}
protocol Localizable {
var tableName: String { get }
var localized: String { get }
}
@ngoclt
ngoclt / checkVersion.js
Created June 2, 2012 08:15
Check iOS version with Javascript
checkVersion = function () {
var agent = window.navigator.userAgent,
start = agent.indexOf( ‘OS ‘ );
if( ( agent.indexOf( ‘iPhone’ ) > -1 || agent.indexOf( ‘iPad’ ) > -1 ) && start > -1 ){
return window.Number( agent.substr( start + 3, 3 ).replace( ‘_’, ’.’ ) );
}
return 0;
}