Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / git-backup.sh
Last active October 25, 2018 11:00
Backup git working status
#!/bin/bash
### Backup git working status
# Backup modified and untracked files without ignored ones in any git working directory. The destination is required and will be created automatically if not exists.
#
# Usage:
# ./git-backup [destination path]
# Ex:
# ./git-backup ~/backup20130101
#
# Note: Mac users have to install GNU Coreutils to support `--parents` of cp command
@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 / cssSelectorPriority.md
Last active February 27, 2018 14:34
css selector priority

css selector priority

priority selector example
1 inline style in html tag <div style="color:red">
2 tag#id div#myID { color:red; }
3 #id .myID { color:red; }
4 tag.class div.myClass { color:red; }
5 .class .myClass { color:red; }
6 tag div { color:red; }
@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 / 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 / cors.html
Created October 25, 2013 09:18
Load external image with CORS to convert image to DataURI and draw content into HTML5 canvas. Note: Image element should be created by javascript. Loading image with <img> tag does not works!
<html>
<body>
Load external CORS image into the canvas below:<br>
<canvas id="c"></canvas><br>
Convert canvas to DataUri then set as source of the image below:<br>
<img id="img" /> <br>
<div id="results"></div>
<script>
var c = document.getElementById('c');
var ctx = c.getContext('2d');