Skip to content

Instantly share code, notes, and snippets.

View tranquan's full-sized avatar
🥝
kiwi

Tran Quan tranquan

🥝
kiwi
View GitHub Profile
@tranquan
tranquan / .bash_profile_for_windows
Created May 27, 2022 22:35
Bash profile for windows
# Git alias
alias ls='ls -F --color=auto --show-control-chars'
alias ll='ls -l'
alias g='git'
alias gg='git push'
alias ggf='git push --force-with-lease'
alias gp='git pull'
alias gf='git fetch'
alias gfa='git fetch --all --prune'
alias gcb='git checkout -b'
@tranquan
tranquan / CountryPickerApp.tsx
Last active September 26, 2024 05:02
Strong typed-check event listener, can be use to passing callback between scenes with react-navigation
import { StatusBar } from "expo-status-bar";
import React from "react";
import { StyleSheet, Text, View } from "react-native";
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import ProfileScene from "./ProfileScene";
import CountryPickerScene from "./CountryPickerScene";
const Stack = createNativeStackNavigator();
@tranquan
tranquan / vscode_keybindings.json
Created November 18, 2021 21:47
Key bindings for vscode with vim
// Place your key bindings in this file to override the defaults
[
{
"key": "ctrl+shift+k",
"command": "workbench.action.terminal.focus"
},
{
"key": "ctrl+shift+k",
"command": "-editor.action.deleteLines",
"when": "textInputFocus && !editorReadonly"
@tranquan
tranquan / client.ts
Created August 5, 2021 20:06
A simple API client for react, react-native
import { handleError } from "./errorHandler";
import { stringify } from "qs";
let BASE_URL = "http://localhost:8000/api/";
interface ClientConfig {
baseUrl?: string;
}
export function configureClient(configs: ClientConfig) {
@tranquan
tranquan / eventEmitter.ts
Last active August 5, 2021 20:07
A simple way to broardcast message in react app, use for low level layer to communicate with higher level (app/ui layer)
/**
* A simplify version of https://github.com/primus/eventemitter3
*/
const listenersMap: { [id: string]: Array<(...params: any[]) => void> } = {};
function addListener(eventName: string, listener: (...params: any[]) => void) {
listenersMap[eventName] = listenersMap[eventName] || [];
listenersMap[eventName].push(listener);
}
@tranquan
tranquan / xcode-keybindings-as-vscode.md
Last active October 28, 2024 01:50
Xcode KeyBindings as VSCode
@tranquan
tranquan / LoginItemsUtil.swift
Created December 20, 2020 15:50
Login Service Utils for macOS
// clone from: https://github.com/Clipy/LoginServiceKit/blob/master/Lib/LoginServiceKit/LoginServiceKit.swift
public final class LoginServiceKit: NSObject {}
public extension LoginServiceKit {
static func isExistLoginItems(at path: String = Bundle.main.bundlePath) -> Bool {
return (loginItem(at: path) != nil)
}
@discardableResult
@tranquan
tranquan / promiseAllLimit.ts
Last active May 2, 2020 10:36
Run promise all with limit how many task can run in concurrence
export async function promiseAllLimit<T>(n: number, list: (() => Promise<T>)[]) {
const head = list.slice(0, n);
const tail = list.slice(n);
const result: T[] = [];
const execute = async (promise: () => Promise<T>, i: number, runNext: () => Promise<void>) => {
result[i] = await promise();
await runNext();
};
const runNext = async () => {
@tranquan
tranquan / README.org
Created May 2, 2020 09:10 — forked from jcouyang/README.org
Promise All with Limit of Concurrent N

The Promise All Problem

in case of processing a very large array e.g. Promise.all(A_VERY_LARGE_ARRAY_OF_XHR_PROMISE)

which would probably blow you browser memory by trying to send all requests at the same time

solution is limit the concurrent of requests, and wrap promise in thunk

Promise.allConcurrent(2)([()=>fetch('BLAH1'), ()=>fetch('BLAH2'),...()=>fetch('BLAHN')])

@tranquan
tranquan / ArrayUtil.java
Created February 18, 2020 12:05 — forked from mfmendiola/ArrayUtil.java
ReadableArray and ReadableMap serialization helpers for the React Native—Android bridge.
/*
ArrayUtil exposes a set of helper methods for working with
ReadableArray (by React Native), Object[], and JSONArray.
*/
package com.iodine.start;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReadableArray;