Search This Blog

GWT Example: set cookies

package test;

import com.google.gwt.user.client.Cookies;

public class CookieTest {

    public static final int COOKIE_EXPIRE_DAYS = 30;
    public static final long MILLISECS_PER_DAY = 1000L * 60L * 60L * 24L;

    public static void setMyCookie(String name, String value, int days) {

    if (value == null) {
        Cookies.removeCookie(name);
        return;
    }
        String v = Cookies.getCookie(name);
        if (value.equals(v)) {
            // Now
            Date d = new Date();
            // Now + days
            d.setTime(d.getTime() + MILLISECS_PER_DAY * days);
            Cookies.setCookie(name, value, d);
        }

    }

    public static void setMyCookie(String name, String value) {
            
            setCookie(name, value, COOKIE_EXPIRE_DAYS);
    }
}

Eclipse: shortcut key combos

Shortcut on Windows/Linux Shortcut on Mac OS Function
Ctrl+1 Command+1 Activates quick fix. If you have methods need to implement, you can then "Add unimplemented methods"
Ctrl+D Command+D Delete the current row
Shift+Alt+R Command+Option+R Highlight the class/method/variable name first then press the shortcut keys to refactor/rename class/method/variable.
Ctrl+Shift+O Command+Shift+o Organize imports
Ctrl+Shift+F Command+Shift+F Format source code
Ctrl+Shift+L Command+Shift+L List available shortcut key combos.
Ctrl+L Command+L Go to line.

SEE ALSO

git: fix binary file conflicts

  • Solution 1: Use the local one
    git add lib/mylib.jar
    git commit -m "fix git conflict by using the local copy"
    
  • Solution 2: Use the remote one
    git checkout origin/master lib/mylib.jar
    git add lib/mylib.jar
    git commit -m "fix git conflict by using the remote copy"
    
    or
    git checkout --theirs -- lib/mylib.jar
    git add lib/mylib.jar
    git commit -m "fix git conflict by using the remote copy"
    

SEE ALSO

MySQL: select records from multiple records

  • Full join(Cross Join):
    SELECT employee.id, employee.name, salary.amount FROM employee, salary WHERE employee.id=salary.employee_id;
    
  • Left/Right join:
    SELECT employee.id, employee.name, salary.amount LEFT JOIN ON employee.id=salary.employee_id;
    

SEE ALSO

MySQL: export data to csv file

SELECT employee.id, employee.name, employee.salary 
INTO OUTFILE '/tmp/employee.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\n'
FROM employee;

Shell script: rename files and prepend leading zeros

you may want to rename the files in a directory, where the file names start with numbers, e.g. 1.txt, 2.txt, 3.txt, 10.txt, 100.txt, to file names with padding zeros: 001.txt, 002.txt, 010.txt, 100.txt. The script below do the work for you:
for f in $(ls *.txt)
do
    mv $f $(printf %03d.%s ${f%.*} ${f##*.})
done

Mac OS X: execute a script or command when the network is connected

  • ControlPlane (MacroPolo)
    • ControlPlane allows you to build configuration profiles, contexts in ControlPlane lingo, for your Mac based on where you are or what you are doing.  ControlPlane determines where you are or what you are doing based on a number of available evidence sources and then automatically reconfigures your Mac based on your preferences.  Evidence sources can include your current location, visible WiFi networks, attached USB devices, running applications and more.  You can even write your own evidence sources using shell scripts!
    • ControlPlane was created using code from version 2.5.1 of the MarcoPolo project still available at http://www.symonds.id.au/marcopolo/.  ControlPlane is a direct port of MarcoPolo and in fact, much of the configuration from MarcoPolo still works with ControlPlane, just better!
      ControlPlane supports 32 and 64bit Intel based Macs running Snow Leopard through Lion.
       
  • LocationChanger
    • LocationChanger is a simple shell script and launchd description. The script gets launched after every network change.
      When running it gathers some information, figures out the location and sets Location accordingly. 

shell script: read lines from file in a while loop

  • by piping cat:
    cat /path/to/file | while read line
    do
        echo $line
    done
    
  • by redirecting the file:
    while read line
    do
        echo $line
    done < /path/to/file
    
  • by using awk:
    awk '{print $0}' /path/to/file
    
  • by using head an tail:
    f=/path/to/file
    total=$(wc -l $f)
    n=0
    while [ $n -lt $total ]
    do
        let n++
        line=$(head -n $n $f | tail -1)
        echo ${line}
    done
    

execute cron job in every a few minutes, hours

  • execute the cron job every 5 minutes:
    */5 * * * * /path/to/script.sh
    
  • execute the cron job every 5 hours:
    0 */5 * * * /path/to/script.sh
    
  • execute the cron job every Friday:
    0 0 * * 5 /path/to/script.sh
    

shell script: update ufw rules for the hosts with dynamic ip addresses

  • The shell script to check the ip address for the host and update the ufw rules:
    #!/bin/bash
    
    HOSTS_ALLOW=/etc/ufw-dynamic-hosts.allow
    IPS_ALLOW=/var/tmp/ufw-dynamic-ips.allow
    
    add_rule() {
      local proto=$1
      local port=$2
      local ip=$3
      local regex="${port}\/${proto}.*ALLOW.*IN.*${ip}"
      local rule=$(ufw status numbered | grep $regex)
      if [ -z "$rule" ]; then
          ufw allow proto ${proto} from ${ip} to any port ${port}
      else
          echo "rule already exists. nothing to do."
      fi
    }
    
    delete_rule() {
      local proto=$1
      local port=$2
      local ip=$3
      local regex="${port}\/${proto}.*ALLOW.*IN.*${ip}"
      local rule=$(ufw status numbered | grep $regex)
      if [ -n "$rule" ]; then
          ufw delete allow proto ${proto} from ${ip} to any port ${port}
      else
          echo "rule does not exist. nothing to do."
      fi
    }
    
    
    sed '/^[[:space:]]*$/d' ${HOSTS_ALLOW} | sed '/^[[:space:]]*#/d' | while read line
    do
        proto=$(echo ${line} | cut -d: -f1)
        port=$(echo ${line} | cut -d: -f2)
        host=$(echo ${line} | cut -d: -f3)
    
        if [ -f ${IPS_ALLOW} ]; then
          old_ip=$(cat ${IPS_ALLOW} | grep ${host} | cut -d: -f2)
        fi
    
        ip=$(dig +short $host | tail -n 1)
    
        if [ -z ${ip} ]; then
            if [ -n "${old_ip}" ]; then
                delete_rule $proto $port $old_ip
            fi
            echo "Failed to resolve the ip address of ${host}." 1>&2
            exit 1
        fi
    
        if [ -n "${old_ip}" ]; then
            if [ ${ip} != ${old_ip} ]; then
                delete_rule $proto $port $old_ip
            fi
        fi
        add_rule $proto $port $ip
        if [ -f ${IPS_ALLOW} ]; then
          sed -i.bak /^${host}*/d ${IPS_ALLOW}
        fi
        echo "${host}:${ip}" >> ${IPS_ALLOW}
    done
    
  • The sample hosts file: /etc/ufw-dynamic-hosts.allow:
    tcp:22:yourpc.no-ip.org
    
  • The crontab which execute the script every 5 minutes to update the rules:
    # m h  dom mon dow   command
    */5 * * * * /usr/local/sbin/ufw-dynamic-host-update  2>&1 > /dev/null
    

sed: how to delete/skip empty/blank lines

  • To delete/skip the empty/blank lines:
    sed '/^$/d' inputFile
    
  • To delete/skip the lines that are empty or contain only spaces:
    sed '/^[[:space:]]*$/d' inputFile
    

sed: how to skip/delete lines starts with #

  • To delete/skip the lines starts with #:
    sed '/^#/d' inputFile
    
  • To delete/skip the lines where the very first non-space character is #:
    sed '/^[[:space:]]*#/d' inputFile
    

Mac OS X: How to change Terminal opacity/transparency

  1. Terminal -> Preferences:
  2. In Settings tab, click Background Color:
  3. Set Opacity to 100% to disable transparency completely:

Firefox: disable flash

Flash videos on the web pages can sometimes crash the Firefox. I am using Firefox on Mac OS. So I want to disable the flash videos in Firefox. The following to addons can be installed for that purpose:
  • Flashblock:
    A Firefox addon, which can disable flash on the web page (you can still play the video by manually start it). It allows white-lists.
  • NoScript:
    A Firefox addon, which lets you disable scripts, Flash and other plugins and supports a white-listing. I am currently using Flashblock, because I found NoScript is a bit complicated to manage and I do not want to block anything else other than flash.

GWT Developer's Plugin for Firefox 13

See also



Thanks Alan Leung for compiling the plugins for us

ip checking services for ddclient

  • http://ip1.dynupdate.no-io.com:

    • ddclient configuration:
      use=web, web=ip1.dynupdate.no-io.com/
  • http://checkip.dyndns.com/:

    • ddclient configuration:
      use=web, web=checkip.dyndns.com/, web-skip='Current IP Address: '
  • http://whatismyip.org/
    • ddclient configuration:
      use=web, web=whatismyip.org/, web-skip='Your Ip Address:'

Blogger: switch between old and new interface

  • To switch back to the old interface:
    1. Click the gear button at the top right corner:
    2. Select "Old blogger interface":
  • To switch to the new/updated interface:
    1. In the old interface, click "Try the updated Blogger interface" at the top:

SEE ALSO:

iptables: mac address filtering

iptables supports MAC address rules. For example you can block a MAC address:
/sbin/iptables -A INPUT -m mac --mac-source 00:00:11:22:22:33 -j DROP
or allow a MAC address:
/sbin/iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m mac --mac-source 11:22:33:44:55:66 -s 192.168.1.0/24 -j ACCEPT

However, allowing MAC addresses in iptables is NOT safe since the MAC address can be easily spoofed on all the operating systems. How should we use MAC address filtering safely? Here are some suggestions:
  1. Use MAC address rules to DROP(filter out) packets. DO NOT use MAC address rules to ACCEPT packets
  2. Use MAC address rules for LAN, e.g. a local subnet, which is considered comparably safe. DO NOT use MAC address rules for internet.

SEE ALSO:

simple iptables firewall script

#!/bin/sh
### BEGIN INIT INFO
# Provides:          iptables
# Required-Start:    mountkernfs $local_fs
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Set up iptables rules
### END INIT INFO

#============================================================================#
# Settings                                                                   #
#============================================================================#

# iptables
IPT=/sbin/iptables

# set to 0 to disable logging drop
LOG_DROP=1

# set to 1 to enable logging accept
LOG_ACCEPT=0

# log prefix (do not change if you do not know what you are doing)
LOG_PREFIX="[IPTABLES "

# chain for logging drops
LOG_DROP_CHAIN="LOGDROP"

# chain for logging accepts
LOG_ACCEPT_CHAIN="LOGACCEPT"

# log_drop prefix (do not change if you do not know what you are doing)
LOG_DROP_PREFIX="${LOG_PREFIX}DROP"

# log_accept prefix (do not change if you do not know what you are doing)
LOG_ACCEPT_PREFIX="${LOG_PREFIX}ACCEPT"

#============================================================================#
# Functions                                                                  #
#============================================================================#

reset() {

    # Reset the default policies to accept everything
    $IPT --policy INPUT   ACCEPT
    $IPT --policy OUTPUT  ACCEPT
    $IPT --policy FORWARD ACCEPT

    # Flush/Remove all rules
    $IPT --flush

    # Delete all custom chains
    $IPT --delete-chain

    # Zero counters
    $IPT --zero

    # Reset all built-in tables (nat, mangle and filter)
    for table in filter nat mangle; do
        $IPT -t $table -F
        $IPT -t $table -X
        $IPT -t $table -Z
    done

}

status() {

    echo "============================================================"
    echo "= Filter Rules:                                            ="
    echo "============================================================"
    $IPT -L -v
    echo ""

    echo "============================================================"
    echo "= NAT Rules:                                               ="
    echo "============================================================"
    $IPT -t nat -L -v
    echo ""

    echo "============================================================"
    echo "= Mangle Rules:                                            ="
    echo "============================================================"
    $IPT -t mangle -L -v
    echo ""

}

start() {

    # Reset iptables (remove all rules & chains; reset default policies to accept everything)
    reset

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

    # create LOGDROP chain
    $IPT -N ${LOG_DROP_CHAIN}
    $IPT -A ${LOG_DROP_CHAIN} -m limit --limit 3/m --limit-burst 10 -j LOG --log-level 4 --log-prefix "${LOG_DROP_PREFIX}"
    $IPT -A ${LOG_DROP_CHAIN} -j DROP

    # create LOGACCEPT chain
    $IPT -N ${LOG_ACCEPT_CHAIN}
    $IPT -A ${LOG_ACCEPT_CHAIN} -m limit --limit 3/m --limit-burst 10 -j LOG --log-level 6 --log-prefix "${LOG_ACCEPT_PREFIX}"
    $IPT -A ${LOG_ACCEPT_CHAIN} -j ACCEPT

    # Log or not drops
    DROP_TARGET=${LOG_DROP_CHAIN}
    if [ "${LOG_DROP}" -eq 0 ]; then
        DROP_TARGET=DROP
    fi

    # Log or not accepts
    ACCEPT_TARGET=ACCEPT
    if [ "${LOG_ACCEPT}" -eq 1 ]; then
        ACCEPT_TARGET=${LOG_ACCEPT_CHAIN}
    fi

    # Accept loopback interfaces
    $IPT -A INPUT -i lo -j ACCEPT
    $IPT -A OUTPUT -o lo -j ACCEPT

    # Log & drop packets do not begin with SYN
    $IPT -A INPUT -p tcp ! --syn -m state --state NEW -s 0.0.0.0/0 -j ${DROP_TARGET}

    # Accept inbound TCP packets
    $IPT -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

####### CUSTOM RULES BEGIN

    # Accept ssh connections from subnet 192.168.2.0/24
    $IPT -A INPUT -p tcp --dport 22 -m state --state NEW -s 192.168.2.0/24 -j ${ACCEPT_TARGET}

    # Accept ssh connections from remote ip 172.23.65.1
    $IPT -A INPUT -p tcp --dport 22 -m state --state NEW -s 172.23.65.1/32 -j ${ACCEPT_TARGET}

    # Accept ssh connections from subnet 192.168.1.0/24 and mac address is 11:22:33:44:55:66
    $IPT -A INPUT -p tcp --dport 22 -m state --state NEW -m mac --mac-source 11:22:33:44:55:66 -s 192.168.1.0/24 -j ${ACCEPT_TARGET}

    # Accept http connections from anywhere
    $IPT -A INPUT -p tcp --dport 80 -m state --state NEW -s 0.0.0.0/0 -j ${ACCEPT_TARGET}

####### CUSTOM RULES END

    # Accept inbound ICMP messages
    $IPT -A INPUT -p ICMP --icmp-type 8 -s 0.0.0.0/0 -j ACCEPT

    # Drop all other traffic
    $IPT -A INPUT -j ${DROP_TARGET}
}

#============================================================================#
# Main                                                                       #
#============================================================================#

case "$1" in
  start|restart)
    start
    echo "iptables firewall enabled."
    ;;
  stop)
    reset
    echo "iptables firewall disabled."
    ;;
  status)
    status
    ;;
  *)
    echo "Usage: $0 {start|stop|restart|status}" >&2
    exit 1
    ;;
esac

exit 0

NOTE:

  • Click here to download the script;
  • You can add your rules between ####### CUSTOM RULES BEGIN and ####### CUSTOM RULES END section by modifying the script.
  • To install the script as startup script on Ubuntu/Debian Linux:
    sudo cp iptables.sh /etc/init.d/
    sudo update-rc.d iptables.sh defaults
    
  • To start the iptables firewall:
    sudo /etc/init.d/iptables.sh start
  • To enable logging on Ubuntu Linux, you also need to do this.

how to reset iptables

  • Reset iptables(IPV4):
      # set default policies to allow everything
      sudo /sbin/iptables --policy INPUT   ACCEPT
      sudo /sbin/iptables --policy OUTPUT  ACCEPT
      sudo /sbin/iptables --policy FORWARD ACCEPT
    
      # flush rules
      sudo /sbin/iptables -F
    
      # delete all user defined chains
      sudo /sbin/iptables -X
    
      # zero counters
      sudo /sbin/iptables -Z
    
      # reset all the tables
      for table in filter nat mangle; do
        sudo /sbin/iptables -t $table -F
        sudo /sbin/iptables -t $table -X
        sudo /sbin/iptables -t $table -Z
      done
    
  • Reset ip6tables(IPV6):
      # set default policies to allow everything
      sudo /sbin/ip6tables --policy INPUT   ACCEPT
      sudo /sbin/ip6tables --policy OUTPUT  ACCEPT
      sudo /sbin/ip6tables --policy FORWARD ACCEPT
    
      # flush rules
      sudo /sbin/ip6tables -F
    
      # delete all user defined chains
      sudo /sbin/ip6tables -X
    
      # zero counters
      sudo /sbin/ip6tables -Z
    
      # reset all the tables
      for table in filter mangle; do
        sudo /sbin/ip6tables -t $table -F
        sudo /sbin/ip6tables -t $table -X
        sudo /sbin/ip6tables -t $table -Z
      done
    

Mac OS X: extended file attributes

When run
 ls -la 
on Mac OS X, there are some files come with @ after the file permissions:
drwxrwxrwx@ 10 user  staff    120 Sep 30 21:11 images

The @ indicates that the file has extended attributes, to see what extended attributes on the file, you can use xattr. See xattr man page.
you can delete the extended attribute using
xattr -d attr_name file

How to flash official KDZ ROM updates for your LG P690 mobile phone

  1. You need a Windows PC (Windows XP sp3 or Windows 7 32/64 bit)
  2. Find and download the official ROM/firmware update for your LG P690 (P690F) mobile phone.
  3. Download and install Windows USB driver
  4. Download and install Software Update utility
  5. Download and extract KDZ_FW_UPD_EN.7z
  6. Configure your phone: Settings -> Applications -> Development, Tick USB Debugging
  7. Connect your phone to the Windows PC using USB cable and wait until all the drivers are installed automatically
  8. Connect the phone but DO NOT turn on USB storage
  9. Run KDZ_FW_UPD.exe as Administrator
  10. Set Type: 3GQCT           Phone Mode: DIAG
  11. Select the .kdz file you downloaded in step 1
  12. Press Lauch Software Update to start and wait (for 6~10 minutes) until you see --FINISHED-- line. (In the meantime, your phone gets into Emergency mode.)
  13. The phone should reboot itself. For me, it failed to reboot, it hangs in the LG splash logo then reboots again infinitely. To fix it, turn off the phone and then press and hold the [Power] + [Volume Down] + [Home] buttons. Wait till you see the droid with the progress bar under it then release the buttons.

See also:

Fix your bricked LG P690 mobile phone

  • NOTE: If the phone hangs at the splash LG logo, the phone may not be really bricked. Try the following to fix it:
    • Turn off the phone and then press and hold the [Power] + [Volume Down] + [Home] buttons. Wait till you see the droid with the progress bar under it then release the buttons.
  • To fix the bricked LG P690: 
    • Press and hold [Power] + [Volume Up] + [Return] buttons until gets into yellow emergency mode
  • Connect the phone to the Windows PC using USB data cable
  • Follow this guide to flash the official stock ROM

SEE ALSO

How to delete a remote git tag

The following commands remove tag: abc
git tag -d abc
git push origin :refs/tags/abc

How to view page source in your browser

  • Firefox
    • Ctrl+U on Windows/Linux
    • Command+U on Mac OS X
  • Internet Explorer
    • "View" menu then select "Source"
  • Safari
    • Command+Alt+U on Mac OS X
    • "View" menu the select "View Source"
  • Chrome
    • Ctrl+Shift+I,  then select html or body element
  • Opera
    • Ctrl+F3
    • "View" menu then select "Source"

Download official firmware/ROM updates for your LG mobile phones

  • Find your mobile phone's IMEI number, type *#06# on the dial pad, and take down the IMEI number.
  • In your web browser's address field, type the following address: http://csmg.lgmobile.com:9002/csmg/b2c/client/auth_model_check2.jsp?esn=XXXXXXXXXXXXXXX
    where XXXXXXXXXXXXXXX should be replaced with your IMEI number
  • Load the page and view page source, you can get the ROM update url inside <sw_url></sw_url> tag.

iptables: add new chains to log drop/accept messages

To create the chains to log&drop or log&accept:
# Create LOGDROP chain
/sbin/iptables -N LOGDROP
/sbin/iptables -A LOGDROP -m limit --limit 5/m --limit-burst 7 -j LOG --log-level 4 --log-prefix "[IPTFW DROP] "
/sbin/iptables -A LOGDROP -j DROP

# Create LOGACCEPT chain
/sbin/iptables -N LOGACCEPT
/sbin/iptables -A LOGACCEPT -m limit --limit 5/m --limit-burst 7 -j LOG --log-level 6 --log-prefix "[IPTFW ACCEPT] "
/sbin/iptables -A LOGACCEPT -j ACCEPT

To log & drop, here is an example:
/sbin/iptables -A INPUT -s 111.112.113.114 -j LOGDROP

To log & accept, here is the example:
/sbin/iptables -A INPUT -s 111.112.113.115 -j LOGACCEPT

SEE ALSO:

Enable iptables logging on Ubuntu Linux

The following solution can enable the iptables logging to /var/log/iptables.log:
  1. Make sure you have --log-prefix set in your iptables entries. e.g.
    iptables -A INPUT -j LOG --log-prefix "[IPTABLES "
  2. Create & edit /etc/rsyslog.d/15-iptables.conf file, and add the following lines:
    :msg,contains,"[IPTABLES " /var/log/iptables.log
    & ~
    
  3. Create & edit /etc/logrotate.d/iptables file, and add the following lines:
    /var/log/iptables.log
    {
     rotate 4
     weekly
     missingok
     notifempty
     compress
     delaycompress
     sharedscripts
     postrotate
      reload rsyslog >/dev/null 2>&1 || true
     endscript
    }
    
  4. Restart rsyslogd:
    sudo /etc/init.d/rsyslog restart

NOTE:

In the solution above, [IPTABLES is used as the --log-prefix. You can replace it with anything you like but remember to update /etc/rsyslog.d/15-iptables.conf file.


References:

syslog: log levels

Code Severity Description General Description
0 Emergency System is unusable. A "panic" condition usually affecting multiple apps/servers/sites. At this level it would usually notify all tech staff on call.
1 Alert Action must be taken immediately. Should be corrected immediately, therefore notify staff who can fix the problem. An example would be the loss of a backup ISP connection.
2 Critical Critical conditions. Should be corrected immediately, but indicates failure in a primary system, an example is a loss of primary ISP connection.
3 Error Error conditions. Non-urgent failures, these should be relayed to developers or admins; each item must be resolved within a given time.
4 Warning Warning conditions. Warning messages, not an error, but indication that an error will occur if action is not taken, e.g. file system 85% full - each item must be resolved within a given time.
5 Notice Normal but significant condition. Events that are unusual but not error conditions - might be summarized in an email to developers or admins to spot potential problems - no immediate action required.
6 Informational Informational messages. Normal operational messages - may be harvested for reporting, measuring throughput, etc. - no action required.
7 Debug Debug-level messages. Info useful to developers for debugging the application, not useful during operations.

SEE ALSO:

SyntaxHighLighter: auto line break with pre wrap

Add the following css into your html page(blog template):
<style type="text/css">
body .syntaxhighlighter .line {
    white-space: pre-wrap !important;
}
</style>

NOTE:

On SyntaxHighLither 3.0.83, enable the above css will make the line numbers go wrong. So better set gutter: false to disable the line numbers if you have long lines in the code block.

SEE ALSO:

  1. http://stackoverflow.com/questions/6286733/automatic-line-break-in-js-syntaxhighlighter
  2. https://bitbucket.org/alexg/syntaxhighlighter/issue/182/version-3-making-code-wrap
  3. http://blog.2k1y.com/2011/05/how-to-add-syntaxhighlighter-3083-on.html
  4. SyntaxHighLighter: auto line break with pre wrap
  5. SyntaxHighlighter on Blogger: how to enable border

HTML: wrap the long lines in pre with CSS

pre {
  white-space: pre;           /* CSS 2.0 */
  white-space: pre-wrap;      /* CSS 2.1 */
  white-space: pre-line;      /* CSS 3.0 */
  white-space: -pre-wrap;     /* Opera 4-6 */
  white-space: -o-pre-wrap;   /* Opera 7 */
  white-space: -moz-pre-wrap; /* Mozilla */
  white-space: -hp-pre-wrap;  /* HP Printers */
  word-wrap: break-word;      /* IE 5+ */
}

How to uninstall node.js on Mac OS X

Run the following commands to uninstall node.js:
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom | while read f; do  sudo rm /usr/local/${f}; done

sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*

Control your MacBookPro's fan speed using smcFanControl widget

Download and install smcFanControl app, you will be able to control the fan speed of you (intel) MacBook Pro. Make it cooler or quieter.

TCL: format date and time using clock

Javascript: regular expression to validate URL

function isValidURL(url) {
  var pattern = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
  return pattern.test(url);
}

GWT JSNI method:

public native boolean isValidUrl(String url) /*-{
    var pattern = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
    return pattern.test(url);
}-*/;

Firefox on Mac OS: mouse right-click on bookmark menu does not work

On Firefox for Windows/Linux, you can right-click to open the context menu to manage the bookmarks in bookmark menu. However, this is not available on Firefox for Mac OS.

The only work around I found is that you can open the bookmark, and click the "blue star" at the right end of the address field to remove/manage the bookmark. It is not as convenient as the pop up menu though.

Mac: reset PRAM, NVRAM and SMC

Ubuntu: check package version

dpkg -s <package>