Skip to content

Instantly share code, notes, and snippets.

@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"
@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 / 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 / gist:5081427
Created March 4, 2013 10:42
Use jQuery to adjust height of iframe according to height of content
// execute script inside iframe
$('#iframe', parent.document).height($(document.body).outerHeight());
@mjj2000
mjj2000 / md5.sh
Last active December 14, 2015 11:49
Generate md5 hash of source string typed by user
# generate md5 hash of source string typed by user
echo -n 'source string:'
read str
echo -n $str | md5sum
@mjj2000
mjj2000 / sed.wc-l.sh
Last active December 14, 2015 11:49
Simulate "wc -l" by sed
# simulate "wc -l" by sed
sed -n '$='
@mjj2000
mjj2000 / center-div-in-div.html
Created May 21, 2013 03:23
[CSS]Center div in div
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<style>
#table{
display:table; /* must be 'table' */
}
#table-cell{
position:relative; /* must be 'relative' */
width:500px; /* must be assigned an absolute value */
@mjj2000
mjj2000 / findNgrep.sh
Last active December 18, 2015 17:49
A shell script to do find and grep.
# arg-1: filename pattern for "find"
# arg-2: content pattern for "grep"
# note: If filename pattern contains wildcard, it should be escaped.
# Or the matched files only in the current path will be the result. Other matched files
# will not be included in the result.
# ex:
# > findNgrep.sh \*.php test
#
find . -name "$1" -exec grep -wnH "$2" {} \;
@mjj2000
mjj2000 / gist:5869097
Last active December 19, 2015 00:29
Show current git branch and state in command line prompt
1. Download git-prompt.sh and saved as hidden file .git-prompt.sh
curl -L https://raw.github.com/git/git/master/contrib/completion/git-prompt.sh -o ~/.git-prompt.sh
2. apply git-prompt and insert branch variable $(__git_ps1) in prompt in your shell configuration file (ex: ~/.bashrc)
# colors
MAGENTA="\[\033[0;35m\]"
YELLOW="\[\033[0;33m\]"
@mjj2000
mjj2000 / _datauri-bg.scss
Last active December 21, 2015 16:38
A scss mixin that convert background images from original URL path to DataURI with IE6-8 fallback.
/*
A scss mixin that convert background images from original URL path to DataURI with IE6-8 fallback.
- Based on `compass/css3/images`
- Support 1-10 background image(s) as arguments of `background-image` in compass.
- Use class `lt-ie9` in `<html>` tag as `html5-boilerplate` to determine if current browser is IE6-8 or not.
- Image created by `linear-gradient` will be skipped.
# Example