Skip to content

Instantly share code, notes, and snippets.

View pmkhoa's full-sized avatar

Khoa Pham pmkhoa

View GitHub Profile
@pmkhoa
pmkhoa / AsyncComponent.jsx
Last active December 5, 2017 07:11 — forked from lencioni/AsyncComponent.jsx
<AsyncComponent> at Airbnb used for Webpack code splitting
// Usage:
//
// function loader() {
// return new Promise((resolve) => {
// if (process.env.LAZY_LOAD) {
// require.ensure([], (require) => {
// resolve(require('./SomeComponent').default);
// });
// }
// });
describe('<Fragments Rendering/>', () => {
test('React 16 - fragments render', () => {
const Fragments = () => [
<li key="1">First item</li>,
<li key="2">Second item</li>,
<li key="3">Third item</li>,
]
const wrapper = shallow(<Fragments />)
expect(wrapper).toMatchSnapshot()
export default function filterTenants(tenants, search) {
return tenants.filter(tenant => {
let hasFound = false
// For convenient, we allow user to search tenant by name & code
if (
tenant.name.toLowerCase().includes(search) ||
tenant.code.toLowerCase().includes(search)
) {
hasFound = true
$brew install brew install mcrypt php54-mcrypt
Copy default php.ini.default to php.ini
$sudo cp /private/etc/php.ini.default /private/etc/php.ini
Add this line to php.ini file extension section - please verify extension path with install location in your machine
extension="/usr/local/Cellar/php54-mcrypt/5.3.26/mcrypt.so"
Restart your apache server
$apache restart
@pmkhoa
pmkhoa / jquery.deparam.js
Created July 28, 2017 22:21 — forked from samny/jquery.deparam.js
jQuery.deparam - The oposite of jQuery param. Creates an object of query string parameters
/**
* jQuery.deparam - The oposite of jQuery param. Creates an object of query string parameters.
*
* Credits for the idea and Regex:
* http://stevenbenner.com/2010/03/javascript-regex-trick-parse-a-query-string-into-an-object/
*/
(function($){
$.deparam = $.deparam || function(uri){
if(uri === undefined){
uri = window.location.search;
@pmkhoa
pmkhoa / docker-destroy-all.sh
Created June 6, 2017 22:40 — forked from JeffBelback/docker-destroy-all.sh
Destroy all Docker Containers and Images
#!/bin/bash
# Stop all containers
docker stop $(docker ps -a -q)
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi $(docker images -q)
var groupBy = function(xs, key) {
return xs.reduce(function(rv, x) {
(rv[x[key]] = rv[x[key]] || []).push(x);
return rv;
}, {});
};
// Usage
// console.log(groupBy(['one', 'two', 'three'], 'length'));
@pmkhoa
pmkhoa / MySQL_macOS_Sierra.md
Last active April 3, 2017 05:08 — forked from nrollr/MySQL_macOS_Sierra.md
Install MySQL on Sierra using Homebrew

Install MySQL on macOS Sierra

This procedure explains how to install MySQL using Homebrew on macOS Sierra 10.12

Install Homebrew

  • Installing Homebrew is effortless, open Terminal and enter :
    $ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • Note: Homebrew will download and install Command Line Tools for Xcode 8.0 as part of the installation process.

Install MySQL

At this time of writing, Homebrew has MySQL version 5.7.15 as default formulae in its main repository :

@pmkhoa
pmkhoa / .vimrc
Created March 15, 2017 06:32 — forked from Deraen/.vimrc
Vimrc clojure parts
" Parts of my .vimrc which might be relevant to Clojure users.
" Src: https://raw.githubusercontent.com/Deraen/dotfiles/master/.vimrc
" NeoBundle is a Vim package manager
" Check https://github.com/Shougo/neobundle.vim for installation
" Autocomplete - https://github.com/Valloric/YouCompleteMe
NeoBundle 'Shougo/vimproc', {'build': {'unix': 'make'}}
NeoBundle 'Valloric/YouCompleteMe'
" Clojure syntax highlight
@pmkhoa
pmkhoa / letsencrypt-renew.sh
Created October 11, 2016 16:29 — forked from jcjones/letsencrypt-renew.sh
Cron script to renew Let's Encrypt certs using the official client
#!/bin/bash
# This is free and unencumbered software released into the public domain.
#
# This script is designed to be run daily by cron. Please run it with randomness in its timing to
# avoid load spikes at Let's Encrypt. One example, running between midnight at 2 AM, would be:
#
# 0 0 * * * sleep $[(RANDOM % 115)+5]m ; /usr/sbin/letsencrypt-renew.sh
#
# If you aren't using Nginx, adjust the startServer and stopServer methods to suit. Also, you could
# use the webroot method.