Skip to content

Instantly share code, notes, and snippets.

View schnell18's full-sized avatar

Justin Zhang schnell18

View GitHub Profile
@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 / get_scriptpath.sh
Created February 26, 2014 03:26
Get absolute script path regardless how it is called in bash. Reference: http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
SCRIPTPATH=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
@schnell18
schnell18 / make_crt_test.sh
Last active September 7, 2024 18:10
Generate a 2048-bit RSA key, create certificate sign request and self-sign the certificate for testing purpose
openssl genrsa -out server.key 2048
openssl req -new -key server.key -out server.csr
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
@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