Skip to content

Instantly share code, notes, and snippets.

@wbingli
wbingli / download_big_file.rb
Created May 1, 2014 22:32
Download big file with ruby and basic authentication
require 'net/http'
require 'uri'
def downloadFile(filePath, url,username, password)
uri = URI(URI.encode(url))
Net::HTTP.start(uri.host,uri.port) do |http|
request = Net::HTTP::Get.new uri.path
request.basic_auth username,password
@wbingli
wbingli / setup-bridge.sh
Created April 15, 2014 20:52 — forked from ismell/setup-bridge.sh
To change the default network for docker
#!/bin/bash -e
IFADDR="192.168.3.1/24"
if [[ ! ip link show docker0 ]]; then
ip link add docker0 type bridge
ip addr add "$IFADDR" dev docker0
ip link set docker0 up
iptables -t nat -A POSTROUTING -s "$IFADDR" ! -d "$IFADDR" -j MASQUERADE
fi
@wbingli
wbingli / add_search_to_resolv.sh
Last active August 29, 2015 13:58
Append a search path to /etc/resolv.conf
if ! grep -q 'test.com' /etc/resolv.conf
then
sed -i "s/`grep search /etc/resolv.conf`/`grep search /etc/resolv.conf` test.com/" /etc/resolv.conf
fi
@wbingli
wbingli / merge_repos.sh
Created April 1, 2014 20:28
Merge multiple repositories into one, keep all commit history
mkdir ~/tdv-core
cd ~/tdv-core
#clone all repos
git clone [email protected]:tdigital-ondemand/tdv-core.git
#Clone parent firstly
git clone [email protected]:tdigital-ondemand/parent.git
cd parent
git checkout dev
@wbingli
wbingli / mod_security_get_only
Created March 25, 2014 04:45
Mod security rule to only allow GET for specified request path
SecRule REQUEST_URI "/getonly" "chain,log,deny,status:403,phase:2,id:1234567010"
SecRule REQUEST_METHOD "!@rx ^(?:GET)$"
@wbingli
wbingli / renmae_lowercase_recursive
Created July 24, 2013 03:53
Change all file and directory name to lowercase
find . -name '*[A-Z]*' -print0 | xargs -0 rename 'y/A-Z/a-z/'
@wbingli
wbingli / winrm-https.bat
Created July 12, 2013 00:03
Windows: Import certificate and configure WinRM HTTPS and IIS HTTPS bindings
REM Check certificates
certutil -store MY
REM Import cert
certutil -p PASSWORD -ImportPFX CERT_PATH
REM Check winrm listners
winrm e winrm/config/listener
REM delete if it exists
@wbingli
wbingli / migration.erb
Last active December 19, 2015 06:49
Chef migration template for Windows
cmd.exe /C del C:\chef\validation.pem
cmd.exe /C del C:\chef\client.rb
cmd.exe /C del C:\chef\client.pem
> C:\chef\validation.pem (
<%= validation_key %>
)
> C:\chef\client.rb (