1. $ < > does not need to be escaped.
2. [ ] & needs to be escaped
3. [a-zA-Z] sometimes can be better accepted than \a (for alphabet)
4. For replacement, & means the matched term
June 6, 2013
May 9, 2013
hg serve multiple projects
To use "hg serve" to serve multiple project internally (with your LAN). Create a file named webconf (it can be any name) with the following content:
[collections]
repos/ = .
[extensions]
hgext.highlight=
[web]
allow_push = *
push_ssl = false
pygments_style = vs
style = gitweb
[collections]
repos/ = .
[extensions]
hgext.highlight=
[web]
allow_push = *
push_ssl = false
pygments_style = vs
style = gitweb
Then in system start up run this:
cd your_hg_directory && sudo -u your-name hg serve --web-conf ./webconf
I like the "gitweb" style because it gives you date on files. The default style is "paper". Other styles can be:
atom
coal
gitweb
monoblue
paper
raw
rss
spartan
May 8, 2013
shrew vpn masquerade on Linux
Once your have your VPN client running on a Linux box, sometimes you would like to share that link with that machines on your LAN (either physical LAN or virtual LAN such as Virtual Machines).
Because shrew uses the kernel IPsec VPN, the iptables masquerade rule does not work on the virtual tap0 interface. There does not seem to exist an easy fix.
The work around I have is to install a linux virtual machine (virtualbox) on the host, which has two NICs, one is NAT, the other one is bridging. Then run iptables masquerade on the virtual Linux, taking traffic from the bridged NIC, and send it out to the NATed NIC. On the host, since virtualbox behaves just like any other application, it is able to access all the VPNed network resources. Bingo!
It works well here. Let me know your thoughts.
Because shrew uses the kernel IPsec VPN, the iptables masquerade rule does not work on the virtual tap0 interface. There does not seem to exist an easy fix.
The work around I have is to install a linux virtual machine (virtualbox) on the host, which has two NICs, one is NAT, the other one is bridging. Then run iptables masquerade on the virtual Linux, taking traffic from the bridged NIC, and send it out to the NATed NIC. On the host, since virtualbox behaves just like any other application, it is able to access all the VPNed network resources. Bingo!
It works well here. Let me know your thoughts.
shrew vpn client on Linux for Cisco Concentrator
To talk to a Cisco VPN Concentrator, one can use "vpnc" or "shrew vpn client".
My vpnc only stays up for a few hours, while on Windows the Cisco VPN client can stay up for days. So I wanted to give shrew a try.
Shrew can import Cisco .pcf configuration file. After that, a connection entry is created. However, you probably will need to modify the profile for it to work. On the "qikea" window, right click on the profile, then "Modify", go to tab "Phase 2" and make your choices instead of auto. For example, try change PFS Group to "2". This worked for many people.
If you are interested, you can try to use the tool "ike-scan" to probe your vpn server and find out exactly the parameters for this tab.
That solved my problem.
The following screenshot is a Windows screenshot, but the Linux one is very similar.

I got the this tip from the following post:
http://www.rhyous.com/2009/10/29/windows-7-64-bit-vpn-client-shrewsoft/
My vpnc only stays up for a few hours, while on Windows the Cisco VPN client can stay up for days. So I wanted to give shrew a try.
Shrew can import Cisco .pcf configuration file. After that, a connection entry is created. However, you probably will need to modify the profile for it to work. On the "qikea" window, right click on the profile, then "Modify", go to tab "Phase 2" and make your choices instead of auto. For example, try change PFS Group to "2". This worked for many people.
If you are interested, you can try to use the tool "ike-scan" to probe your vpn server and find out exactly the parameters for this tab.
That solved my problem.
The following screenshot is a Windows screenshot, but the Linux one is very similar.
I got the this tip from the following post:
http://www.rhyous.com/2009/10/29/windows-7-64-bit-vpn-client-shrewsoft/
April 26, 2013
Text to ASCII Art
Under Linux, use the program "figlet" to turn regular text info a ASCII art text.
Example:
figlet hello
_ _ _
| |__ ___| | | ___
| '_ \ / _ \ | |/ _ \
| | | | __/ | | (_) |
|_| |_|\___|_|_|\___/
figlet -W hello (wide version)
_ _ _
| |__ ___ | | | | ___
| '_ \ / _ \ | | | | / _ \
| | | | | __/ | | | | | (_) |
|_| |_| \___| |_| |_| \___/
You can choose different style too:
figlet -f banner -W hello
# # ###### # # ####
# # # # # # #
###### ##### # # # #
# # # # # # #
# # # # # # #
# # ###### ###### ###### ####
figlet -f bubble -W hello
_ _ _ _ _
/ \ / \ / \ / \ / \
( h ) ( e ) ( l ) ( l ) ( o )
\_/ \_/ \_/ \_/ \_/
Example:
figlet hello
_ _ _
| |__ ___| | | ___
| '_ \ / _ \ | |/ _ \
| | | | __/ | | (_) |
|_| |_|\___|_|_|\___/
figlet -W hello (wide version)
_ _ _
| |__ ___ | | | | ___
| '_ \ / _ \ | | | | / _ \
| | | | | __/ | | | | | (_) |
|_| |_| \___| |_| |_| \___/
You can choose different style too:
figlet -f banner -W hello
# # ###### # # ####
# # # # # # #
###### ##### # # # #
# # # # # # #
# # # # # # #
# # ###### ###### ###### ####
figlet -f bubble -W hello
_ _ _ _ _
/ \ / \ / \ / \ / \
( h ) ( e ) ( l ) ( l ) ( o )
\_/ \_/ \_/ \_/ \_/
Use "figlist" to list all the styles.
April 10, 2013
Fix: vim indent not working
If you loaded a new indent file or syntax file under ~/.vim/ and it is not taking effect, make sure you have the following line in your ~/.vimrc file:
filetype plugin indent on
filetype plugin indent on
This turns on filetype detection, filetype plugin, and filetype-indent.
April 1, 2013
how to mount vdi
First install lvm2, ndb and qemu-common packages:
Then run this to load the nbd module:
And connect the device:
Load the dm-mod module:
Run this command to scan for volume groups:
This will output something like this:
In the next step we want to use what is in the quotes above. Run this command but replace vg_centos with whatever shows in the quotes.
Then show which partitions there are:
This will output something like this:
In this case we want the logical volume named lv_root so run this command:
Now you should be able to find your disk in the /mnt/vdi folder. Note that you must have created the /mnt/vdi folder first but you can mount it wherever you like into an empty folder.
This command will disconnect the nbd:
After you disconnect the nbd you can unload the module:
Code
yum install lvm2 nbd qemu-common
Then run this to load the nbd module:
Code
modprobe nbd max_part=16
And connect the device:
Code
qemu-nbd -c /dev/nbd0 "/home/USER/VirtualBox VMs/CentOS6/CentOS6.vdi"
Load the dm-mod module:
Code
modprobe dm-mod
Run this command to scan for volume groups:
Code
vgscan
This will output something like this:
Reading all physical volumes. This may take a while...
Found volume group "vg_centos" using metadata type lvm2
In the next step we want to use what is in the quotes above. Run this command but replace vg_centos with whatever shows in the quotes.
Code
vgchange -ay vg_centos
Then show which partitions there are:
Code
lvs
This will output something like this:
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
lv_root vg_centos -wi-a- 18.12g
lv_swap vg_centos -wi-a- 1.97g
In this case we want the logical volume named lv_root so run this command:
Code
mount /dev/vg_centos/lv_root /mnt/vdi -o ro,user
Now you should be able to find your disk in the /mnt/vdi folder. Note that you must have created the /mnt/vdi folder first but you can mount it wherever you like into an empty folder.
Some more useful tips.
You can unmount the disk:Code
umount /mnt/vdi
This command will disconnect the nbd:
Code
qemu-nbd -d /dev/nbd0
After you disconnect the nbd you can unload the module:
March 29, 2013
tip: embed raw text in html
it's become somewhat au courant to use the "type" attribute to mark
<script> blocks that you don't want to be evaluated:<script type='text/html-template'>
<div> this is a template </div>
</script>
By giving a weird non-JavaScript type, you get a way to stuff raw
text into the page for use by other JavaScript code (which is presumably
in script block that can be evaluated).This technique is great for using the block inside the <script> for html template, to be used by JQuery. Without the <script> block, IE will mess with the source code and remove thing it does not know.
Source: http://stackoverflow.com/questions/5265202/do-you-need-text-javascript-specified-in-your-script-tags
March 20, 2013
California LLC taxs and fees
For California LLC not treated as corporation:
1. https://www.ftb.ca.gov/businesses/bus_structures/LLCompany.shtml
2. http://www.taxes.ca.gov/Income_Tax/limliacobus.shtml
3. https://www.upcounsel.com/california-llc-fee
- Annual tax of $800 is paid in the tax year by 04/15 with form 3522 .
- LLC fee estimate for current year is paid by 6/15 current year
- LLC fee final is filed by next year 4/15 with From 568, the payment form is 3536
- The Fee is tax deductible
1. https://www.ftb.ca.gov/businesses/bus_structures/LLCompany.shtml
2. http://www.taxes.ca.gov/Income_Tax/limliacobus.shtml
3. https://www.upcounsel.com/california-llc-fee
March 15, 2013
php one line udp client
socket_sendto(socket_create(AF_INET, SOCK_DGRAM, SOL_UDP), $raw_post_data, strlen($raw_post_data), 0, '127.0.0.1', 57000);
The above will send the post data (suppose it is in $raw_post_data) to a local udp server listening on port 57000.
The above will send the post data (suppose it is in $raw_post_data) to a local udp server listening on port 57000.
March 6, 2013
Excel 2003 useful shortcuts
Ctrl-1: Open Cell Format Dialog
shift +space: select row
ctrl + -: delete row.
ctrl + +: Insert a row (above the currently selected row)
shift +space: select row
ctrl + -: delete row.
ctrl + +: Insert a row (above the currently selected row)
March 1, 2013
clean up diff file
The following program take a diff file and removes chunks that are simply different by a white spaces or carriages returns, such as
int func(a,b){
vs.
int func(a,b)
{
Save this to file "diffclean.awk" and run it as "./diffclean.awk my.diff".
#!/usr/bin/gawk -f
function process_block(str,strp,strm){
regex="[ \t\f\r\n]+";
gsub(regex," ",strp);
gsub(regex," ",strm);
if (strp!=strm){
print str;
}
}
{
if (!block_started) {
if (/^@@/) {
block_started=1;
str=$0;
strp="";
strm="";
}else{
print;
}
next;
}
if (/^diff/) {
process_block(str,strp,strm);
block_started=0;
print;
next;
}
if (/^@@/) {
process_block(str,strp,strm);
str=$0;
strp="";
strm="";
next;
}
str=str "\n" $0;
if (/^-/) strm=strm substr($0,2);
if (/^+/) strp=strp substr($0,2);
}
END{
if (block_started){
process_block(str,strp,strm);
}
}
int func(a,b){
vs.
int func(a,b)
{
Save this to file "diffclean.awk" and run it as "./diffclean.awk my.diff".
#!/usr/bin/gawk -f
function process_block(str,strp,strm){
regex="[ \t\f\r\n]+";
gsub(regex," ",strp);
gsub(regex," ",strm);
if (strp!=strm){
print str;
}
}
{
if (!block_started) {
if (/^@@/) {
block_started=1;
str=$0;
strp="";
strm="";
}else{
print;
}
next;
}
if (/^diff/) {
process_block(str,strp,strm);
block_started=0;
print;
next;
}
if (/^@@/) {
process_block(str,strp,strm);
str=$0;
strp="";
strm="";
next;
}
str=str "\n" $0;
if (/^-/) strm=strm substr($0,2);
if (/^+/) strp=strp substr($0,2);
}
END{
if (block_started){
process_block(str,strp,strm);
}
}
February 27, 2013
vimdiff ignore empty lines
Add this to the end of your .vimrc file to make vimdiff ignore empty lines:
set diffopt+=iwhite
set diffexpr=MyDiff()
function MyDiff()
let opt = ""
if &diffopt =~ "icase"
let opt = opt . "-i "
endif
if &diffopt =~ "iwhite"
let opt = opt . "-w -B " " vim uses -b by default
endif
silent execute "!diff -a --binary " . opt .
\ v:fname_in . " " . v:fname_new . " > " . v:fname_out
endfunction
set diffopt+=iwhite
set diffexpr=MyDiff()
function MyDiff()
let opt = ""
if &diffopt =~ "icase"
let opt = opt . "-i "
endif
if &diffopt =~ "iwhite"
let opt = opt . "-w -B " " vim uses -b by default
endif
silent execute "!diff -a --binary " . opt .
\ v:fname_in . " " . v:fname_new . " > " . v:fname_out
endfunction
February 25, 2013
Thinkpad T530 Ctrl-Alt-Break for Remote Desktop Full Screen
Thinkpad T530 does not have the "break" key. Use "Fn-Alt-B" will generate "Break" key code.
So to send Ctrl-Alt-Break, just do Ctrl-Alt-Fn-B
So to send Ctrl-Alt-Break, just do Ctrl-Alt-Fn-B
February 8, 2013
February 5, 2013
How to add a upstart task on RHEL6
Suppose the application you want to start is called myapp.
Become root and create a file under /etc/init/myapp.conf
start on stopped rc RUNLEVEL=[2345]
respawn
script
cd /home/me/myapp
./myapp -i /home/me/myapp/system.ini
end script
Run "initctl start myapp" to start the app.
Run "initctl status myapp" to see the status.
Run "initctl stop myapp" to stop the app
Keep in mind that myapp should not daemonize itself. Upstart will do the daemonize part.
January 20, 2013
So Cal lakes that allow bow fishing
El Capitan
Sutherland
Otay
San Vicente
Hodges
Lakes Already Approved:
Elsinore
Big Bear
Cachuma
Hemet (with strict regulations)
Sutherland
Otay
San Vicente
Hodges
Lakes Already Approved:
Elsinore
Big Bear
Cachuma
Hemet (with strict regulations)
January 14, 2013
uml and console job control
I started uml with my host debian file system:
./linux rootfstype=hostfs rw init=/home/tzhang/uml/init-uml.sh mem=64M TERM=linux eth0=tuntap,,,192.168.6.88
However the shell I get does not have job control. I tried multiple things found on internet but none did the trick for me. This is what finally solved the problem:
1. get busybox and build it with the "cttyhack" enabled (in shell section of menuconfig)
2. ln -sf busybox cttyhack
3. run that in your init. My init.sh looks like this:
#!/bin/bash
export PS1="[\\u@\\h:\\w] $"
export HOME=/home/tzhang
. /home/tzhang/.bashrc
ifconfig eth0 192.168.6.99
hostname -b R1
export PATH=/usr/local/bin:/usr/bin:/bin:/sbin:/usr/local/sbin:/usr/sbin
mount -t proc proc /proc
mount -t sysfs sysfs /sys
mount -t tmpfs tmpfs /var/run -o rw,nosuid,nodev
mount -t tmpfs tmpfs /var/log -o rw,nosuid,nodev
cd $HOME/uml
mount -t tmpfs /dev/ /dev/
/etc/init.d/udev start
/home/tzhang/uml/dropbear -r dropbear_rsa_host_key
exec setsid /home/tzhang/uml/cttyhack bash
./linux rootfstype=hostfs rw init=/home/tzhang/uml/init-uml.sh mem=64M TERM=linux eth0=tuntap,,,192.168.6.88
However the shell I get does not have job control. I tried multiple things found on internet but none did the trick for me. This is what finally solved the problem:
1. get busybox and build it with the "cttyhack" enabled (in shell section of menuconfig)
2. ln -sf busybox cttyhack
3. run that in your init. My init.sh looks like this:
#!/bin/bash
export PS1="[\\u@\\h:\\w] $"
export HOME=/home/tzhang
. /home/tzhang/.bashrc
ifconfig eth0 192.168.6.99
hostname -b R1
export PATH=/usr/local/bin:/usr/bin:/bin:/sbin:/usr/local/sbin:/usr/sbin
mount -t proc proc /proc
mount -t sysfs sysfs /sys
mount -t tmpfs tmpfs /var/run -o rw,nosuid,nodev
mount -t tmpfs tmpfs /var/log -o rw,nosuid,nodev
cd $HOME/uml
mount -t tmpfs /dev/ /dev/
/etc/init.d/udev start
/home/tzhang/uml/dropbear -r dropbear_rsa_host_key
exec setsid /home/tzhang/uml/cttyhack bash
This solved the problem beautifully. The last line is what did the trick for job control.
the udev daemon and dropbear made ssh possible.
the udev daemon and dropbear made ssh possible.
=============UPDATED 4/10/2017=====================
init.sh:
#!/bin/bash
export PS1="\u@\h:\w $"
export HOME=/home/tzhang
. /home/tzhang/.bashrc
ifconfig eth0 192.168.6.99
hostname -b R1
export PATH=/usr/local/bin:/usr/bin:/bin:/sbin:/usr/local/sbin:/usr/sbin
mount -t proc proc /proc
mount -t sysfs sysfs /sys
mount -t tmpfs tmpfs /var/run -o rw,nosuid,nodev
mount -t tmpfs tmpfs /var/log -o rw,nosuid,nodev
cd $HOME/uml
mount -t tmpfs /dev/ /dev/
ifconfig eth1 192.168.3.2
ifconfig eth0 192.168.2.2
busybox mdev -s
mkdir /dev/pts
mount -t devpts /dev/pts /dev/pts
#dropbear -r dropbear_rsa_host_key -p 2222
exec setsid /home/tzhang/uml/cttyhack bash
init.sh:
#!/bin/bash
export PS1="\u@\h:\w $"
export HOME=/home/tzhang
. /home/tzhang/.bashrc
ifconfig eth0 192.168.6.99
hostname -b R1
export PATH=/usr/local/bin:/usr/bin:/bin:/sbin:/usr/local/sbin:/usr/sbin
mount -t proc proc /proc
mount -t sysfs sysfs /sys
mount -t tmpfs tmpfs /var/run -o rw,nosuid,nodev
mount -t tmpfs tmpfs /var/log -o rw,nosuid,nodev
cd $HOME/uml
mount -t tmpfs /dev/ /dev/
ifconfig eth1 192.168.3.2
ifconfig eth0 192.168.2.2
busybox mdev -s
mkdir /dev/pts
mount -t devpts /dev/pts /dev/pts
#dropbear -r dropbear_rsa_host_key -p 2222
exec setsid /home/tzhang/uml/cttyhack bash
run.sh
./linux rootfstype=hostfs rw init=/home/tzhang/uml/init.sh mem=64M TERM=linux \
eth0=tuntap,tap0,,192.168.2.88 \
eth1=tuntap,tap1,,192.168.3.88
eth0=tuntap,tap0,,192.168.2.88 \
eth1=tuntap,tap1,,192.168.3.88
Host /etc/network/interfaces
# The primary network interface
auto ens33
iface ens33 inet manual
auto ens33
iface ens33 inet manual
auto ens38
iface ens38 inet manual
iface ens38 inet manual
auto tap0
iface tap0 inet manual
pre-up ip tuntap add tap0 mode tap user tzhang
up ip link set dev tap0 up
iface tap0 inet manual
pre-up ip tuntap add tap0 mode tap user tzhang
up ip link set dev tap0 up
auto tap1
iface tap1 inet manual
pre-up ip tuntap add tap1 mode tap user tzhang
up ip link set dev tap1 up
iface tap1 inet manual
pre-up ip tuntap add tap1 mode tap user tzhang
up ip link set dev tap1 up
auto br0
iface br0 inet dhcp
bridge_ports ens33 tap0
iface br0 inet dhcp
bridge_ports ens33 tap0
auto br0:1
allow-hotplug br0:1
iface br0:1 inet static
address 192.168.2.1
broadcast 192.168.2.255
netmask 255.255.255.0
allow-hotplug br0:1
iface br0:1 inet static
address 192.168.2.1
broadcast 192.168.2.255
netmask 255.255.255.0
auto br1
iface br1 inet dhcp
bridge_ports ens38 tap1
iface br1 inet dhcp
bridge_ports ens38 tap1
auto br1:1
allow-hotplug br1:1
iface br1:1 inet static
address 192.168.3.1
broadcast 192.168.3.255
netmask 255.255.255.0
allow-hotplug br1:1
iface br1:1 inet static
address 192.168.3.1
broadcast 192.168.3.255
netmask 255.255.255.0
January 13, 2013
uml with minimal debian
Build kernel:
1. get kernel
2. make ARCH=um defconfig
3. make ARCH=um menuconfig ; to remove options you don't need
4. make -j 12 ; parallel build
Build rootfs:
dd if=/dev/zero of=my.rootfs bs=1M seek=512 count=0 mkfs.ext2 -F my.rootfsmkdir rootfssudo mount -o loop my.rootfs rootfssudo debootstrap --arch=i386 --variant=minbase lucid rootfs
January 8, 2013
SQL Server 2008 can't login with newly created user
SQL Server was not configured to allow mixed authentication.
Here are steps to fix:
- Right-click on SQL Server instance at root of Object Explorer, click on Properties
- Select Security from the left pane.
- Select the SQL Server and Windows Authentication mode radio button, and click OK.
Right-click on the SQL Server instance, select Restart (alternatively, open up Services and restart the SQL Server service).
I wish Microsoft has better document.
Source: http://stackoverflow.com/questions/1719399/sql-server-2008-cant-login-with-newly-created-user
Subscribe to:
Posts (Atom)