Javascript: copy to clipboard











Source code:

<textarea cols="60" id="textArea1" rows="6" style="height: 137px; width: 596px;">Copy me.</textarea><br/>
<input name="copy" onclick="window.prompt('Copy to clipboard: Ctrl+C (or Command+C on Mac), Enter', document.getElementById('textArea1').value);" type="button" value="Copy to Clipboard" />

See Also:







awk: add a column based on the test of existing columns








E.g. we have a text file, numbers.txt, see below:
1 2
3 4
5 6

and we want to add the 3rd column, its value is yes/no. If the sum of the 1st column and the 2nd column is greater than 3, the value of the 3rd column is yes, otherwise no.
1 2 no
3 4 yes
5 6 yes

The following command:
awk '{printf "%s %s %s\n",$1,$2,($1+$2>3)?"yes":"no"}' numbers.txt > new_numbers.txt
will do the work.






awk: append a column that sums up existing columns








E.g. we have a text file, numbers.txt, see below:
1 2
3 4
5 6

and we want to add the 3rd column which is the sum of values of the first and the second columns.
1 2 3
3 4 7
5 6 11

The following command:
awk '{print $1 " " $2 " " int($1+$2)}' numbers.txt > new_numbers.txt
will do the work.
Or, the following command do the same thing:
awk '{printf "%s %s %d\n",$1,$2,int($1+$2)}' numbers.txt > new_numbers.txt






Edit a text file using sed








  • Replace a word
    • text.txt file contains following line:
      ios
      
    • Run the following command to replace ios with android:
      sed -e "s/ios/android/g" -i .bak text.txt
      
  • Append a word
    • text.txt file contains following line:
      leopard
      
    • Run the following command to append lion after leopard:
      sed -e "s/leopard/& lion/g" -i .bak text.txt
      
  • Append a token to each line
    • Run the following command to append 0 to each line:
      sed -e "s/$/ 0/g" -i .bak text.txt
      






Link: Best free Android applications














fail safe copy using rsync








#!/bin/bash
TMPDIR=/tmp
rsync -a --partial-dir=$TMPDIR --delete-after --partial --delay-updates $@






Multiple Hop SSH using Putty









  • use plink in command line:
    • plink -t -X -A username@gateway.yourcompany.com ssh -X -A username@remoteWorkstation
      
  • use putty:
    • Host Name: username@gateway.yourcompany.com
    • SSH:
      • Remote command: ssh username@remoteWorkstaion.yourcompany.com

    • NOTE: The options below can be specified:
      • -t enable pty allocation (used so you can do the second ssh from gateway to the work computer)
      • -A agent forwarding (only needed if you are using Pageant or another key agent)
      • -X enable X11 forwarding (only needed if you want to send X11 back to your home computer)
      • TO run X11 server on Windows, see this post.

See Also:







海外网上观看体育直播的网站








飞流直播 中超亚冠都有直播。正在用它看2018世预赛中国队的比赛。【推荐】
http://goatd.net/ 速度比较快,画质一般,无中文解说。中超亚冠都有直播。弹窗有流氓软件广告。Google Chrome 屏蔽此站。
乐视体育 2017年,乐视出现资金问题,未能获得中超亚冠的直播权。
央视体育频道(CCTV 5, CCTV 5+)
可在电脑上安装Bluestacks模拟器和电视家观看
中文解说,画质较好,经常有停滞和音画不同步。每輪中超只直播一场。
央视体育频道(CCTV 5 [无插件直播]
在线直播,画质较好,速度一般,有一定的延迟。每輪中超只直播一场。



A lightweight free PDF viewer for Windows








Sumatra PDF is a PDF, CHM, XPS, DjVu, CBZ, CBR reader for Windows.





Mirror ftp sites using lftp








The shell script below can mirror two ftp sites:
#!/bin/bash
     
    usage() {
      echo ""
      echo "USAGE: `basename $0` <src_ftp_address> <dst_ftp_address>"
      echo "DESCRIPTION:"
      echo "             ftp_address  is in the format of ftp://username:password@host:port/path, e.g. ftp://wilson:pass@168.site90.net:21/public_html"
      echo ""
    }
     
    # lftp is required
    if [[ -z `which lftp` ]]; then
      echo 1>&2 "Error: could not find lftp."
      exit 1
    fi
     
    # save current path
    CWD=`pwd`
     
    # check arguments
    if [[ $# -ne 2 ]]; then
      echo 1>&2 "Error: invalid arguments."
      usage
      exit 1
    fi
     
    # parse src address
    s=$1
    [[ $s == ftp://* ]] && s=${s:6}
    s1=`echo $s | awk -F @ '{print \$1}'`
    s2=`echo $s | awk -F @ '{print \$2}'`
    SRC_FTP_USER=`echo $s1 | awk -F : '{print \$1}'`
    SRC_FTP_PASS=`echo $s1 | awk -F : '{print \$2}'`
    SRC_FTP_HOST=`echo $s2 | awk -F : '{print \$1}'`
    s3=`echo $s2 | awk -F : '{print \$2}'`
    i=`expr index $s3 /`
    SRC_FTP_PORT=${s3:0:$((i-1))}
    [[ -z $SRC_FTP_PORT ]] && SRC_FTP_PORT=21
    SRC_FTP_PATH=${s3:$((i-1))}
    SRC_FTP_ADDR="ftp://${FTP_HOST}:${FTP_PORT}${FTP_PATH}"
     
    # parse dst address
    s=$2
    [[ $s == ftp://* ]] && s=${s:6}
    s1=`echo $s | awk -F @ '{print \$1}'`
    s2=`echo $s | awk -F @ '{print \$2}'`
    DST_FTP_USER=`echo $s1 | awk -F : '{print \$1}'`
    DST_FTP_PASS=`echo $s1 | awk -F : '{print \$2}'`
    DST_FTP_HOST=`echo $s2 | awk -F : '{print \$1}'`
    s3=`echo $s2 | awk -F : '{print \$2}'`
    i=`expr index $s3 /`
    DST_FTP_PORT=${s3:0:$((i-1))}
    [[ -z $DST_FTP_PORT ]] && DST_FTP_PORT=21
    DST_FTP_PATH=${s3:$((i-1))}
    DST_FTP_ADDR="ftp://${FTP_HOST}:${FTP_PORT}${FTP_PATH}"
     
    TMP_DIR=`export TMPDIR=$CWD; mktemp -d`
     
    # download from src ftp server to local temp dir.
    echo "Downloading from $SRC_FTP_HOST..."
    lftp -c "set ftp:list-options -a; 
             open -u $SRC_FTP_USER,$SRC_FTP_PASS -p $SRC_FTP_PORT $SRC_FTP_HOST;
             lcd $TMP_DIR;
             cd $SRC_FTP_PATH;
             mirror --delete  --verbose"
     
    # upload from local temp dir to dst ftp server
    echo "Uploading to $DST_FTP_HOST..."
    lftp -c "set ftp:list-options -a;
             open -u $DST_FTP_USER,$DST_FTP_PASS -p $DST_FTP_PORT $DST_FTP_HOST;
             lcd $TMP_DIR;
             cd $DST_FTP_PATH;
             mirror --delete --reverse --verbose"
     
    # remove temp directory
    rm -fr $TMP_DIR


see also

Stackoverflow.com





Regular expression to match camel case string








[A-Z]([A-Z0-9]*[a-z][a-z0-9]*[A-Z]|[a-z0-9]*[A-Z][A-Z0-9]*[a-z])[A-Za-z0-9]*

See also:

  • http://stackoverflow.com/questions/1128305/regular-expression-to-identify-camelcased-words







Mac OS X: Enable/Disable X11 full screen mode








  • Start X11
  • X11 -> Preferences... -> Output, tick Full-screen mode to enable
  • Use key combo Command+Option+A to switch on/off full screen mode in a X11 window.






Change your Flash player settings














How to Virtualize OS X Lion on Windows








How to Virtualize OS X Lion on Windows: A blog post show how to install Mac OS X in VMWare Workstation running on Windows 7.





Enable NFS server -32bitclients option on Mac OS X 10.4 Tiger








 enable -32bitclients option on the NFS server can fix the problem: NFS + readdir() issues in 10.4?

  • 1. Dump the existing exports, if any, to a file. Start the Terminal application. Type the following commands at the prompt:
    • su root
    • nidump -r /exports . > ~/exportfile
    • Note that the '.' indicates the current domain.
    • This places a list of all the existing exports in a file, using a property-list notation.
  • 2. Edit the file to add new exports or modify existing exports.
    • cp ~/exportfile ~/exportfile.bkup
    • vi ~/exportfile
    • {
        "name" = ( "exports" );
        CHILDREN = (
          {
            "name" = ( "/Volumes/home" );
            "opts" = ( "32bitclients", "maproot=nobody" );
          }
        )
      }
      
  • 3. Load the modified exports back into Netinfo.
    • niload -r /exports . < ~/exportfile
  • 4. If something goes drastically wrong, restore the original exports:
    • niload -r /exports . < ~/exportfile.bkup
  • 5. Restart the server. (Alternatively, if you feel lucky, use Terminal.app to start 'mountd' if it's not running, or send it a SIGHUP if it is by typing the following command:
    • kill -HUP `cat /var/run/mountd.pid`

See also:







Edit NFS server options on Mac OS X 10.5 Leopard








1. Server Admin's features for editing NFS export options are incomplete. E.g. -32bitclients option can only be added by editing /etc/exports file.

### [ Begin Server Admin managed exports. Do Not Edit.
/nfsdir -maproot=nobody -sec=sys -network 192.168.20.0 -mask 255.255.255.0
### ] End Server Admin managed exports. 


2. Before you do that, you should unshare the directories managed by "Server Admin". After doing that, you can get an empty /etc/exports file to start, then you can add new entry:


/nfsdir -32bitclients -maproot=nobody -sec=sys -network 192.168.20.0 -mask 255.255.255.0

3. Restart NFS server and check its status:

nfsd restart
showmount -e


See also:

NFS share export options ("-32bitclients") where to set?





Rotate Video in VLC player








  • Window -> Video Filters... (Command+E)
  • Activate Geometry tab, tick Transform






GWT Developer's Plugin for Firefox 11








Update: GWT Developer's Plugin for Firefox 12 is available. see GWT Developer's Plugin for Firefox 12


See also



Thanks Alan Leung for compiling the plugins for us


Check My IP Address & Location










IP Address Lookup



Online Code Formatter for blogger









Note: the code formatter below can translate code fragment into HTML safe string. Can be used to post source code into blogger.
Usage: post your source code into the source code area then click the "Format" button.


Source code(Paste your source code below then click Format button):


Font Colour:  Background Colour:

Formatted Code:


Preview:




Online base64 encoder & decoder













Note: The javascript source code is available at http://www.webtoolkit.info/javascript-base64.html




Multiple Hop SSH access








I have a desktop computer, homepc, at home and I want to access my desktop computer, workpc, at work. However, workpc does not have an public ip, therefore, it is not directly accessible from home. I have go through the gateway computer, Gateway.mycompany.com, at work.
ssh -oproxycommand="ssh Gateway.mycompany.com nc %h %p" WorkPC

Note: WorkPC can the internal IP address or internal host name recognized by Gateway. The host name (or ip address) of the Gateway must be public accessible.
ssh -oproxycommand="ssh Gateway.mycompany.com nc %h %p" 192.168.20.12

Note: if nc is not installed on the Gateway, you can try the following command instead:
ssh -oproxycommand="ssh Gateway.mycompany.com /bin/bash -c 'exec 3<>/dev/tcp/%h/%p; cat <&3 & cat >&3;kill $!'" WorkPC

See also:




Web Sites of Free E-Books








  1. http://en.wikibooks.org/
  2. http://refcardz.dzone.com/  Reference cards (Cheat sheets) in PDF format. You need to register to download.



Free Computer Science Books








  1. Data Structures and Algorithms with Object-Oriented Design Patterns in Java Also available in C#, Python, Perl, Ruby, Lua, C++ and PHP versions.



Comparisons between Mercurial and Git











Install nsscache on CentOS 6








  1. Download the latest rpmforge-release rpm from http://apt.sw.be/redhat/el6/en/i386/rpmforge/RPMS/
  2. Install rpmforge-release rpm:
    • rpm -Uvh rpmforge-release*rpm
      
  3. Install nsscache rpm package:
    • yum install nsscache
      
  4. edit /etc/nsscache.conf to set up which system databases you wish to synchronise, and to set local configuration parameters.
  5. run following command to perform a full update
    • nsscache update --full
      
  6. run following command to confirm that the system is configured:
    • nsscache verify
      
  7. edit /etc/nsswitch.conf to point your local database to use the cache nss module, or the db module.
    • passwd:     files ldap [NOTFOUND=return] db
      shadow:     files ldap [NOTFOUND=return] db
      group:      files ldap [NOTFOUND=return] db
      
  8. Run
    getent passwd 
    
    to test if the entries are pulled from the server
See also nsscache official web site




Metro Trains Monthly Performance Results








http://www.metrotrains.com.au/About-us/Metro-Performance/Monthly-Performance-Results.html


Blogger: Missing Quick Edit Icon in the country specific URL








Blogger recently redirects users to country specific urls: e.g. notepad2.blogspot.com will be redirected to notepad2.blogspot.com.au if the user is browsing from Australia.

But there is a side effect that the quick edit icon is missing in the country specific url.

I spent quite a lot time trying to fix it by editing the template and modifying the browser settings. None of them works. Finally, I realized it was caused by the URL redirection.

Thankfully, you can bypass the URL redirection by appending  /ncr to the blog address, e.g.

notepad2.blogspot.com/ncr 

will let you access the notepad2.blogspot.com address and the quick editing icon will appear.

SEE ALSO:




UID and EUID in Linux








Each UNIX process has 3 UIDs associated to it. Superuser/root is UID=0.

  • UID
    • Read UID. It is of the user/process that created THIS process. It can be changed only if the running process has EUID=0.
  • EUID
    • Effective UID. It is used to evaluate privileges of the process to perform a particular action. EUID can be change either to RUID, or SUID if EUID!=0. If EUID=0, it can be changed to anything.
  • SUID 
    • If the binary image file, that was launched has a Set-UID bit on, SUID will be the UID of the owner of the file. Otherwise, SUID will be the RUID.

See also:

NOTE: EUID is not available in standard POSIX shell: /bin/sh. Therefore, $EUID can not be used in a shell script starts with #!/bin/sh.






Free e-books on learning Objective-C








  1. Become An X coder A guide to MacOSX development with Cocoa using Objective-C. The book contains lots of examples and detailed screenshots. (PDF & html online)
  2. Objective-C 2.0 Essentials(html online)
  3. Object-Oriented Programming with Objective-C(PDF)
  4. Learning Cocoa with Objective-C(html online)
  5. The Objective-C Programming Language(html online)
  6. Objective-C for Java Programmers(html online)





Javascript to force a page refresh








  • Method 1:
    • window.location = window.location;
      
  • Method 2: 
    • window.location.href = "index.html" + "?" + Date.parse(new Date());
      
    • or, if the url contains already query
    • window.location.href = "index.php?id=1" + "&" + Date.parse(new Date());
      



TPG Mobile APN Settings








Android Phones

Mobile data settings
Go to Settings -> Wireless & Networks -> Mobile Networks -> Access Point Names -> Tap your phone's menu button -> New APN

And then fill in the fields as below:


Name Optus Yes Internet
APN yesinternet
Proxy (blank)
Port (blank)
Username (blank)
Password (blank)
Server (blank)
MMSC (blank)
MMS Proxy (blank)
MMS Port (blank)
MMS Protocol (blank)
MCC 505
MNC 02
APN Type default


MMS settings
Go to Settings -> Wireless & Networks -> Mobile Networks -> Access Point Names -> Tap your phone's menu button -> New APN

And then fill in the fields as below:

Name Optus MMS
APN mms
Proxy 202.139.83.152
Port 8070
Username (blank)
Password (blank)
Server (blank)
MMSC http://mmsc.optus.com.au:8002/
MMS Proxy 61.88.190.10
MMS Port 8070
MMS Protocol WAP2.0
MCC 505
MNC 2
APN Type mms



iPhone (note: unlocked iPhone only)

Mobile data settings
Go to Home -> Settings -> Phone -> Network -> Cellular Data Network

And then fill in the fields as below:

APN internet
Username (blank)
Password (blank)
MMSC (blank)
MMS Proxy (blank)


MMS settings
Go to Home -> Settings -> Phone -> Network -> Cellular Data Network

And then fill in the fields as below:

APN mms
Username (blank)
Password (blank)
MMSC mmsc.optus.com.au:8002
MMS Proxy 61.88.190.10:8070



Other Phones (Generic Settings)

Mobile data settings

APN internet OR yesinternet
Username (blank)
Password (blank)
Leave everything else as default


MMS settings

APN mms
Username (blank)
Password (blank)
MMSC mmsc.optus.com.au:8002
MMS Proxy 61.88.190.10
MMS Port 8070



Mac OS X: How to clear VLC player viewing history








  • Clear Recent Played Files 
    • Start your VLC player
    • Click on File -> Open Recent -> Click on “Clear Menu
  • Disable Recent Items in Mac OS X Dock
    • In Terminal window, run the following commands:
      defaults write org.videolan.vlc NSRecentDocumentsLimit 0
      defaults delete org.videolan.vlc.LSSharedFileList RecentDocuments
      defaults write org.videolan.vlc.LSSharedFileList RecentDocuments -dict-add MaxAmount 0
      
See also:

-->


Mac OS X: join PDF files using Preview








  • Open the first PDF using Preview
  • View -> Thumbnails
  • Open Finder window, drag the second PDF file to the Sidebar in Preview
  • You can remove a page using Command + delete

See also: How to merge pdf files in Mac OS X



Allow relay hosts on EXIM4 smtp server








  • sudo vi /etc/exim4/update-exim4.conf.conf
    • dc_relay_domains='myorg1.org:myorg2.org'
    • dc_relay_nets='127.0.0.0/24:192.168.1.0/24:115.146.90.163/32'
  • sudo update-exim4.conf
  • sudo /etc/init.d/exim4 restart



Unix: stderr and stdout redirections











UNIX tips: Learn 10 good UNIX usage habits











Unix: combine commands with control operators








  • Run the second command only if the first command return a zero exit status
    • cd a/b/c && tar zxvf ~/archive.tar.gz
      
    • the command above extracts archive.tar.gz to a/b/c directory if a/b/c exists.
  • Run the second command only if the first command return a non-zero exit status
    • cd a/b/c || mkdir -p a/b/c
    • the command above create a/b/c directory, if it does not exist
  • You can also chain the commands with both operators: 
    • cd a/b/c || mkdir -p a/b/c && tar zxvf ~/archive.tar.gz
    • the command above make directory a/b/c and extracts archive.tar.gz into it.



Shell script: generate random string as password








See also: http://www.howtogeek.com/howto/30184/10-ways-to-generate-a-random-password-from-the-command-line/



Open source java PDF libraries









See also:





Javascript trim









function trim(str){
    return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}


function trim (str) {
    var    str = str.replace(/^\s\s*/, ''),
        ws = /\s/,
        i = str.length;
    while (ws.test(str.charAt(--i)));
    return str.slice(0, i + 1);
}




Generate iptables firewall rules online










A script generated by the online generator
#!/bin/sh

# iptables script generated 2012-03-01
# http://www.mista.nu/iptables

IPT="/sbin/iptables"

# Flush old rules, old custom tables
$IPT --flush
$IPT --delete-chain

# Set default policies for all three default chains
$IPT -P INPUT DROP
$IPT -P FORWARD DROP
$IPT -P OUTPUT DROP

# Enable free use of loopback interfaces
$IPT -A INPUT -i lo -j ACCEPT
$IPT -A OUTPUT -o lo -j ACCEPT

# All TCP sessions should begin with SYN
$IPT -A INPUT -p tcp ! --syn -m state --state NEW -s 192.168.20.0/24 -j DROP

# Accept inbound TCP packets
$IPT -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPT -A INPUT -p tcp --dport 22 -m state --state NEW -s 192.168.20.0/24 -j ACCEPT

# Accept inbound ICMP messages
$IPT -A INPUT -p ICMP --icmp-type 8 -s 192.168.20.0/24 -j ACCEPT
$IPT -A INPUT -p ICMP --icmp-type 11 -s 192.168.20.0/24 -j ACCEPT

# Accept outbound packets
$IPT -I OUTPUT 1 -m state --state RELATED,ESTABLISHED -j ACCEPT
$IPT -A OUTPUT -p udp --dport 53 -m state --state NEW -j ACCEPT




Iptables example: a simple firewall script









#!/bin/bash


# flush all chains
iptables -F

# set the default policy for each of the pre-defined chains
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP

# allow all traffic on loopback. If you don't do this, various processes, such as Postfix, will break:
iptables -A INPUT -i lo -j ACCEPT

# allow establishment of connections initialised by my outgoing packets
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

# allow server ports
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 8080 -j ACCEPT

# redirect port 8080 to port 80 
iptables -t nat -A PREROUTING -p tcp --dport 8080 -j REDIRECT --to-port 80

# drop everything else
iptables -A INPUT -j DROP