Skip to content

Instantly share code, notes, and snippets.

View hungtrinh's full-sized avatar

Hưng Trịnh hungtrinh

  • Ha Noi, Viet Nam
View GitHub Profile
@hungtrinh
hungtrinh / index.jsx
Created March 15, 2019 09:25 — forked from avinmathew/index.jsx
Multiple layouts with React Router v4
import React from "react"
import { Route, Switch } from "react-router-dom"
const AppRoute = ({ component: Component, layout: Layout, ...rest }) => (
<Route {...rest} render={props => (
<Layout>
<Component {...props} />
</Layout>
)} />
)
@hungtrinh
hungtrinh / introrx.md
Created February 26, 2019 17:32 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@hungtrinh
hungtrinh / launch.json
Last active August 21, 2018 09:46
xdebug remote vscode config
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug - Remote",
"type": "php",
"request": "launch",
"port": 9000,
"pathMappings": {
"/var/www/html/your_app_on_server": "${workspaceFolder}",
@hungtrinh
hungtrinh / bitwise-permission-checking.php
Created April 10, 2018 07:00
Check permission using bitwise operators
Initially, I found bitmasking to be a confusing concept and found no use for it. So I've whipped up this code snippet in case anyone else is confused:
<?php
// The various details a vehicle can have
$hasFourWheels = 1;
$hasTwoWheels = 2;
$hasDoors = 4;
$hasRedColour = 8;
@hungtrinh
hungtrinh / pre-commit
Created March 7, 2017 10:23 — forked from mklabs/pre-commit
run jshint as git/hg hooks, NO COMMIT IF NO LINT FREE.
#!/usr/bin/env node
// todo: try to require jshint here, instead of spawning process, then fallback to spawning process.
var jshint = nrequire('jshint');
if (jshint) return process.exit(0);
// jshint not installed locally, spawn process instead.
// basically the same, but less pretty.
var exec = require('child_process').exec;
@hungtrinh
hungtrinh / Vagrantfile
Created March 1, 2017 13:21
Vagrant configuration file with OS detection - on windows we mount shared folders without NFS - on all other OS we use NFS for speeding up the project inside the virtual machine
# -*- mode: ruby -*-
# vi: set ft=ruby :
module OS
def OS.windows?
(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
end
def OS.mac?
(/darwin/ =~ RUBY_PLATFORM) != nil
@hungtrinh
hungtrinh / regex-japanese.txt
Created January 17, 2017 03:29 — forked from terrancesnyder/regex-japanese.txt
Regex for Japanese
Regex for matching ALL Japanese common & uncommon Kanji (4e00 – 9fcf) ~ The Big Kahuna!
([一-龯])
Regex for matching Hirgana or Katakana
([ぁ-んァ-ン])
Regex for matching Non-Hirgana or Non-Katakana
([^ぁ-んァ-ン])
Regex for matching Hirgana or Katakana or basic punctuation (、。’)
@hungtrinh
hungtrinh / git commands.txt
Created June 30, 2016 04:00 — forked from kmorcinek/git commands.txt
Git Commands. My common scenarios for using git.
# good git book
http://git-scm.com/book
# Discard uncommitted changes in a specific file
git checkout file_name
# Clear everything not in repo
git checkout -- .
# A way to quickly move to the previous commit in a git branch. This also way for "deleting" last commit.
@hungtrinh
hungtrinh / bobp-python.md
Created December 2, 2015 02:41 — forked from sloria/bobp-python.md
A "Best of the Best Practices" (BOBP) guide to developing in Python.

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General

Values

  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens
@hungtrinh
hungtrinh / shiftjis-csv.rb
Created November 18, 2015 07:03 — forked from gotwalt/shiftjis-csv.rb
Convert a CSV file to Shift-JIS for use in Japanese versions of Microsoft Excel in ruby-1.8.7
require "iconv"
encoding = "SHIFT-JIS"
# Open a file for writing in the Shift-JIS format
File.open("output.csv", "w:#{encoding}") do |io|
# Read the CSV file, and convert CRs to CRLFs.
csv = File.open("input.csv").read.gsub("\r", "\r\n")
# Convert the CSV to the correct encoding
io.write Iconv.iconv(encoding, "UTF-8", csv).join
end