Friday Dec 14, 2007

Nothing lasts forever

They say nothing lasts forever. After working for Sun five and half years, I decided to pursue another opportunity outside the company.

Sun is my first employer right after I graduated from college. I really enjoyed my time here at Sun China ERI. It's my pleasure to have chance to work with you. Thanks everyone for your support, guidance and encouragement during the past years. I'll treasure all the memories during daily work, club activities, luncheons, and table football games.

This world is small. No doubt our paths will cross again one day. Look forward to working with you gain. Good luck to you all. Take care and keep in touch.

Monday Dec 10, 2007

Mercurial TOI slides

The slides for Mercurial TOI can be found at http://blogs.sun.com/simford/resource/Mercurial-simford.pdf

Thursday Dec 06, 2007

My highest page hits

After I wrote the blog about solving the "World's Hardest Easy Geometry Problem", I got my highest page hits ever (check the snapshots, took around 21:40 Dec 6, 2007 CST). But it's weird that my blog was not listed on Popular Blogs of http://blogs.sun.com.


From page hits

From page hits

Tuesday Dec 04, 2007

Solved the World's Hardest Easy Geometry Problem

There's a famous "World's Hardest Easy Geometry Problem" in http://thinkzone.wlonk.com/MathFun/Triangle.htm, It's solved now. Here is the step by step for the solution.

From Triangle

Figure 1

From Figure 1, we have

[1] AC = BC

[2] BD = CD

 

From Triangle

Figure 2

In Figure 2, parallel to AB, we draw DF

Because [1] and AB||DF, we get

[3] DC = FC

[4] AD = BF

From Triangle

Figure 3

In Figure 3, we draw line AF.

From [4], and AB=BA, and angle DAB = FBA (=80),

the triangle ABD equals to triangle ABF. So

[5] AF = BD

From [2], AF = CD

From [3], we get

[6] AF = CF

So CAF = 20, EAF = 10, FAB = 60,

[7] DGF = 60 

[8] AB = BG = GA 

From [5], [7] and [8], we get 

[9] DF = FG = GD 


From Triangle

Figure 4

In Figure 4, we draw FH vertical to AC.

From [6] and angle CAF = ACF, we get triangle AFH equals to triangle CFH. So

[10] AH = CH 

 

From Triangle

Figure 5

In Figure 5, we draw CI.

From [10] and FH vertical to AC, we get

[11] angle DCI = DAI = 10

[12] CI = AI

From [11], we get

[13] angle FCI = 10 = DCI

[13'] angle FCI = FAI

From Triangle

Figure 6

In Figure 6, extend CI to AB.

From [13], and angle ABC = BAC = 80, we get

line CI vertical to AB,

[14] line CI is the same as line CG

From [12], [13], [14], we get triangle CEI equals to triangle AGI. So

[15] EI = GI

From [12], [15], we get

[16] CG = AE

From [13'], [16], we get triangle CGF equals to triangle AEF. So

[17] EF = FG

 

Finally 

From [9], [17], we get

[18] EF = DF

Because DF || AB, so

[19] angle CFD = CBA = 80

From [18], [19], we get

[20] angle DEF = EDF = 50

So angle X = angle DEF - angle AEF

           = 50 - (180 - 70 - 60 - 20)

           = 50 - 30

           = 20

 

Tuesday Oct 23, 2007

Add Handlers on Firefox and Thunderbird

It's quite annoying when you click on a link on Thunderbird but no browser (Mozilla or Firefox) is launched, and vice versa. It's actually quite simple to fix this by adding handlers on Firefox or Thunderbird.

  1. go to 'about:config' editor
    for Firefox, just type 'about:config' on address bar
    for Thunderbird, click on 'Edit/Preferences' menu, a dialog pops up
          then click on 'Config Editor' button on 'Advanced/General' tab

  2. right click on any existing entry, click 'New/String' menu
    for Firefox, enter 'network.protocol-handler.app.mailto' on first dialog,
          then '/usr/bin/thunderbird %s' on second dialog (\*).
    for Thunderbird, enter 'network.protocol-handler.app.http' on first dialog,
         then '/usr/bin/firefox -new-tab "%s"'.

  3. repeat step 2 for Thunderbird to add other handlers
    network.protocol-handler.app.https
    network.protocol-handler.app.ftp


That's it!

 

 

(\*) Note that the actual path name for firefox and thunderbird may vary on your environment.
(\*) Note #2: this works on all versions of Firefox, but only version 1.5 or later for Thunderbird.

Thursday Oct 18, 2007

Enable Network Services on Nevada

Some network services (sendmail, ftpd, etc) are disabled or restricted to local only on a newly installed Nevada box. We need to modify or enable them through SMF(5).

  • Enable sendmail
    # svccfg -s svc:/network/smtp:sendmail setprop config/local_only=false
    # svcadm restart svc:/network/smtp:sendmail
     
  • Enable ftpd
    # inetadm -e svc:/network/ftp:default
     
  • Enable nfs.server (this is actually enabled by default, but can be disabled by 'netservices limited')
    #### list all nfs services
    # svcs -p |grep nfs

    # svcadm disable svc:/network/nfs/server:default
    # svcadm enable svc:/network/nfs/server:default
    #


References

Thursday Sep 13, 2007

Brand new packaging system for project Indiana

In the meeting of ERI Stars with Jeff Jackson (Solaris VP && ERI Site Sponsor), Jeff mentioned that project Indiana will use a brand new packaging system, other than SVR4, dpkg (.deb) and RPM (.rpm). The details for this new packaging system is not available yet, but we can safely expect some features it will have.

  • It's brand new packaging system, similar to dpkg and RPM
  • There's not patch any more (like in SVR4)
    updates are in pkg format
  • More similar to .rpm than .deb

PS. Stevepn Hahn is working on it.

PS2: More discussion on install-dicussion@opensolaris.org alias
         http://mail.opensolaris.org/pipermail/install-discuss/2007-September/005207.html

 

Wednesday Sep 12, 2007

yet another programming languages flame war

There's a flame war on C vs. C++ programming languages recently on GIT development newsgroup: http://thread.gmane.org/gmane.comp.version-control.git/57643/focus=57918. Dmitry Kakurin asked why not C++ for GIT, then Linus replied with "C++ is a horrible language". It's not surprised that most of the GIT developers are in favour of C, we can see many analysis of the drawbacks for each language though. Walter Bright also mentioned about programming language D, and described what D is trying to achieve and how it does.

 Some interesting statements:

  • As I said, it's a matter of believes. As such, any reasoning and arguing will be endless and pointless, as for any other religious issue.  -- Dmitry Kakurin
  • The only really important part is the \*design\*. -- Linus Torvalds
  • A design is perfect not when there is no longer anything you can add to it, but if there is no longer anything you can take away. -- David Kastrup

 

Friday Aug 17, 2007

Mercurial Best Practices

These are some good practices for those who are not familiar with Mercurial Source Code Management (SCM) tool. Assuming that you are working on many Mercurial based repositories on OpenSolaris.org community, and your local workspaces are inside SWAN.

  1. understand the differences between Mercurial and Subversion
    check my other blog Differences between Subversion and Mercurial for more details

  2. register an account in OpenSolaris.org community,
    and upload your ssh pub key in your profile page

  3. subscribe to the mailing list that repository will send commit notifications to,
    otherwise the mailing list will reject the notification email for your putbacks

  4. create proper $HOME/.hgrc file
    [ui]
    username = [your account on OpenSolaris community]

    [extensions]
    hgext.fetch =

  5. use ssh proxy if you cannot connect to hg.opensolaris.org server directly
    vi $HOME/.ssh/config
    Host \*.opensolaris.org
             ProxyCommand /usr/lib/ssh/ssh-socks5-proxy-connect -h [socks proxy address] %h %p
    you can get available sock5 proxy list from internal web page

  6. clone from SWAN parent to save time
    clone from hg.opensolaris.org directly may be very slow some times. if true,
    you can clone from SWAN parent, then re-direct the parent to hg.opensolaris.org one.
    the parent info is kept in 'default' entry of [WS]/.hg/hgrc file

  7. update local workspace before making local modifications
    this will avoid potential multiple heads mess
    note: 'hg fetch' will do 'hg pull && hg up && hg merge && hg commit' for you
              'hg fetch' cmd only available when you enable hgext.fetch extension
              in $HOME/.hgrc (tips #4)

  8. if multiple heads encountered in local workspace
    please use 'hg merge && hg commit' to eliminate it locally.
    DO NOT use 'hg push -f' to force the putback,
    otherwise it will propagate the heads to the parent workspace!

    you can also use 'hg rollback' to undo last commit
    scenario:
    you make local modifications, then 'hg commit'.
    after that, you also 'hg pull && hg up', then two heads encountered.

    solution:
    --  'hg rollback' to undo last commit
    --  'hg pull && hg up' to update workspace
    --  'hg ci' again to commit local modifications
    --  'hg push' to put back your commits

    reference:
    check 'hg help rollback' for more details

Thursday Aug 16, 2007

svn2svn.py

There's not a good tool to replicate Subversion repository yet.

Although it's easy to use 'svnadmin dump' in server side to replicate the Subversion repositories. But most of the case, we don't have the privilege to access to Subversion server.

There's a client side tool svn2svn.rb though, which is written in ruby. But I don't like the way it works: check out each revision separately, commit back the output from cmd 'diff -Naur [rev-1] [rev]'. This would require a huge amount of disk space when there are lots of revisions and each revision is quite large (my case: 3400+ revisions, 2GB each revision from rev 2000 and on).

So I decided to write a new tool myself. After searching on Internet, I found a related tool: hgsvn, which create Mercurial repositories from Subversion repositories. It's written in Python. There are several modules in svnclient.py are re-usable for my svn2svn tool. So I created svn2svn.py based on it.

Hope I'm not reinventing the wheel. More information can be found from project page:
http://code.google.com/p/svn2svn/


Sunday Jul 22, 2007

5 years of service at Sun

I didn't know I can stay in a place so long when I joined Sun Microsystems (China) ERI 5 years ago in July 1st, 2002. I did it. And I know I'm actually quite young comparing to those folks who work for Sun 10 years, 15 years, or even more.

It's not easy to stay in one place for a long time. The longest record for staying in one place is my university. I spent 7 years there for undergraduate (for Bachelor Degree) and graduate (for Master Degree) study. The second one is here at ERI, I stay here more than 5 years now ( :) ). The 3rd one is in primary school, 5 years. The 4th record should be in junior and senior high school (3 years each).

What's your records?

 

From 5th anniversary

From 5th anniversary

From 5th anniversary

From 5th anniversary

Tuesday Jul 10, 2007

Install MySQL + Tomcat on Solaris

The default MySQL (4.0.24) shipped in Solaris Nevada (build 59) doesn't support UTF-8 encoding. Following are the steps to install a new MySQL on Solaris environment.

  1. download latest pkgs from www.sunfreeware.com
    mysql-5.0.41-sol10-sparc-local.gz
    openssl-0.9.8e-sol10-sparc-local.gz
    libgcc-3.4.6-sol10-sparc-local.gz

  2. with root privilege, pkgadd all pkgs

  3. setup environment for mysql
    # groupadd mysql
    # useradd -g mysql mysql
    # cd /usr/local/mysql
    # chown -R mysql .
    # chgrp -R mysql .
    # bin/mysql_install_db --user=mysql
    # bin/mysqld_safe --user=mysql &

  4. create root passwd (optional), add new account 'mysql'
    # bin/mysql mysql
    > UPDATE user SET password=password("newpasswd") WHERE user="root";
    > GRANT ALL PRIVILEGES ON \*.\* TO 'mysql'@'localhost'
        > IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
    > GRANT ALL PRIVILEGES ON \*.\* TO 'mysql'@'%'
        > IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
    > exit
    # pkill -9 mysql
    # bin/mysqld_safe --user=mysql &

  5. Import database from backup
    create backup in source mysql env
    # mysqldump -u mysql -p --opt lunch > lunch.sql

    import backup into new mysql env
    # mysql -u mysql -p
    > create database lunch;
    > exit

    # mysql -u mysql -p < lunch.sql


Here are the steps to install and deploy Tomcat.
 

  1. download latest version of tomcat binaries from tomcat.apache.org
    http://archive.apache.org/dist/tomcat/tomcat-5/v5.5.23/bin/apache-tomcat-5.5.23.tar.gz

  2. install
    # cd /usr/local
    # gunzip < [path]/apache-tomcat-5.5.23.tar.gz | tar xvf -
    # ln -s apache-tomcat-5.5.23 tomcat

  3. install jdbc mysql connector
    # cp [path]/mysql-connector-java-5.0.3-bin.jar /usr/local/tomcat/common/lib

  4. start
    # export JAVA_HOME=/usr/java
    # /usr/local/tomcat/bin/startup.sh

 


 

Add MySQL and Tomcat in the startup scripts of apache2:

 

  1. append following lines in /usr/apache2/bin/envvars

    MYSQL=/usr/local/mysql/bin/mysqld_safe
    [ -x $MYSQL ] && $MYSQL --user=mysql &

    TOMCAT=/usr/local/tomcat/bin/startup.sh
    [ -x $TOMCAT ] && $TOMCAT

menuDataProvider.findFirst() failed

When developing my small project based on JSF (Visual Web Pack) on NetBeans 5.5.1, I encountered a weird stuff -- the following codes don't work as expected, I always got 'Something wrong' warnings.

Integer dishID = new Integer(1);
RowKey rkMenu = menuDataProvider.findFirst("id", dishID);
if (rkMenu == null) {
info("Something wrong!!"):
return null;
}
info("You're lucky!!");

 

I found the cause when I tried to do manually searching:

menuDataProvider.refresh();
menuDataProvider.cursorFirst();
Integer curDishID = (Integer) menuDataProvider.getValue("id");

 

There is an Exception in the last line of above code snippet: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer.

This is pretty weird to me, since the property of menu.id is INTEGER in MySQL database. After double checking the design of menu database, I found that menu.id also has a UNSIGNED property. JSF (or Java) will map INTEGER column into Integer datatype, but will map INTEGER|UNSIGNED column into Long datatype. That may be the root cause.

Solution is pretty straightforward -- either remove the UNSIGNED property in database, or use Long datatype when accessing INTEGER|UNSIGNED column.


References:

Thursday Jul 05, 2007

Force Canonical Hostnames in Web Server

People like to use the short hostnames to access a web server, eg, http://agc163/ or http://agc163.prc/. It would be better that apache (httpd) can re-direct this request to a canonical hostname, thus we can force the use of canonical hostnames. Code snippet in httpd.conf:


RewriteEngine on
Options +FollowSymLinks
RewriteCond %{HTTP_HOST}   !\^agc163\\.prc\\.sun\\.com [NC]
RewriteCond %{HTTP_HOST}   !\^$
RewriteRule \^/(.\*)         http://agc163.prc.sun.com/$1 [L,R]

 Reference: http://httpd.apache.org/docs/1.3/misc/rewriteguide.html

Tuesday Jul 03, 2007

Support Chinese in JSF, NetBeans

I'm developing a small project based on the JSF (Visual Web Pack) on NetBeans 5.5.1. It works pretty well at the beginning. But when I tried to input some Chinese characters in the form, and save it into MySQL database through menuDataProvider.commitChanges(), it didn't work. The Chinese chars will become '?' next time it's retrieved and displayed.

Solution: JSF is based on UTF-8 already. But by default, the connection to mysql db is using ISO8859_1 encoding. Adding encoding info in the connecting url string in context.xml file should fix this issue.

url="jdbc:mysql://127.0.0.1:3306/lunch?useUnicode=true&amp;characterEncoding=UTF-8"

 

About

simford

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today