Skip to content

Instantly share code, notes, and snippets.

@mjj2000
mjj2000 / heredoc.js
Created April 26, 2019 09:28
Heredoc for Javascript
// assign html string value with easy-to-ready format
const html = (function() {/* This line will be removed!!!!
<div>
hello world!!!
</div>
This line will be removed!!!! */}).toString().split('\n').slice(1,-1).join('\n');
@mjj2000
mjj2000 / hasBig5.php
Last active September 5, 2018 05:09
Check if string has any big5 character in PHP
<?php
function isBig5Char ($char) {
if (strlen($char) < 2)
return false;
$byte1hex = dechex(ord($char[0]));
$byte2hex = dechex(ord($char[1]));
$number = hexdec($byte1hex . $byte2hex);
return (
0x8140 <= $number &&
@mjj2000
mjj2000 / copy-local-ip.sh
Created May 23, 2017 10:29
Copy local ip address to clipboard in OS X
#!/bin/bash
#
# copy local ip address to clipboard
# this script is only for OS X
echo -n `ifconfig en0 | awk '$1 == "inet" {print $2}'` | pbcopy
@mjj2000
mjj2000 / get-current-git-tag.sh
Last active April 1, 2024 01:11
[GIT] Get tag of current branch(that is HEAD) or fallback to short commit hash(7 digits) by single shell command
git describe --exact-match --tags 2> /dev/null || git rev-parse --short HEAD
@mjj2000
mjj2000 / cd-nvm.sh
Last active August 8, 2016 04:08
Switch to target node version of project by nvm automatically(only when .nvmrc exist in current folder)
# put this snippet in your shell config(ex: ~/.bashrc, ~/.zshrc, ...)
# make sure `.nvmrc` exsits in your project folder
function init-node {
# switch node version by nvm after changing folder without AVN
if [[ -f ".nvmrc" ]]; then
# initialize nvm if necessary
if [[ -z $(nvm 2>/dev/null) ]]; then
# nvm is not initailized
echo 'initialize nvm ...'
source ~/.nvm/nvm.sh
@mjj2000
mjj2000 / eject.sh
Created April 26, 2016 03:09
Unmount specified storage in Mac OS X
# this script is only for Mac OS X
# ex: eject.sh /Volumes/MyDisk
diskutil unmount $1
@mjj2000
mjj2000 / self.sh
Last active May 8, 2023 15:04
Shell script to get full folder path of itself
if [ -L $0 ] ; then
BASEDIR=$(cd "$(dirname "$(readlink $0)")"; pwd -P) # for symbolic link
else
BASEDIR=$(cd "$(dirname "$0")"; pwd -P) # for normal file
fi
@mjj2000
mjj2000 / screen.md
Created June 17, 2015 07:15
Sudo as different user and running screen

Add this function screen in ~/.bashrc to avoid error as below:

Cannot open your terminal '/dev/pts/0' - please check.

function screen() {
  /usr/bin/script -q -c "/usr/bin/screen ${*}" /dev/null
}
@mjj2000
mjj2000 / gerrit-push.sh
Created April 22, 2015 03:42
GIT push to Gerrit for current branch
#!/bin/bash
# git push to gerrit for current branch
branch_name=$(git symbolic-ref -q HEAD)
branch_name=${branch_name##refs/heads/}
branch_name=${branch_name:-HEAD}
git push origin HEAD:refs/for/$branch_name
@mjj2000
mjj2000 / gist:db8cde516af0f97f5e1f
Last active August 29, 2015 14:08
A command alias to trigger quick look of target files in Mac OS X
alias qlook="qlmanage -p 2>/dev/null"