Skip to content

Instantly share code, notes, and snippets.

View phuochau's full-sized avatar
👨‍💻

Hau Vo phuochau

👨‍💻
View GitHub Profile
@phuochau
phuochau / transparent-modal-react-navigation.js
Last active April 19, 2019 02:13
Working sample for react-navigation transparent modal in 3.3.0 & support this.props.navigation.dismiss() in screen in Modal Stack
import { createSwitchNavigator, createStackNavigator } from 'react-navigation'
import { StackNavigationOptions } from './Routes.NavigationOptions'
import { getChildComponentNavigationOptions } from './Routes.Utils'
import n from './Routes.Names'
// Stacks
import StartScreen from '../containers/Start'
import GuestStack from './routes/Routes.Guest'
import MainStack from './routes/Routes.MainStack'
@phuochau
phuochau / react-native-view-measurement.js
Last active May 16, 2023 15:09
Best way to measure layout of view in React Native (works in both iOS & Android)
import {
findNodeHandle
} from 'react-native'
this.childItem.measureLayout(findNodeHandle(this.containerWrapper), (x, y, width, height) => {
console.log('got measurement', x, y, width, height)
})

Keybase proof

I hereby claim:

  • I am phuochau on github.
  • I am hauvo (https://keybase.io/hauvo) on keybase.
  • I have a public key ASAYd5F03S5a1iTya8Mbp8y9ptLtOO2hedxc3wjC2dzSfAo

To claim this, I am signing this object:

@phuochau
phuochau / urlUtil.js
Created July 30, 2018 02:08
[JS] Detect links and replace link by another string
export const hasLinks = (str) => {
return str.test(/(?:(?:https?|ftp):\/\/|\b(?:[a-z\d]+\.))(?:(?:[^\s()<>]+|\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))?\))+(?:\((?:[^\s()<>]+|(?:\(?:[^\s()<>]+\)))?\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))?/gi)
}
export const groupLinkIntoAngleBracket = (str, replacedString) => {
return str.replace(/(?:(?:https?|ftp):\/\/|\b(?:[a-z\d]+\.))(?:(?:[^\s()<>]+|\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))?\))+(?:\((?:[^\s()<>]+|(?:\(?:[^\s()<>]+\)))?\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))?/gi, replacedString)
}
@phuochau
phuochau / Deep mutable copy
Created June 11, 2018 10:52 — forked from sdpjswl/Deep mutable copy
Get a deep Mutable copy of NSArray and NSDictionary
+ (NSMutableDictionary *)deepMutableCopyOfDictionary:(NSDictionary *)dictionary
{
return (__bridge_transfer NSMutableDictionary *)CFPropertyListCreateDeepCopy(kCFAllocatorDefault, (__bridge CFDictionaryRef)dictionary, kCFPropertyListMutableContainers);
}
+ (NSMutableArray *)deepMutableCopyOfArray:(NSArray *)array
{
return (__bridge_transfer NSMutableArray *)CFPropertyListCreateDeepCopy(kCFAllocatorDefault, (__bridge CFArrayRef)array, kCFPropertyListMutableContainers);
}
@phuochau
phuochau / Strip-i386-x86_64-in-iOS.sh
Created April 26, 2018 01:15
Strip i386 x86_64 for framework in iOS
APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"
# This script loops through the frameworks embedded in the application and
# removes unused architectures.
find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK
do
FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"
echo "Executable is $FRAMEWORK_EXECUTABLE_PATH"
@phuochau
phuochau / GitHub-Forking.md
Created March 8, 2018 07:51 — forked from Chaser324/GitHub-Forking.md
GitHub Standard Fork & Pull Request Workflow

Whether you're trying to give back to the open source community or collaborating on your own projects, knowing how to properly fork and generate pull requests is essential. Unfortunately, it's quite easy to make mistakes or not know what you should do when you're initially learning the process. I know that I certainly had considerable initial trouble with it, and I found a lot of the information on GitHub and around the internet to be rather piecemeal and incomplete - part of the process described here, another there, common hangups in a different place, and so on.

In an attempt to coallate this information for myself and others, this short tutorial is what I've found to be fairly standard procedure for creating a fork, doing your work, issuing a pull request, and merging that pull request back into the original project.

Creating a Fork

Just head over to the GitHub page and click the "Fork" button. It's just that simple. Once you've done that, you can use your favorite git client to clone your repo or j

@phuochau
phuochau / sample_geo_fire_and_firebase.js
Last active March 6, 2018 04:51
This is an example for Geofire and Firebase
const { user, profiles } = this.state
const swipedProfiles = await this.getSwiped(uid)
const geoFireRef = new GeoFire(firebase.database().ref('geoData'))
const userLocation = [user.geolocation.latitude, user.geolocation.longitude]
const geoQuery = geoFireRef.query({
center: userLocation,
radius: distance
})
geoQuery.on('key_entered', async (uid, location, distance) => {
log(uid + ' at ' + location + ' is ' + distance + 'km from the center')
import React, { Component } from 'react'
import {
View,
InteractionManager
} from 'react-native'
export default class Screen extends Component {
constructor (props) {
super(props)
this.state = {