Skip to content

Instantly share code, notes, and snippets.

View phuochau's full-sized avatar
👨‍💻

Hau Vo phuochau

👨‍💻
View GitHub Profile
@phuochau
phuochau / config-arc-s3-for-phoenix.exs
Last active April 19, 2019 02:15
Configure Arc S3 for Phoenix project
config :arc,
virtual_host: true,
version_timeout: 60_000, # milliseconds
bucket: System.get_env("AWS_S3_BUCKET")
config :ex_aws,
access_key_id: [System.get_env("AWS_ACCESS_KEY_ID"), :instance_role],
secret_access_key: [System.get_env("AWS_SECRET_ACCESS_KEY"), :instance_role],
region: System.get_env("AWS_S3_REGION")
@phuochau
phuochau / custom-reducer-for-react-navigation.js
Last active April 19, 2019 02:14
Custom Reducer for ReactNavigation
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { addNavigationHelpers } from 'react-navigation';
import { createStore, combineReducers, applyMiddleware } from 'redux';
import { connect, Provider } from 'react-redux';
import { composeWithDevTools } from 'remote-redux-devtools';
import reducers from './redux/reducers';
import middlewares from './redux/middlewares';
// create redux store and async configuration
import React, { Component } from 'react'
import {
View,
InteractionManager
} from 'react-native'
export default class Screen extends Component {
constructor (props) {
super(props)
this.state = {
@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')
@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 / 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 / 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 / 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)
}