Skip to content

Instantly share code, notes, and snippets.

View schnell18's full-sized avatar

Justin Zhang schnell18

View GitHub Profile
@schnell18
schnell18 / mv_master.sh
Created February 14, 2014 01:30
Replace master branch with different name. If you want to set up master branch with a different name, try these commands.
git checkout master
git checkout -b <NEW_NAME_FOR_MASTER>
git symbolic-ref HEAD refs/heads/<NEW_NAME_FOR_MASTER>
git branch -D master
@schnell18
schnell18 / open_pipe_tmpl.pl
Created February 25, 2014 00:47
Code snippet to run external command and get the output in Perl
my $cmd_base = "...";
my @cmd_opts = qw(
...
);
my $cmd_args = "...";
my $cmd = join(" ", $cmd_base, @cmd_opts, $cmd_args);
my $ph;
open($ph, "$cmd |") or do {
warn("Can not run command $cmd due to: $!");
@schnell18
schnell18 / skeleton_rwd.css
Created February 25, 2014 00:50
CSS skeleton for Responsive Web Design
/* Put your reset styles here */
/* Put styles for desktop and basic styles for all devices here */
body {
/* properties for body here */
}
/* medium display only */
@media (min-width: 481px) and (max-width:768px) {
body {
/* properties that only apply to tablets */
@schnell18
schnell18 / redirect_https.conf
Created March 14, 2014 08:20
Apache mod_rewrite rule to redirect insecure http request to https
# Redirect insecure http request from outside of internal network to https
RewriteEngine on
RewriteCond %{HTTPS} !^on$ [NC]
RewriteCond %{REMOTE_HOST} !^100\.2\.[0-9]+\.[0-9]+$
RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1 [R]
@schnell18
schnell18 / auto_rebase_i.sh
Last active August 29, 2015 13:57
Automate git rebase -i to remove selected commits
# Perl onliner is used to delete selected commits from the git rebase -i commit text
# The range of commits includes extra commit to prevent git from doing noop when
# all commits after certain point are to be backed out.
# Some notes on the Perl onliner:
# -n: run the script as specified by -e in the while(<>) loop
# -i: modify the file inplace
# -e: command to run
env GIT_SEQUENCE_EDITOR="perl -ni -e 'print unless /^pick (7d105ae|08fe503|97bf990)/'" git rebase -i <earliest_commit_to_backout>^^
@schnell18
schnell18 / backup.sh
Last active August 29, 2015 13:57
Copy file unless it does not already exist in target
SRC=/mnt/data/src1
TRG=/mnt/data/trg1
IFS=$'\n'
for f in $(ls -1 $SRC)
do
if [[ -d $TRG/$f || -f $TRG/$f ]]; then
echo "$f already exists!"
else
echo "Moving $f..."
@schnell18
schnell18 / flash_raspberry_pi_sd_card.sh
Created April 2, 2014 14:18
Setup Raspberry Pi SD card on MacOS X
diskutil list
diskutil unmountDisk /dev/<disk# from diskutil>
sudo dd bs=1m if=<your image file>.img of=/dev/<disk# from diskutil
@schnell18
schnell18 / expand_openelec_storage.sh
Created April 2, 2014 14:24
Expand the partition to use all SD card space
SSH in as root, by default you’re in /storage; switch to root partition:
$ cd /
Keep XBMC from restarting:
$ touch /var/lock/xbmc.disabled
Stop XBMC, so we can unmount /storage:
$ killall -9 xbmc.bin
$ umount /storage
@schnell18
schnell18 / disable_replicatioin_oe.sh
Created April 3, 2014 01:21
Disable Site replication for OpenEdge database
# OpenEdge/Fathom Replication can be disabled offline by running the following:
# For the sourcedb:
proutil source_db_name -C DisableSiteReplication source
# For the targetdb:
proutil target_db_name -C DisableSiteReplication target
@schnell18
schnell18 / cgit_nginx_enabling
Last active August 29, 2015 13:58
Key config to make cgit work under nginx
# The .css and image files required by CGit should be copied to /var/www/cgit-css
# as nginx concat the matched URI with the document root which is very different
# from Apache's Alias directive.
location /cgit-css {
root /var/www;
index index.html index.htm;
}
# The cgit.cgi program does not work if the whole URI is passed as PATH_INFO.
# Strip the CGI program name from URI and set PATH_INFO to the remaining part,