Skip to content

Instantly share code, notes, and snippets.

View terrywang's full-sized avatar

Terry Wang terrywang

View GitHub Profile
@terrywang
terrywang / vcheck.c
Last active August 29, 2015 13:56
Check Linux VM hardware assisted virtualization type {Xen HVM,KVM,VMware}. Based on the C program written by http://www.vpsee.com
/*
* Use CPUID opcode from EAX register to determine Linux VM Virtualization type {Xen HVM,KVM,VMware}
* Based on the c program written by http://www.vpsee.com ;-)
*/
#include <stdio.h>
#include <string.h>
#define HYPERVISOR_INFO 0x40000000
#define CPUID(idx, eax, ebx, ecx, edx) \
@terrywang
terrywang / rsync.rb
Last active November 2, 2016 17:15
rsync Homebrew formula for OS X, with fileflags, crtimes and hfs-compression patches. May be merged to https://github.com/Homebrew/homebrew-dupes soon ;-)
require 'formula'
class Rsync < Formula
homepage 'http://rsync.samba.org/'
url 'http://rsync.samba.org/ftp/rsync/src/rsync-3.1.0.tar.gz'
sha1 'eb58ab04bcb6293da76b83f58327c038b23fcba3'
depends_on :autoconf
def patches
@terrywang
terrywang / Berkshelf
Last active October 25, 2019 23:20
Vagrantfile sample for Vagrant, the following plugins are required: vagrant-berkshelf, vagrant-omnibus, vagrant-proxyconf, vagrant-vbguest, vagrant-proxyconf. Berksfile defines cookbooks and their dependencies. Run berks install to install cookbooks and dependencies.
site :opscode
cookbook 'nginx', '~> 2.4.4'
@terrywang
terrywang / jdk.sh
Last active March 27, 2019 05:33
Oracle JDK Download Script, the magic cookie comes from oab-java6 ;-) It **ONLY** works for latest Oracle JDK 7 and 8 update releases.
#!/bin/bash
# --------------------------------------
#
# Title: Oracle JDK Download Script
# Author: Terry Wang
# Email: i (at) terry (dot) im
# Homepage: http://terry.im
# File: jdk.sh
# Created: 28 August, 2013
#
@terrywang
terrywang / .bashrc
Last active December 6, 2023 08:52
Bash 5.2.x dot files for Linux and macOS, extracted from Ubuntu which by default does NOT use $HOME/.bash_profile for interactive login shells.
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
# [ -z "$PS1" ] && return
case $- in
*i*) ;;
*) return;;
esac
@terrywang
terrywang / chef_solo_bootstrap.sh
Last active December 14, 2015 10:10 — forked from ryanb/chef_solo_bootstrap.sh
Chef Solo bootstrap script using rbenv and ruby-build.
#!/bin/bash
# --------------------------------------
#
# Title: Chef Solo Bootstrap
# Author: Terry Wang
# Email: i (at) terry (dot) im
# Homepage: http://terry.im
# File: bootstrap-ubuntu.sh
# Created: Feb, 2013
#
@terrywang
terrywang / iptables.rules
Last active December 11, 2015 12:38
Generic iptables rules template, ready to be used;-)
*filter
# Allow all loopback (lo) traffic and drop all traffic to 127.0.0.0/8 that doesn't use lo
-A INPUT -i lo -j ACCEPT
-A INPUT -d 127.0.0.0/8 -j REJECT
# Accept all established inbound connections
# -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# conntrack match is recommended
-A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
# Allow all outbound traffic
# It can be modified to allow certain traffic ONLY
@terrywang
terrywang / dumpAccountImage.sh
Last active March 26, 2017 10:04
Extract / dump Mac OS X user account picture using dscl (Directory Service command line utility) and convert (hexdump into binary) it to to a JPEG file. NOTE: The resolution can vary depending on the original size of the photo and what version of the operating system you're using when it is saved.
dscl . -read /Users/username JPEGPhoto | tail -1 | xxd -r -p > /path/to/accountImage.jpg
@terrywang
terrywang / wiki_backup.sh
Last active December 9, 2015 20:39
Wiki backup script, use mysqldump to dump confluence wiki database, pipe it to xz for compression and then pipe to pv to display progress and finally > wiki.xz
#!/bin/sh
# One liner
# mysqldump to stdout, pipe to xz for compression and then pipe to pv redirect to xz file
# pv is OPIONTAL, it is for showing the progress ONLY
# The - after xz -z is OPTIONAL, by default xz reads from stdin and writes to stdout
mysqldump -u confluenceuser -ppassword confluence | xz -z | pv > wiki_$(date +"%Y%m%d").xz
# Other 2 equivalant variants
# mysqldump -u confluenceuser -ppassword confluence | xz -z | > wiki_$(date +"%Y%m%d").xz
@terrywang
terrywang / iptables.rules
Last active October 13, 2015 22:07
iptables rules for the Confluence wiki box
*filter
-P INPUT DROP
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT