Skip to content

Instantly share code, notes, and snippets.

@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 / 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');
@mjj2000
mjj2000 / gist:6337698
Last active December 21, 2015 16:59
Round avatar with CSS3
/* Configure by modifying variables:
$round-width: size of round avatar
$avatar-image: image path of ravatar
*/
div.round-avatar{
$round-border-size: 5px;
$round-border-color: #fff;
$round-width: 100px;
$round-height: $round-width;
$avatar-image: url('//goo.gl/Nw9pE2');
@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
@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 / 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 / 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 / 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 / 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 / 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