May 8, 2013

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.

VPN Setting

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 )
  \_/   \_/   \_/   \_/   \_/

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


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:

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. Annual tax of $800 is paid in the tax year by 04/15 with form 3522 . 
  2. LLC fee estimate for current year is paid by 6/15 current year
  3. LLC fee final is filed by next year 4/15 with From 568, the payment form is 3536
  4. The Fee is tax deductible
Source:

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.

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)     

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);
        }
}

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

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

February 8, 2013

diff ignore files only in one directory


diff -bBur old_dir/ new_dir/ | grep -v "^Only in" > my.diff

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)

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

This solved the problem beautifully. The last line is what did the trick for job control.
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


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

Host /etc/network/interfaces
# The primary network interface
auto ens33
iface ens33 inet manual
auto ens38
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
auto tap1
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
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
auto br1
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

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.rootfs

mkdir rootfs
sudo mount -o loop my.rootfs rootfs
sudo 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:
  1. Right-click on SQL Server instance at root of Object Explorer, click on Properties
  2. Select Security from the left pane.
  3. 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

December 27, 2012

putty and gnu screen scroll back with mouse


Summary: add the line to your .screenrc file:
termcapinfo xterm ti@:te@
Reference ( Putty FAQ )
PuTTY's terminal emulator has always had the policy that when the ‘alternate screen’ is in use, nothing is added to the scrollback. This is because the usual sorts of programs which use the alternate screen are things like text editors, which tend to scroll back and forth in the same document a lot; so (a) they would fill up the scrollback with a large amount of unhelpfully disordered text, and (b) they contain their own method for the user to scroll back to the bit they were interested in. We have generally found this policy to do the Right Thing in almost all situations.
Unfortunately, screen is one exception: it uses the alternate screen, but it's still usually helpful to have PuTTY's scrollback continue working. The simplest solution is to go to the Features control panel and tick ‘Disable switching to alternate terminal screen’. (See section 4.6.4 for more details.) Alternatively, you can tell screen itself not to use the alternate screen: the screen FAQ suggests adding the line ‘termcapinfo xterm ti@:te@’ to your .screenrc file.

November 30, 2012

run as user in inittab or init

Sometimes sudo -u USERNAME gives error.

You can try to to use su USERNAME -c "COMMAND" instead.

November 28, 2012

Start screen after sudo su to another user


Sudo'ing to a user then running screen doesn't work out of the box.  Typically you get the following error:
Cannot open your terminal '/dev/pts/1' - please check.
The solution:
sudo su - someuser
script /dev/null
screen

Source: http://dbadump.blogspot.com/2009/04/start-screen-after-sudo-su-to-another.html