Wednesday, March 13, 2013

Coldfusion Error: "Value can not be converted to requested type."

Symptom: All of a sudden the test cases that worked before, stopped working. Error message is: "Value can not be converted to requested type.". Wasted hours trying to diff and check typos with no avail. Finally, surrender, and Googled the following article published in 2006:

ColdFusion Query Error: Value Can Not Be Converted To Requested Type

http://www.bennadel.com/blog/194-ColdFusion-Query-Error-Value-Can-Not-Be-Converted-To-Requested-Type.htm

So, it is an old problem that never go away. Everything clicks now. Database schema was just updated with a few new columns. "SELECT *" combined with CFQUERYPARAM seems to have some caching issue and everything just messed up from there.

Solution? remove SELECT *, change to use explicit column names. The problem simply goes away for good.

Friday, March 01, 2013

HTML + JavaScript Charting Solutions

  • Ext JS, Example (good for intranet application)
  • d3.js (extremely popular at this moment)
  • Dojo Charting
  • YUI Chart
  • Google Chart (Big down side, at least at this time, is that Google will receive every single data point you want to plot. Not a good thing for any data that requires privacy!)
  • Flotr2
  • Flash charts? lots of good choices there, but not accessible on mobile clients, and in danger of being completely out in a few years?

Tuesday, February 19, 2013

Support JSONP in Coldfusion

Let say you already have a Coldfusion page that serves JSON data to your AJAX web application, now you want to support JSONP from cross domain client call. Here is the code snippet that will do it:

Solr in Coldfusion 9


Some tips for using Coldfusion 9 Solr search:
  • Lesson Number 1: Make sure you review ALL the files under your collections \conf folder, many of them need to be commented out or changed from default values. Here is an incomplete list of what I changed:
    • Commented out words in protwords.txt
    • Deleted content in spellings.txt
    • Updated synonyms.txt, deleted the test words, and added new synonyms based on the vocabulary specific to my application's domain
    • schema.xml:
      • Updated default query operator from AND to OR
    • solrconfig.xml
      • commented out "solr", "rocks" and other similar configurations
    • Enable term highlighting (see http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSe9cbe5cf462523a0-5bf1c839123792503fa-8000.html \), but it's still not quite there. Still looking for a complte solution for this one.
  • In Coldfusion Admin, change Solr buffer limit from default value 40 to 80 (http://bloggeraroundthecorner.blogspot.com/2009/08/tuning-coldfusion-solr-part-1.html)
  • Ensure "Coldfusion 9 Solr Service" is started and set to "Automatic" startup type
  • To access Solr collection from remote Coldfusion servers, 
    • For the remote CF servers: change Solr server name in Coldfsuion Admin, DATA & Service > Solr Server > Solr Host Name
    • For the Solr Host: Allow remote server to have access to its Solr instance. Configure Jetty to listen on all incoming IP address. Coldfusion's default configuration is allow only 127.0.0.1, thus disabling remote CF server's access to it's hosted Solr instance. To change this, just open jetty.xml in {coldfusion home}\solr\ect, and comment out the host line which restricts to listen on 127.0.0.1 only (interestingly, I found this solution from this link: http://helpx.adobe.com/coldfusion/kb/coldfusion-9-limit-access-solr.html, which claims Coldfusion's default configuration is to listen on all ip addressed
  • Web access to Solr admin: http://{Your CF Server Name}:8983/solr/
  • Last and a big one, when you try to update multiple indexes, you will see error like this:
Error_opening_new_searcher_exceeded_limit_of_maxWarmingSearchers4_try_again_later

Stack Trace:
...
org.apache.solr.common.SolrException: Error_opening_new_searcher_exceeded_limit_of_maxWarmingSearchers4_try_again_later

Error_opening_new_searcher_exceeded_limit_of_maxWarmingSearchers4_try_again_later

request: http://localhost:8983/solr/.../update?commit=true&waitFlush=false&waitSearcher=false&wt=javabin&version=1
    at org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:424)
    at org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:243)
    at org.apache.solr.client.solrj.request.AbstractUpdateRequest.process(AbstractUpdateRequest.java:105)
    at coldfusion.tagext.search.SolrUtils.commitToServer(SolrUtils.java:1024)
    at coldfusion.tagext.search.SolrUtils.addDocument(SolrUtils.java:664)
    at coldfusion.tagext.search.IndexTag.doQueryUpdate(IndexTag.java:929)
    at coldfusion.tagext.search.IndexTag.doStartTag(IndexTag.java:254)
    at coldfusion.runtime.CfJspPage._emptyTcfTag(CfJspPage.java:2722)


This error will be consistently showing up in production environment with even very light traffic, and became a big show stopper for the usage of Solr collection provided by Coldfusion (does not seem to be a Solr problem, instead a problem of Coldfusion integration problem). 

Root cause seems to be that Coldfusion commits every index update, and causing excessive Solr searcher warming. Combining with misconfigured default Solr configuration, this problem starts to appear for a collection of only a few hundred entries.

In Coldfusion 10, this problems seems like easier to solve by using the newly introduced "autoCommit" attribute, which should always be "no" (i.e. never use the default value). Then I guess configuring the "autoCommit" in solr config file will solve the above problem in Coldfusion 10.

However, production environment that is already in CF 9 is stuck. My solution for it is a combination attack:
    • Manually throttle cfindex update by adding a sleep after every update
    • Wrap try catch block around the cfindex update, then add a longer sleep time in the catch block, and add retry logic to try update again after the sleep
    • Database flag of index entries, this flag will be set only after index is updated successfully. A scheduled CF task will scan this flag to identify missed updates (due to the above error), and try to update index again
The above approach so far allows me to update thousands of indexes without any problem.

Wednesday, October 10, 2012

Downloadify Stopped Working in Google Chrome

Downloadify uses Flash's download functionality to enable client side download. It saves server side roundtrip.  There is also nice user extensions using Downloadify to export ExtJS grid on the client side. HTML 5 does have some limited support of client side download, but it suffers inconsistent support between browsers.

Ok, after all the justification for using it, Downloadify stopped working for Google Chrome recently. And here are the observations:
  • Environment: Windows, Google Chrome is up-to-date
  • Download still works in IE and Firefox;
  • Download only works in Chrome if I'm testing using Intranet URL. But it does not work if the URL looks like Internet address (i.e. http://localhost works, but http://10.10.10.1 won't work);
  • IE, Firefox are on Flash 11.3, and Chrome is running Flash 11.4
Solution:
Not really a solution. It's more like a workaround.
  1. In Chrome address bar type: "about:plugins"
  2. Click on "Details" button to expand into more detailed view
  3. Find "Flash" section, and disable the Flash player 11.4 (something called "PepperFlash"\"pepflashplayer.dll")
  4. Make sure there is another Flash player listed here, which should be Adobe's distribution

Root Cause?
I can only guess. Still not sure why and how to fix it properly.
Turns out Google Chrome has it's own Flash distribution. (Only guessing) It seems to be different from Adobe's official one, and somehow has higher default security settings.

itemId and id in ExtJS

The story: 
Here is a lesson for not reading document thoroughly. My very first ExtJS project goes smoothly until one day I created multiple tabs, and then closed some of them. All of sudden the layout completely messed up. In the debug console, there is null reference error. Call stack is deep in the ExtJS library.

Fast forward, after several hours of digging around, I found out I was using "id" config for several ExtJS controls. Then, close tab action will cause all the controls on the other tabs with the same "id" got deleted from DOM.

Solution:
Use "itemId" instead of "id" config for controls.

Comparison to ASP.NET
Came from ASP.NET world, I guess that is why I was using "id" config without any second thought. Below is a comparison of similar concepts in ASP.NET

ExtJS ASP.NET _
itemId  ID  (Recommended) HTML element's ID is automatically generated to ensure uniqueness, usually by concatenating ID of the container hierarchy. Programmer only need to ensure ID is unique within it's container.
id  ClientID  (Not recommended) Rendered HTML element will use this property as their ID. It's programmer's responsibility to ensure it is unique across the whole page (think when you starting to have multiple instances of the same control on a page).

(To check out more ExtJS related posts from me, click here: http://developertips.blogspot.com/search/label/ExtJS)

Monday, March 12, 2012

ASP.NET Exception: "Session state has created a session id, but cannot save it ..."

Symptom:
  • Only happens for new session
  • Exception Message:
    A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll Additional information: Session state has created a session id, but cannot save it because the response was already flushed by the application.
  •  Stack Trace: 
[HttpException (0x80004005): Session state has created a session id, but cannot save it because the response was already flushed by the application.]   System.Web.SessionState.SessionIDManager.SaveSessionID(HttpContext context, String id, Boolean& redirected, Boolean& cookieAdded) +3691007   System.Web.SessionState.SessionStateModule.DelayedGetSessionId() +199   System.Web.SessionState.SessionStateModule.ReleaseStateGetSessionID() +25   System.Web.SessionState.SessionStateModule.OnReleaseState(Object source, EventArgs eventArgs) +874   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +80   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +270 

Cause:
  • I was able to narrow down the cause of this problem to setting page's Buffer="false"
  • Reasoning would be that without buffering, all content are pushed to client immediately, and somehow, ASP.NET decided to set cookie at a very late stage where it can no longer write to HTTP header to set SessionID cookie
Solution:
Set Buffer to true is not a solution for me, because I will need to flush content to deliver real-time progress information.
Based on some understanding, a solution quickly came up with some Google search. Simply add the following line to Global.asax.cs > Session_Start, the problem is resolved.
string sessionID = Session.SessionID;

Wednesday, February 15, 2012

Faster Flex Builder Compile Time

To increase Flex Builder compile time during development, the following tweak helped my Flex 3 builder to go from 30 seconds to just a few seconds for a medium sized project.
Open project property, under Flex Compiler -> Additional compiler arguments, add " -incremental -keep-generated-actionscript"

It definitely helps me go from compile once every hour, to every few minutes. Such that I can get immediate feedback through compiler errors or warnings.

Monday, February 13, 2012

file 'lib' not found

When installing Ruby on Rails using command: gem install rails
Got this error message: file 'lib' not found
Seems like it's fixed by running gem instal rdoc followed by gem install rails again.

Tuesday, January 17, 2012

Cross Site XMLHttpRequest

  • IE8 and above:
    • use XDomainRequest instead
    • Can only cross from HTTP to HTTP or HTTPS to HTTPS (i.e. if web page is served from HTTP, then cannot cross-site access HTTPS. Or web page served over SSL cannot cross site access HTTP content. Will get "Access Denied" error.)
  • Cross site request server must send this response header:  Access-Control-Allow-Orig *

Friday, December 02, 2011

Useful Sysinternals Utilities

As a software engineer (not system administrator), I found the following tools from Sysinternal to be useful.
  • Autoruns: mainly used to turn off unnecessary executables during boot and login to speed up system boot performance
  • Portmon: used to monitor serial port traffic (similar to wireshark for network traffic)
  • Process Explorer: used mainly to find file locks, so that I know which process to kill to be able to free up the lock.
  • Process Monitor
  • PsExec: remote execute console application. Examples:
  • psexec \\vm-001 ipconfig /all
  • psexec \\vm-001 cmd
  • This command copies the program test.exe to the remote system and executes it interactively: psexec \\vm-001 -c test.exe
  • PsKill: kill local or remote processes. Mainly used in server software for house keeping (for example: kill stuck Office Automation process)
  • PsService
  • ZoomIt: usefuly for presentation. Zoom in screen, draw lines on the screen.

Friday, October 28, 2011

Disable Touchpad on Dell Laptop

Problem
Ever frustrated with Touchpad being overly sensitive?

I frequently got random mouse movements and clicks while using Laptop's keyboard. They are caused by the Touchpad being overly sensitive. It is especially a problem when I am using remote desktop working on another computer. I guess the Touchpad sensitivity settings does not work on remote desktop client?

And this is a major frustration, because when I finish typing a line of code, they frequently show up on the wrong line, and did not show up anywhere at all, because the random mouse clicks has took their focus away.

Research
Today, finally it struck me that I should disable this thing. And turns out the latest DELL tool has some nice options available. For one thing, I can permanently enable/disable "Pointing Stick", "Pointing Stick Buttons", "Touchpad", and "Touchpad Buttons". But, there is also a very nice feature called: "Disable Touchpad/Point Stick when external USB mouse is present". This is really a very user friendly feature that I never thought of searching for before.

Conclusion
I put a check next to the option:  "Disable Touchpad/Point Stick when external USB mouse is present", and got a wireless mouse. Problem solved. Happily typing code again.

Monday, October 10, 2011

Portable Mouse with a Hook or Loop

Goal: to allow portable mouse to be even more portable

Going to meeting with a laptop, a pen and notebook (made with paper) and a mouse can be a handful (not to mention when you have a cup of coffee). What if we have a hook or ring on the mouse so that it can dangle on a finger (or belt?).
 
Potential Solutions
- retractable ring
- foldable ring
- hook

Need to pay attention of location of ring or hook so that they don't interfere with normal mouse use.

Saturday, September 03, 2011

Adobe Flash Builder 4 and Coldfusion Builder crash during startup

Symptom: all of sudden, my Flash Builder 4 and Coldfusion Builder can not be started. They will crash during start. They are running on Eclipse 3.4.2, and 3.5.2 respectively.

Diagnostic: Coldfusion builder simply show me an error dialog without any useful information. It just generically states something like: Visual C++ request application to exit in abnormal way.
Of course, I tried to reset Eclipse and clear it's workspace to no avail.
However, luckily, Flash Builder 4 throws an exception. And I got a chance to start Visual Studio 2010 debugger session on it. Once in Visual Studio debugger, I saw exception type "bad_day_of_month" from boost library. Then I turn to "Stack Trace" tab, and saw callstack: Kernel32->atmlib.dll->UpdateNotifications.dll. A little Google on this end turned up a thread talking about similar problem from other Adobe users. So, I read the thread, it starts to mention how the "UpdateNotification" library will look at Windows Scheduled Tasks for Adobe updater. Then it occurs to me what might be, and later proven to actually be the root cause.

Cause: A few days earlier, in an effort to speed up my computer, I ran "AutoRuns" utility from "System Internals", and disabled a bunch of "Scheduled Tasks". Among them was a task named "AdobeAAMUpdater-1.0......".

Fix: using "AutoRuns" utilities, I turned the "AdobeAAMUpdater-1.0....." scheduled task back on. Then Flash Builder 4 and Coldfusion Builder are all back to normal.

Monday, August 08, 2011

SQL Maintenance Plan Failed

Environment: SQL 2005
Symptom: Scheduled SQL maintenance plan to do partial backup failed. Got two message logged in SQL Server log:
Error: 3041, Severity: 16, State: 1
BACKUP failed to complete the command BACKUP DATABASE master WITH DIFFERENTIAL. Check the backup application log for detailed messages.
Cause: Master database does not support partial backup. So, if the task is for "Differential" backup, "master" database should not be included.
Solution: Open the plan details, in the "Database(s)" section make sure database that needs to be backup are explicitly selected, instead of having "All databases" checked.


Monday, August 01, 2011

Coldfusion Webservice Input Name Changed to in0

Symptom: Coldfusion webservices sometimes complain about input parameter "In0"

Environment: Coldfusion 9 on Windows

Solution: Login to Coldfuion 9 Administrator portal, Go to Server Settings > Caching, click on "Clear Template Cache Now" and "Clear Component Cache Now". This seems to trigger to re-compile of webservices WSDL thus fixed the problem.


However:
  1. I don't know what is the root cause of this problem. Google turn-up some similar complains, but could not find any official answers on this
  2. The solution which required human interaction does not help in production environment
  3. The solution does not solve the problem permanently, sooner or later I'll hit the same error, and has to go back to the server and clear cache again

Wednesday, May 11, 2011

CFQUERYPARAM: LIST and SEPARATOR attributes

Adobe online document only listed these two attributes without much explanation. I found the following link with very thorough explanation of the effects and usage of these two attributes:
http://www.pukkared.com/2011/01/using-cfqueryparam-list-attribute-when-using-in-operator/

Tuesday, May 03, 2011

NUnit Integration With Visual Studio 2010

I just discovered the perfect tool for NUnit integration: Visual Nunit 2010

Here are the pros:
  • Open source, Apache License
  • GUI: I personally like it better than the official Nunit GUI
  • Visual Studio Integration: of course, this is the #1 reason I try it out, and I'm completely satisfied
  • Load config file without problem (Nunit project does not load config files correctly)
  • Debug: attach to Nunit or Nunit-agent is no longer needed, simply set breakpoints and click the red  arrow to start debug session
  • Easy drilldown of test cases
  • One click to execute any individual test cases
Cons? None so far.

Thursday, April 21, 2011

Server Side Office Automation using ColdFusion

Tips after fighting to get robust Office Automation using ColdFusion 9.


Definitions
COM: Microsoft Component Object Model.
Automation: the process of launching another application and controlling it programmatically through a public interface.

Environment
ColdFusion 9
Office 2007 SP2

Tips
  • Pay attention to Office version (down to minor rev numbers), I encountered several major differences  between Office 2007, and Office 2007 SP2 (no to mention the differences between 2003 and 2007)
  • Server setup
    • CF service account must be interactive
    • Office installation need to select option to install all features locally
    • After Office installation, need to login as service account, and start Office applications and click through license agreement, registration, ...
  • Open Office applications with Visible=false may have negative impact on it's behavior (At least for Powerpoint, I found some layout options are not functioning correctly if application is started in invisible mode. Specifically, I was trying to set text box property: "Shrink text on overflow", by setting AutoSize=2 (msoAutoSizeTextToFitShape), it won't work unless Powerpoint application is created in visible mode.)
  • Before even start ColdFusion code, I usually test my script using VBS, then translate to CFScript, however, CFScript have some minor difference from VBS:
    • VBScript can use array notation or foreach on some collections, but CFScript  usually has to access the 'items' accessor
    • Explicit type conversion may be necessary in some COM function calls, use "JavaCast". In my case, I got this error message:
An exception occurred when executing a COM method. 
The cause of this exception was that: AutomationException: 0x80048240 - Item 1 not found in the Designs collection. in 'Microsoft Office PowerPoint 2007'. 
Code causing the problem: objPresentation.Designs.Item(1)
Reason: ColdFusion is not type safe. COM definition for this input parameter is variant type. Seems like ColdFusion trying to send it over in string format "1" instead of numeric value 1.
Solution: objPresentation.Designs.Item(JavaCast("int", 1))
    • VBScript can use enumerates just by name, CF does not have that luxury, you have to find out the numeric values for each of the enumerations, please see my other post for list of some numeric values: Some Enum Values for Office COM Object.
  • To find out numeric values, I used Visual Studio to add reference to Office library, then I can easily navigate or search for enums
  • One way to implementation robust automation:
    • Main CFC
      • Create a worker thread to do automation task
      • Wait for the thread with timeout
      • After wait is finished, if it's timeout, will kill automation application, kill thread, and cleanup, else we have successfully done!
    • Automation thread
      • Global lock on Office Application name (avoid concurrency issue)
      • Create automation object
      • <<do you thing>>
      • quit automation object
      • ReleaseCOMObject
      • cleanup
  • To cleanup, I use "pskill" to kill office processes, so that a single failed call won't block all future automation attempts
  • Code segment to create automation object

Server Side Office Automation Problems
  • Office applications are not designed for server environment
  • Concurrency (Office applications are non-reentrant, STA based automation, use global shared resources)
  • Scalability
  • Security
  • May lock up on launch or any point during execution if there are modal dialog popup (typically you will see license agreement, error messages, “install on first use”, … dialogs)
  • License considerations: each client must have licensed copies of Office
  • Officially discouraged by Microsoft
“Microsoft does not recommend or support server-side Automation of Office”
Alternatives
  • CFSpreadsheet
  • HTML/XML based format for word and excel
  • OOXML (Open XML file format)
  • Excel Services (Since Sharepoint Server 2007)
  • Word Automation Services (Since Sharepoint Server 2010)
  • Server libraries: Apach POI, Microsoft Open XML SDK
Reason to Stick with Automation Approach
  • After the above "Problems" section, the biggest incentives to use automation are
    • Need to invoke Excel macro or solution package on server side
    • You already have some fancy VBS code that can do what you wanted through Office automation

References

Adobe. 2011. ColdFusion Developer’s Guide. Last Accessed April 19, 2011. http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Part_4_CF_DevGuide_1.html
Forta, Ben and et al. 2005. Advanced Macromedia ColdFusion MX 7 Application Development, Chapter 26 Extending ColdFusion with COM. Macromedia Press. http://www.forta.com/books/0321292693/0321292693_chapter26.pdf
Microsoft. 2011. KB 257757: Considerations for server-side Automation of Office. Last Accessed April 19, 2011. http://support.microsoft.com/kb/257757

Friday, March 25, 2011

Some Enum Values for Office COM Object

Actual integer values for several Office 2007 (12.0) COM Enums

Microsoft Office Core


MsoAutoSize

msoAutoSizeMixed-2
msoAutoSizeNone0
msoAutoSizeShapeToFitText1
msoAutoSizeTextToFitShape2

Word


WdSaveFormat

wdFormatDocument970
wdFormatDocument0
wdFormatTemplate971
wdFormatTemplate1
wdFormatText2
wdFormatTextLineBreaks3
wdFormatDOSText4
wdFormatDOSTextLineBreaks5
wdFormatRTF6
wdFormatUnicodeText7
wdFormatEncodedText7
wdFormatHTML8
wdFormatWebArchive9
wdFormatFilteredHTML10
wdFormatXML11
wdFormatXMLDocument12
wdFormatXMLDocumentMacroEnabled13
wdFormatXMLTemplate14
wdFormatXMLTemplateMacroEnabled15
wdFormatDocumentDefault16
wdFormatPDF17
wdFormatXPS18
wdFormatFlatXML19
wdFormatFlatXMLMacroEnabled20
wdFormatFlatXMLTemplate21
wdFormatFlatXMLTemplateMacroEnabled22
wdFormatOpenDocumentText23

WdExportFormat

wdExportFormatPDF17
wdExportFormatXPS18

WdAlertLevel

wdAlertsMessageBox-2
wdAlertsAll-1
wdAlertsNone0


PowerPoint


PpSaveAsFileType

ppSaveAsPresentation1
ppSaveAsPowerPoint72
ppSaveAsPowerPoint43
ppSaveAsPowerPoint34
ppSaveAsTemplate5
ppSaveAsRTF6
ppSaveAsShow7
ppSaveAsAddIn8
ppSaveAsPowerPoint4FarEast10
ppSaveAsDefault11
ppSaveAsHTML12
ppSaveAsHTMLv313
ppSaveAsHTMLDual14
ppSaveAsMetaFile15
ppSaveAsGIF16
ppSaveAsJPG17
ppSaveAsPNG18
ppSaveAsBMP19
ppSaveAsWebArchive20
ppSaveAsTIF21
ppSaveAsPresForReview22
ppSaveAsEMF23
ppSaveAsOpenXMLPresentation24
ppSaveAsOpenXMLPresentationMacroEnabled25
ppSaveAsOpenXMLTemplate26
ppSaveAsOpenXMLTemplateMacroEnabled27
ppSaveAsOpenXMLShow28
ppSaveAsOpenXMLShowMacroEnabled29
ppSaveAsOpenXMLAddin30
ppSaveAsOpenXMLTheme31
ppSaveAsPDF32
ppSaveAsXPS33
ppSaveAsXMLPresentation34
ppSaveAsOpenDocumentPresentation35
ppSaveAsExternalConverter36


PpAlertLevel
ppAlertsNone1
ppAlertsAll2


PpAutoSize
ppAutoSizeMixed-2
ppAutoSizeNone0
ppAutoSizeShapeToFitText1

PpSlideLayout
ppLayoutMixed-2
ppLayoutTitle1
ppLayoutText2
ppLayoutTwoColumnText3
ppLayoutTable4
ppLayoutTextAndChart5
ppLayoutChartAndText6
ppLayoutOrgchart7
ppLayoutChart8
ppLayoutTextAndClipart9
ppLayoutClipartAndText10
ppLayoutTitleOnly11
ppLayoutBlank12
ppLayoutTextAndObject13
ppLayoutObjectAndText14
ppLayoutLargeObject15
ppLayoutObject16
ppLayoutTextAndMediaClip17
ppLayoutMediaClipAndText18
ppLayoutObjectOverText19
ppLayoutTextOverObject20
ppLayoutTextAndTwoObjects21
ppLayoutTwoObjectsAndText22
ppLayoutTwoObjectsOverText23
ppLayoutFourObjects24
ppLayoutVerticalText25
ppLayoutClipArtAndVerticalText26
ppLayoutVerticalTitleAndText27
ppLayoutVerticalTitleAndTextOverChart28
ppLayoutTwoObjects29
ppLayoutObjectAndTwoObjects30
ppLayoutTwoObjectsAndObject31
ppLayoutCustom32
ppLayoutSectionHeader33
ppLayoutComparison34
ppLayoutContentWithCaption35
ppLayoutPictureWithCaption36

PpTextStyleType
ppDefaultStyle1
ppTitleStyle2
ppBodyStyle3

Friday, December 17, 2010

Instead of CFDUMP

Ways to inspect CFC returns in browser without using CFDUMP.

1. Using Chrome JSONView extension:
Prerequisite:
Install Google Chrome

Now just add to request URL: "&returnFormat=JSON". The CFC return will be shown in nice hierarchical which can be interactively expanded or collapsed.

2. In IE and FireFox using ServiceCapture
Prerequisite: buy and install ServiceCapture.

Still in request URL, add: "&returnFormat=JSON". In ServiceCapture, Response > JSON will show the data structure in expandable tree structure.

Friday, November 19, 2010

SQL Interview Questions

Here is a collection of Microsoft SQL Server interview questions.
Basic Concepts
  • Filtered index
  • Common Table Expression
  • Derived tables
  • Fill factor
  • Clustered Index
  • Heap table
  • OLTP vs. OLAP
  • Star schema
  • What are the differences between SQL developer, standard and enterprise editions
  • local vs. global temporary table
  • sparse columns
  • Functions: STUFF, PATINDEX, RANK, NTILE
  • SCOPE_IDENTITY vs. @@IDENTITY
  • XML support
  • Geo-spatial data support
  • CLR integration
  • Replication
Breadth
  • NoSQL
  • Column based RDBMS
Best Practices
  • What are the performance best practices
  • What are the security best practices
Coding Skills
  • How to select top N records without using TOP
  • Write a stored procedure to check out one job with columns: JobID, Status (new, checked out, done), priority
  • Write a stored procedure to atomically insert records into the following tables with error handling
Table A
---------
ID
Name

Table B
---------
ID
Name

Table A_B
---------
ID_A
ID_B

Wednesday, October 27, 2010

Tuesday, September 07, 2010

Laptop Performance vs. Network Drive

Symptom: When working from home using a company laptop, ever notice that the corporate laptop appears to be much slower on your home network? Well, I have had this problem for a while. After a closer look, I found whenever I switch to Windows Explorer or trying to open a file, it will take almost a minute for it to showup.

Root Cause: In my case, I found out the root cause is actually a bunch of network drives that are causing this performance problem.
There are 4 network mapped drives on my laptop which access various resources on intranet. Some are setup by IT so that they will be mapped whenever you boot you computer on company intranet. However, at home, connection to intranet is slow or non-existent. Whenever you make Windows Explorer visible or showing a File dialog, Windows explorer will try to map all of them one by one. That is, the more network drives you have, the longer you have to wait until Windows decide to give up on reconnecting these network drives.

Solution: I end up created a VB script to batch start/stop the mapping. At home with limit access to internet, I will run the scripts to stop all the mapped drives. At work, I will run the script to start the mapping.

The vb script to stop network drive:
Set objNetwork = CreateObject("WScript.Network")
On Error Resume Next
objNetwork.RemoveNetworkDrive "X:", "True"
objNetwork.RemoveNetworkDrive "Y:", "True"
objNetwork.RemoveNetworkDrive "Z:", "True"

To start network drive:
Set objNetwork = CreateObject("WScript.Network")
On Error Resume Next
objNetwork.MapNetworkDrive "X:" , "[your URI]"
objNetwork.MapNetworkDrive "Y:" , "[your URI]"
objNetwork.MapNetworkDrive "Z:" , "[your URI]"

Friday, September 03, 2010

What's in a RIA Software Engineer's Tool Chest

Major Power Tools
  • Microsoft Visual Studio
  • Adobe Flex Builder, Flash Builder
  • Adobe Coldfusion Builder
  • SQL Server Management Studio
Browsers
  • IE
  • FireFox
  • Google Chrome
Eclipse Plugins

Firefox Plugins
  • Firebug
  • Html Validator
  • Screengrab: take screenshots of browser content (including Flash)
  • YSlow
  • Web Developer

Free or really affordable utilities
  • Data Dictionary Creator: manage and generate data dictionary
  • Service Capture: capture HTTP traffic in/out of local computer, with built-in parser of Flash Remoting content
  • Fiddler: capture HTTP traffic, well known in .NET community
  • JSON Viewer: all you can ask for to navigate, search, format JSON data string
  • VNC: remote desktop
  • Tortois SVN, CVS, GIT: version control with Windows Explorer integration
  • Tour De Flex: Air application showcasing Flex controls and sample code
  • Skype: IM, talk, video conference, share desktop, ...
  • Google Desktop: search code, design document with ease
  • GIMP: free replacement for Photoshop
  • Sysinternals: a group of Windows Utilities now owned by Microsoft. Here are a few of my favorites:
    • Process Explorer: advance task manager, mostly used to search for locked resources
    • Port Mon: serial port traffic analyzer
    • Autoruns: manage autorun programs that can start through various mechanisms
  • Depends: Dependency Walker
  • WinMerge: graphical diff, can be easily integrated with Tortoise clients

Online Resources in Browser Bookmarks
  • Google Code Search: search open source code
  • Google Analytics: keep tab on web site usage
  • Stackoverflow: ask questions, search for answers, and answer some questions. Occasionally get job offers due to your answers here
  • EETimes: resource on embedded, semiconductor development
  • TechCrunch
  • DZONE: daily digest of tech blogs similar to TechCrunch
  • ScottGu's Blog: MSFT VP of several .NET products
  • MIX: Video, PPT of past conference
  • PDC: Video, PPT of past conference
  • GOOGLE IO: Video of past conference
  • BeanStalk: online SVN server
  • Github: onlien GIT server
  • Gist: code snippet management
  • CFLib.org: Coldfusion library

Open Source Software
  • FlexLib: Flex controls
  • AS3Core: Actionscript 3 utilities
  • PureMVC: MVC framework, popular in Flex community
  • Cairngorm: official MVC framework in Flex community
  • Report.NET: .NET PDF library
  • ZedGraph: .NET chart library
  • SQLite: light-weight database, popular in embedded community
  • NUnit: .NET unit testing framework
  • FlexUnit: Flex unit testing framework
Icons
  • Java Look and Feel Graphics Repository: official JAVA icon set
  • Visual Studio Image Library: came with Visual Studio Installation
  • Web Application Icons from WebAppers.com
  • famfamfam.com

Thursday, September 02, 2010

Flex Builder - TODO, FIXME in "Tasks" view

Here is a plugin that adds support for TODO comments in "Tasks" view.
http://www.richinternet.de/blog/index.cfm?entry=911D4B57-0F0D-5A73-AF6F4D4D04099757

It was created for Flex Builder 2 in 2006, but I tested, it also works for Flex Builder 3.

Here is link to the request on Adobe's JIRA: FlexBuilder should parse //TODO comments into the normal Task panel . I have voted for this issue.

However, Dirk obviously did a good job in his plugin, such that Adobe decided to defer and closed the issue!?

Wednesday, August 25, 2010

Import Android Samples into Eclipse

I am trying to open Android samples in Eclipse (with ADT installed). At first, it seems to be a tedious task, trying to import every single project. Then, I found out that ADT already has a shortcut for importing samples. Just go File > New Android Project. In the "New Adroid Project" dialog, select the Build Target, then check "Create project from existing sample". Now, in the dropdown below select the project you want to import. It is much simpler than I thought.



Well, of course, it would be even better, if the sample projects have Eclipse project in them. That will save me even more time.

Wednesday, August 18, 2010

SQL Scripts for CLR Assemblies

Here are SQL Scripts for CLR assemblies on Microsoft SQL Server.

Assumptions: assembly's name: "SQLCLR.dll".In the dll, you have an aggregate function: "ConcateAll" which concatenate all string. The dll is in database server's c:\temp directory.

To enable CLR on SQL Server:


To clean up (remove the CLR function and assembly from database)


To upload assembly to SQL Server


Create aggregate function based on CLR assembly


Grant execution permission to user

Monday, July 26, 2010

MS SQL Column Alias

T-SQL used in Microsoft SQL Server seem to have very limited support for column alias. If you have a complex calculated column that you want to re-use in GROUP, SELECT or another expression, it will be desirable to use alias to reference the same definition everywhere so that we can have a clear and easier to understand SQL statement.


Here is an article that is very helpful in this matter: Avoid Transact-SQL's Column Alias Limitations

Key points:
  • MS SQL only allow alias in SELECT and ORDER BY
  • Use sub-query, can help in some cases to re-use column alias

Thursday, July 15, 2010

Coldfusion web services call return error: java.lang.NullPointerException

Turns out Coldfusion web services return data may contain pointer, and the receiving side will try to interpret that pointer. Once we commented out the offending data (a 2D array) in return, the error is gone.

Wednesday, July 14, 2010

DELL Quickset for Latitude E-Family

Just got a new Dell Latitude E6510 laptop. However, cannot find the familiar Dell Quickset on it.

After a couple of days' casual research, I finally found the answer: Dell Control Point is the new Quickset for Latitude E-Family.

As a side note, I like E6510.
Pros:
  • Fast
  • Bright screen
  • Nice keyboard: backlight, good touch
  • Multi-touch, allow pinch zoom, rotations, and other gesture
  • ... more
Cons: none so far.

Wednesday, July 07, 2010

Syntax Highlighting on Blogger - Gist

Here is another way to paste code into blogger with nice syntax highlighting.
  1. Go to http://gist.github.com
  2. Past the code you want to post
  3. Copy the embed tag
  4. Go back to blogger, and select "Edit Html"
  5. Paste the embed tag into your post
Below is the example source code using this tag: <script src="http://gist.github.com/467670.js?file=gistfile1.sql"></script>




A potential drawback of this approach might be the stability of github as a company. In a downturn, it may shut down with very short notice.

Compare to using SyntaxHighlighter, personally, I think this approach is way better:
  1. No setup required (in a previous post I documented how to setup syntaxhighlighter for blogger, it took me half an hour to setup everything correctly. Now with gist, there is zero setup required );
  2. Faster to create code snippet in a post;
  3. Supports more languages;
  4. No need to worry about pasting XML, HTML, or other special characters;


To paste script like below used to require replacing '<' with &lt; and '>' with &gt; manually. Now is simply copy paste without any manual changes:

Flex Builder Error 1046: "Type was not found or was not a compile-time constant"

Problem:
While editing a big .as file in Flex Builder 3, the compile is broken suddenly. Got this error:
1046: Type was not found or was not a compile-time constant: ?????.


Cause:
Seems like Flex editor tend to wrongly remove import statement at the top of .as file without user consent.

Solution:
Disable Flex Builder feature:
Windown > Preferences > Flex > Editors > ActionScript Code, uncheck "Remove unused imports when organizing"

Tuesday, June 29, 2010

ColdFusion Builder Error: "Unhandled event loop execution"

Environment: Eclipse 3.5, ColdFusion Builder Plugin, Aptana

Problem:
Whenever I open a Coldfusion file, will see error "Unhandled event loop exception." followed by a dialog: "An error has occured. See error log for more details. CFMOutlinePage_0".

Cause:

Turns out CF Builder is using Aptana which conflict with the lastest Aptana.

Solution:
Disable Aptana:
  • Disable Aptana: Windows -> Preferences -> General -> Startup and Shutdown, uncheck all Aptana plugins;
  • Disable Aptana Update: Windows -> Preferences -> Install/Update -> Available Software Sites, disabled all Aptana sites;
  • Restart Eclipse using the "-clean" command line, and the problem seems to be fixed now.
Another riskier solution is to uninstall Aptana Studio from Eclipse.
  • Copy current Eclipse directory for backup;
  • Help > About Eclipse > Installation Details > Installed Software > Aptana Studio > Uninstall
More Info:
---------------Detailed Error Log-------------------------
eclipse.buildId=
java.version=1.6.0_20
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en_US
Framework arguments: -product org.eclipse.epp.package.jee.product
Command-line arguments: -os win32 -ws win32 -arch x86 -product org.eclipse.epp.package.jee.product -clean


Error
Tue Jun 29 10:45:04 PDT 2010
Unhandled event loop exception

org.eclipse.swt.SWTException: Failed to execute runnable (java.lang.NoSuchFieldError: EditorUpdaterThread_0)
at org.eclipse.swt.SWT.error(SWT.java:3884)
at org.eclipse.swt.SWT.error(SWT.java:3799)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:137)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3885)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3506)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2405)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2369)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2221)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:500)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:493)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:113)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:194)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:368)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:559)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
at org.eclipse.equinox.launcher.Main.run(Main.java:1311)
Caused by: java.lang.NoSuchFieldError: EditorUpdaterThread_0
at com.adobe.ide.editor.cfml.EditorUpdaterThread.createDelayedRefreshJob(EditorUpdaterThread.java:340)
at com.adobe.ide.editor.cfml.EditorUpdaterThread.access$1(EditorUpdaterThread.java:338)
at com.adobe.ide.editor.cfml.EditorUpdaterThread$1.run(EditorUpdaterThread.java:265)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:134)
... 22 more

-------------Screenshot of the error dialog--------------------------------------

Thursday, June 24, 2010

Visaul Studio Strong Name Error - Importing key file "X.pfx" was canceled

Problem:
Getting a new computer, so I installed fresh Visual Studio 2010, and checked out source code from SVN. Then I got the following errors:

Cannot import the following key file: X.pfx. The key file may be password protected. To correct this, try to import the certificate again or manually install the certificate to the Strong Name CSP with the following key container name: VS_KEY_F...


Importing key file "X.pfx" was canceled
Solution:
Run this command line:
sn -i X.pfx VS_KEY_F...

Wednesday, June 23, 2010

Flex Compiler Error - Could not resolve * to a component implementation

While extending MX control ComboBox, I am trying to alter it's property.

<mx:dropdownfactory>
<mx:component>
<mx:tree change="outerDocument.updateLabel()" height="200" allowmultipleselection="{outerDocument.allowMultipleSelection}" showroot="{outerDocument.showRoot}" showdatatips="true" datatipfield="{outerDocument.labelField}">
</mx:tree>
</mx:component>
</mx:dropdownfactory>

I got the compiler error as stated in the tile. Turns out I should refer to the property using my custom control's own name space. So the code should be like this:

<local:dropdownfactory>
<mx:component>
<mx:tree change="outerDocument.updateLabel()" height="200" allowmultipleselection="{outerDocument.allowMultipleSelection}" showroot="{outerDocument.showRoot}" showdatatips="true" datatipfield="{outerDocument.labelField}">
</mx:tree>
</mx:component>
</local:dropdownfactory>

SQL 2005 on Windows XP SP3 - MSXML6 Error

Problem:
With a fresh Windows XP SP3, I cannot install SQL 2005. The error message in log file is:
Property(S): SupportedOSMessage = Installation of this product failed because it is not supported on this operating system. For information on supported configurations, see the product documentation.
Property(S): ShortCutText = MSXML 6 Service Pack 2 (KB973686)
Property(S): DialogTitle = MSXML 6 Service Pack 2 (KB973686) Setup
Property(S): ProductName = MSXML 6 Service Pack 2 (KB973686)
Property(S): ShortName = MSXML 6 Service Pack 2 (KB973686)
Property(S): WrongPackage = This MSXML6 Service Pack 2 (KB973686) package is not supported on the current processor type.
Property(S): DialogPatchTitle = MSXML 6 Service Pack 2 (KB973686) Patch
Property(S): SystemFolder = C:\WINDOWS\system32\
...
MSI (s) (04:A8) [09:38:47:725]: Product: MSXML 6 Service Pack 2 (KB973686) -- Configuration failed.

MSI (s) (04:A8) [09:38:47:725]: Windows Installer reconfigured the product. Product Name: MSXML 6 Service Pack 2 (KB973686). Product Version: 6.20.2003.0. Product Language: 1033. Reconfiguration success or error status: 1603.
Solution:
Luckily, I am not the first one who saw this problem. This problem seems to be around for a while now. There is a nice Microsoft KB article for this exact problem, and the solution is to use "Windows Installer CleanUp utility" to remove existing MSXML then install SQL 2005.

And, IT WORKS!!

Reference: MSKB 968749 http://support.microsoft.com/kb/968749

Monday, June 07, 2010

MSDN Library is Gone in Visual Studio 2010

I consider this another major setback in Visual Studio 2010.

Visual Studio 2010 come with a help system that is the worst since Visual Studio 2002.

Pros:
  • web-based, can be views in IE, as well as FireFox;
  • Encourage the use of better search engines like Google?
Cons:
  • No auto-complete search box;
  • Search result is worse than Google;
  • Left pane only has three fixed positions, cannot be resized or hidder;
To compensate the lack of auto-complete, I have stopped using my local help system and starting to use Google as my MSDN document explorer which did an excellent job.

Monday, May 10, 2010

Google Lost Touch with Users

Recently, Google made some major changes without giving user an option to use the old style.

I do not like their changes, mainly the bar on the left. It is duplicate of the bar on the top which I'm fine with.

Now, with the bar on the left, waste huge amount of space beneath it, I am forced to constantly scroll my browser horizontally to see the full content.

I'd rather to see ads fill that space. Then I know this is a decision driven by commercial interest.

Now, with those seemingly useless links which is neither good for me nor Google, I am completely puzzled.

How can I turn this sidebar off? Try a "GOOGLE SEARCH".

Thursday, May 06, 2010

Dynamically Hide Cells in Flex DataGrid

Goal: Control visibility of controls in Flex DataGrid

Problem:
Control of cells' visibility in Flex DataGrid turns out to be pretty tricky. If you simply use inline item renderer and bind it's visibility attribute to a data provider, it won't work.

Why:
Fortunately, Flex is open source. So, we can dig a little deeper into why it does not work.
  1. Look at SDK 3.2.0: DataGridBase.as, line 1073 will show that Flex SDK will actually set the renderer to visible after set "data" property of the control.
  2. Also, the SDK may decide to hide the cell when it sees fit in various situations;
So, it is not desirable to control visibility directly. You are fighting with the SDK.

Solution(s):
Solution 1: Use a container as item renderer, and embed your control inside the container.
Pros: Quick and easy to implement. An added benefit is that you can control cell layout;
Cons: As all the Flex text book will stress: using too many containers is very BAD for performance! How bad? A 20X20 DataGrid may take at least 5 seconds to render!

Solution 2: Create custom control based on the control you want to use in the cell. And manage a new "forceHide" attribute, which will cooperate with the original "visible" attribute to decide a control's visibility. Please see the sample code below. Some details are missing, but you get the idea.

...
protected var _forceHide:Boolean = false;
/**
* visible by set method
*/
protected var _setVisible:Boolean = false;
/**
* If set, this control will not be visible. It will overwrite visible property.
* DataGrid tend to manipulate visible directly, we can only use
* this extra field to force hide control even if DataGrid decides
* that it can be shown.
*/
public function set forceHide(value:Boolean):void {
_forceHide = value;
setVisible(_setVisible);
invalidateProperties();
}
override public function setVisible(value:Boolean, noEvent:Boolean=false):void {
//save desired settings
_setVisible = value;
//forceHide can mask out change request
super.setVisible((!_forceHide) && value, noEvent);
}
...

Other Thoughts:
How about "CallLater"? It turns out to be a bad idea. As stated before, Flex SDK may want to hide some controls. If your "CallLater" set a control's visible to true, when Flex SDK think it is invisible, you may see some ghost controls hanging around.

Thursday, April 29, 2010

Coldfusion Query of Queries (QoQ) Support

QoQ is convenient, but also poorly documented. I cannot find any official Adobe documentation with details about its features and limitations. It's features changes from version to version, usually only expanding (which is a good thing). There are also many bugs, and weird restrictions.

I guess Ben Forta's books rarely touched this topic for a reason.

So generally, I can only test what can be done by trial and error, and frequently find out that although it works on my computer, but will fail in another CF host due to difference in CF server version.

A summary of what can and cannot be done in CF QoQ (aka In Memory Query).
1. Data size: recommended 5,000 - 50,000 rows, subject to computer memory size;
2. join: inner join of two tables using WHERE clause
Can:
join two tables
inner join through a WHERE clause
cross join
Cannot:
use these clauses: LEFT JOIN, RIGHT JOIN, OUTER JOIN
join more than two tables
3. union: supported, but can be difficult to use due to strict type matching requirements;
4. dot notation: allow access to query in a structure through dot notation;
5. conditional operators: IS, IS (NOT) NULL, >, >=, <>, !=, <, <=, ==, BETWEEN, IN, LIKE
6. case sensitivity: it is case sensitive
7. other supported T-SQL keywords: GROUP, ORDER, DISTINCT, AVG, COUNT,

Beyond QoQ:
1. features from CFQuery tag: maxRows (equivalent to TOP), blockFactor
2. features from CFOutput, CFLoop: startRow, maxRows (combined equivalent to LIMIT)

Thursday, April 22, 2010

Windows XP "System Restore" and Subversion

Subversion users be aware: Windows XP "System Restore" will rollback your SVN working folder!

Just learned it the hardway. I did a system restore on my Windows XP box, and all of sudden all the projects are broken. It turned out that all my SVN working folders are rolled back too.

Solutions?
  1. Checkout "Head" from SVN repo again. Lucky for me, I do check-in frequently, and this solution works for me just fine;
  2. Start "System Restore", and this time select "Undo my last restoration";

Monday, April 19, 2010

Subversion (SVN) Client for Windows Quick Start

This is a brief guide to SVN client usage on Windows using Tortoise SVN client.

Recommended Software:
  1. Install Tortoise SVN client from this web site: tortoisesvn.tigris.org
  2. Install winmerge from winmerge.org for merging code
Check out:To check out a project from SVN server for the first time: start Windows Explorer, right click in the folder you want to save the checkout code, and select "SVN Checkout".

Check in procedures:
Check-in usually have three steps in the following order:
  1. add new file to server;
  2. check for new updates from server and merge if necessary;
  3. commit the changes back to the server;
Minimum requirement for the checked in code is that they can compile without errors.

More detailed checkin steps:
1. In windows explorer, right click the checkout root folder, and select “SVN Add”;
2. If new files are listed in the following dialog:
a. check the files that you want to send to SVN;
b. uncheck the files that you do not want to send to SVN, and add them to the ignore list;
3. Right click the root folder again, and select “SVN Update”
4. If there are changes or merge during update step, double check that the code can still compile;
5. Right click the root folder, and select “SVN Commit”, and type a proper comment about what are fixed, or the new features in this checkin;

Monday, April 12, 2010

Visaul Studio 2010 First Impression

It is officially released today. Tried a little bit and did not like it at all.

#1 problem: sluggish GUI response! No kidding. I thought Eclipse is slow, now I see something slower. No wonder it's release date was postponed to fix performance problem.

Of course, there is also problem finding my way around the IDE. Cannot seem to find a way to generate create script for my database project.

Friday, March 26, 2010

Lean Software Development

Some study notes while reading about Lean Software Development:
  • Adapted from Lean Manufacturing, Toyota Production System;
  • Originated in the boot "Lean Software Development" by Mary Poppendieck and Tom Poppendieck
  • Principles:
    • Eliminate waste
      • Extra features
      • Economies of scale: focusing on high utilization is almost guaranteed to lower it
      • Cross boundaries

    • Amplify leaning
    • Decide as late as possible
    • Deliver as fast as possible
    • Empower the team
    • Build integrity in
    • See the whole

  • Two pillars
    • Continuous improvement
    • Respect for people

  • The responsibility lies, not with black belt specialist, but with the leadership hierachy that runs the operation and they are teachers and coaches;
  • The essence of (the Toyota system) is that each individual employee is given the opportunity to find problems in his own way of working, to solve them and to make improvements;
  • Challenge everything, dissatisfied with status quo
  • Kanban
  • Kaizen
    • spread knowledge
    • small, relentless
    • retrospectives
    • 5 whys
    • eyes for waste

  • Share rather than enforce practices
Good References:


http://en.wikipedia.org/wiki/Lean_software_development

Lean Primer: http://www.leanprimer.com/downloads/lean_primer.pdf

http://www.poppendieck.com/

Friday, January 29, 2010

Flex Builder Error: "Unable to export SWC oem"

Solution: Right click on project, select Properties > Flex Library Build Path > Assets. Uncheck the root node and check it again, then compile project. The error is gone.

I found the solution here: http://flexdevtips.blogspot.com/2009/06/unable-to-export-swc-oem.html

Friday, January 15, 2010

Performance Optimization for Embedded Systems

Some key points:
  • Load code and data as much as possible into internal memory (L1 cache);
  • Use compiler or linker options to optimize for code size can sometimes give better performance than optimize for performance (GreenHills has a very nice tool to help find the optimum compromise between optimize for speed and size). Major points for manipulation:
    • Optimize for speed
    • Optimize for size
    • Remove unused functions
    • Remove debug information
    • Enable code cache
  • Carefully tune the use of code cache and data cache. Performance difference between fine tuned layout and the default can be 10 time or more;
  • Use integer, fixed point over float over double. If floating point computation is necessary, but double is not needed, then remember that all the constants MUST explicitly declared as floating precision, otherwise there may be a lot of double computation and float to double conversions. For example, instead of x=2.0; should use x=2.0f;
  • Bit shift is faster than add (usually), add is faster than multiply (usually), multiply is faster than divide. So the following tricks usually are helpful:
    • Use left shift and right shift instead of multi and div by 2, 4, 8, 16, 32, ... (integer only);
    • Use add instead of multi 2, 3;
    • If a number is used as divider many times, pre-calculate it's inverse, and use multiply for the calculations;
  • Blackfin (DSP architecture specific): assign data to A/B bank properly to enable parallel data retrieval;
  • Profiler is your friend: use profiler to find the biggest consumer and focus on them;
  • In C++ world: avoid deep hierarchy, because those practices take precious memory space which in turn have grave impact on performance;
  • Be careful when you use C runtime. Call to "printf" can easily add 1k memory footprint;

Thursday, January 14, 2010

"var scope" for CFC Function Variables

Why is it good practice to always "var-scope" every CFC function variable?
  • Make it clear that the variables are only visible within the function;
  • Using "var-scope" actually can help improve performance. I tried the test here, and am personally convinced that "var-scope" has significant positive impact on performance;
  • If you "var-scope" every CFC function local variables, then it will be obvious when you have typo in your code. Because you can use tool like "varScoper" to scan your file, if there are complains, you either forget to "var-scope" a variable, or you've got a typo that "varScoper" just helped you to catch;

Monday, December 14, 2009

Start ASP.NET Development Web Server in Command Line

start "ASP.NET Development Server" /B c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\WebDev.WebServer.EXE /port:[port#] /path:[file path] /vpath:[/virtual parth/]

Starting debug server this way will allow debugging web project without even starting Visual Studio 2005.

Friday, December 04, 2009

VC++ Redistributing

Symptom: I keep bumping into this issue. Once in a while my VC++ application does not even start on the targe computer.

Cause: The root cause is that the target computer does not have the VC++ library to support the applications. I works with server products, so I usually just install VC++ library once and expect all my future updates can be done by xcopy only. However, because I turned on auto-update on my development computer, my Visual Studio 2005 keep changing the library it is linked against. So once in a while xcopy deployment is broken.

Fix:
  • Sometimes it can be fixed by simply running Windows Update
  • Run VC++ Redistributable Package on the target computer. It is located here: %PROGDIR%\Microsoft Visual Studio 8\SDK\v2.0\Bootstrapper\Packages\
  • More options here: Choosing a Deployment Method

Monday, November 16, 2009

GridView: get selected rows

Below is sample C# code to get selected rows in GridView.

protected int[] GetSelectedRows()
{
List rowIDs = new List();
foreach (GridViewRow row in GridView.Rows)
{
CheckBox cb = ((CheckBox)row.FindControl("chkRow"));
if (cb.Checked)
{
string IDString = GridView.DataKeys[row.RowIndex].Value.ToString();
rowIDs.Add(Int32.Parse(IDString));
}
}
return rowIDs.ToArray();
}

"SelectAll" CheckBox in GridView using jQuery

Here is a way to do it:


/**
* Register logic for "select all" check box and the group of check boxes
* for each data row.
*
* @param {Object} chkAllSelector jQuery selector to find the "select all" check box
* @param {Object} chkItemSelector jQuery selector to find the check boxes for all the rows
*/

function registerSelectAll(chkAllSelector, chkItemSelector) {
//"select all" checkbox
var checkAllBox = $(chkAllSelector);
//checkbox for each row
var checkItems = $(chkItemSelector);

//check/uncheck all rows if "select all" is clicked
checkAllBox.bind("click", function(){
checkItems.each(function(){
this.checked = checkAllBox[0].checked;
})
});

//uncheck "select all" if some rows are unchecked
checkItems.bind("click", function(){
if(this.checked === false) {
checkAllBox[0].checked = false;
}
});
}


To use it:

registerSelectAll(".chkAllHeader input", ".chkItem input");

Monday, November 09, 2009

"An unexpected error occurred." accessing Network Connection's properties

Cause: seems like it suddenly happens after a recent Windows Update. I cannot ping or "remote desktop" to the computer. Trying to access network connection give me this error: "An unexpected error occurred."

Solution:
This seems to fix the problem:
command line:
regsvr32 netshell.dll
regsvr32 ole32.dll
reboot

Then I can access the properties page, and I disable/re-enabled firewall. Everything coming back to normal.

P.S.
Keep my fingers crossed. Waiting for more surprised from next automatic Windows Update.

Wednesday, October 14, 2009

3D Visualization on iPhone - Got to see it to believe it

Ziosoft showcased this amazing 3D visualization on iPhone. It is fast and smooth with very high image resolution. With dual touch, seem like it is very easy to control zoom, move cutoff plane, rotate and move object, and select depth of rendering.

http://www.youtube.com/watch?v=sDVAosnh1j4&feature=channel_page

From their description and the look, it is obvious that there is web server doing the rendering behind. iPhone seem to provide the dual touch and navigation. Still the the speed is impressive. Either the iPhone has very high speed internet access, or there is some very efficient decompress and rendering algorithms running on it so that data transfer rate is not too high.

Monday, August 10, 2009

Server Explorer Missing

Symptom: Visual Studio 2005 Server Explorer is missing.
Reason: A while back, Visual Studio failed to load the server explorer at starup time, and showed a dialog to disable it. I guess I accidentally clicked "yes".

Solution: run this command in Visual Studio 2005 command line environment:
devenv /resetskippkgs

Tuesday, June 30, 2009

Refeactor! for C++ -- Review

Tried Refactor! for C++ (free version 9.1.5 published June 29, 2009). Visual Studio 2005

Summary of my experience:
Pros:
  • Free;
  • The idea is very attractive: refactor C++ code with right click and no modal dialogs;
  • Rename class names seem to work fine;
Cons:
  • Does not work most of the times. Usually global search and replace did a better job in renaming things;
  • Affects VS grammar highlight. After installation, code grey out by "ifdef"s are totally messed up. Unistall the softwate, Visual Studio went back to correct grey out;

Recommended? No. I uninstalled the software after a few days.

Still looking for a decent C++ refactoring tool.

Monday, December 29, 2008

Modem Error: NO CARRIER

What to check when you get "NO CARRIER" (numeric code: 3) error from Modem:
  • Verify Modem is connected to phone line properly;
  • Verify the phone number you are dialing works properly by calling this number using your phone, and verify that you hear: first ring tone, then the negotiation tone (yes, you should be able to hear the chirping sound over a regular phone);
If you can hear the negotiation tone, but frequently get "NO CARRIER" error, here is a solution:
Set modem register S7 to a longer timeout value. 50 is the default, you can set it to 120 (ATS7=120). Sometimes, you can set this timeout value through MODEM configuration GUI, you can find something like: "Cancel the call if not connected within __ seconds".

Friday, November 07, 2008

Firefox keep crashing -- a solution

Every couple of days, I will see my Firefox using 99% of CPU and crash.

I am a web developer. My Firefox has all sorts of add-ons: Abduction, Firebug, Html Validator, ScapBook, Screen grab!, Web Developer, YSlow. So, I do not need YSlow to know why my Firefox is slow and tend to crash.

I have an idea: how about start two instances of Firefox, one with all the add-ons and the other one clean. I will use the clean one for normal web browsing, and the fully loaded one with development. And, guess what, there is already someone who has done this and posted a blog about it: Firefox: Run a Regular and Development Profile at the Same Time. I used the solution, and it works perfectly.

Friday, September 26, 2008

Blue Screen Trying to Install Windows XP SP3

During last few months, I have been through a couple of Windows XP SP3 installation. They are mostly eventless. One of the worst was a computer that hung after reboot, but after a forced power recycle that system seem to be fine.

Just when I am about to conclude that Windows XP SP3 update is pretty good, I got the famous Blue Screen of Death.

While trying to install Windows XP SP3 on my computer, I got an "Access is denied" error message. So that was not too scary, I typed the error message along with keyword "Windows XP SP3" in Google and found an MSKB 949377 which provided a solution to this exact problem.

Now, following KB 949377, I downloaded full Windows XP SP3 package and subinacl.exe, and created Reset.CMD. But, I tried it 3 times, everytime I ran Reset.CMD, it gave me Blue Screen of Death with error message about registry access. So, I did another Google search with keywords: "windows xp sp3 access denied subinacl registry blue screen". Now "I'm feeling lucky". The first hit provides a solution that works perfectly for me. Here is link to Jason's blog post that solved my problem: http://www.mrfloppysa.com/wordpress/?p=13

The trick is to remove the HKLM line in RESET.CMD. The new RESET.CMD file would be like this:

cd /d "%ProgramFiles%\Windows Resource Kits\Tools"
REM subinacl /subkeyreg HKEY_LOCAL_MACHINE /grant=administrators=f /grant=system=f
subinacl /subkeyreg HKEY_CURRENT_USER /grant=administrators=f /grant=system=f
subinacl /subkeyreg HKEY_CLASSES_ROOT /grant=administrators=f /grant=system=f
subinacl /subdirectories %SystemDrive% /grant=administrators=f /grant=system=f
subinacl /subdirectories %windir%\*.* /grant=administrators=f /grant=system=f
secedit /configure /cfg %windir%\repair\secsetup.inf /db secsetup.sdb /verbose

Thursday, August 21, 2008

How to Delete Broken Windows Service

As a developer who writes Windows Services, I sometimes get services registered with the source code and executables long gone (because I no longer work on that project). When it finally came the time to cleanup. I found it difficult to remove them from the registry without the original executables.

After a bit of Google, however, I found a useful tool: sc.exe (Service Controller Tool) come with Windows Resource Kit. This command line tool make deleting service very easy, just run:
sc.exe delete [service name]

Notice: the service name for the command line is not the same as "Name" you see in the list (this is usually the "Display Name"). You need to double click the service to open the properties page. And there you will find "Service Name".

Thursday, July 24, 2008

C++/CLI Gotchas

C++/CLI is a hybrid monster. I am very green in the world of C++/CLI. Below are a few very stupid problems I have met.

Example 1: If you are writing unsafe code in C++/CLI with mixed managed code and unmanaged code, it proved to be more dangerous than plain old C++. Here are a few examples of using System::String together with char (C native data type). Without thorough understanding of the new .NET String class will create code that compiles perfectly but return unexpected results to you in run time.

String^ str = "";
char ch = 'a';
str += ch; //result: str="97", instead of "a", because it called ch.ToString()
str = gcnew String(&ch); //result: str="a@#!$%", because &ch is considered to be a string
str = gcnew String(&ch, 0, 1); //result: str="a" as expected.


Example 2: Visual Studio 2005 Debugger is a liar

int i;
i=1000;
... //all the code in between so that you forgot what is defined
for(int i=0; i < 3; i++)
{
...
}
int k = i++; //if you set a break here, Visual Studio Debugger will tell you i=4??!

I agree that the code above is stupid which is an artifact from trying to correct old VC++ code. But Debugger giving a wrong answer wouldn't help!

Monday, July 07, 2008

C++/CLI Warning C4945

Reason: This warning was generated because I referenced multiple C# projects in the C++/CLI project, and they all have "copy local" set to true.

Solution: Change reference to the C# projects, set all "copy local ..." properties to false.

A hotfix is available, which does not seem to be in SP1 as of 7/7/2008. So this fix probably will never be publicly available. This proves again C++/CLI is not on the top of TODO list for Visual Studio team.

Reference:
Microsoft KB 922271: http://support.microsoft.com/kb/922271

Wednesday, May 07, 2008

Convert VC++6 to VC++7 -- (2)

Below is a laundry list of the problems and solutions.

Compiler Error: fatal error C1083: Cannot open include file: 'fstream.h': No such file or directory
Solution: change include from fsream.h to fstream, and add using namespace std;
Related problems: ios::nocreate and ios::noreplace are deprecated. ios::nocreate is replace by ios::in

CFile::ReadHuge() and CFile::WriteHuge() are obsolete. Use CFile::Read() and CFile::Write() instead.

Replace &afxChNil by empty string "".

Compiler Error:
  • error C2059: syntax error : '<'
  • error C2143: syntax error : missing ';' before '<'
  • error C2182: 'ConstructElements' : illegal use of type 'void'
  • error C2988: unrecognizable template declaration/definition
Solution: ConstructElements and DestructElements are deprecated. Remove definition of these functions. Ref: Microsoft KB 318734

WINVER default changed to 0x0501 (Windows XP). If your program still want to support Windows 2000, the the following line must be included in the project:
#define WINVER 0x0400

CPropetySheetEx, CPropertyPageEx are deprecated, they are included back to CPropertySheet and CPropertyPage.


CString s(45) no longer compiles. Because CString is changed to template based function with more constructors. This definition has ambiguous overloaded constructors. Change to CString s((TCHAR)45).



VC++7.1 has stricter type requirements. For example, conversion from HANDLE to int and uint is not allowed.

Compiler Error:
error C2668: 'sqrt' : ambiguous call to overloaded function
Solution:
sqrt, fabs, log and other CRT math functions support both double and float type now. An integer input to these functions will cause the error above.
Example:
int i = 10;
float f = sqrt(i); //error C2688
float f = sqrt((float)i); //compiles ok


Compiler Error:
error C2440: 'static_cast' : cannot convert from 'void (__thiscall XXXXXXXX::* )(void)' to 'void (__thiscall XXXXXX::* )(NMHDR *,LRESULT *)'
Solution:
Function signature of event handler OnKillfocus was changed from void Func(void) to void Func(NMHDR*, LRESULT*).

Thursday, May 01, 2008

Convert VC++6 to VC++7 -- (1)

VC++6 is a pretty solid product, which can still produce decent software in Windows XP. But Microsoft has decided to stop support for VC6 for about 2 years now. With the arrival of VS2008 and Windows Vista, it might finally be the time to convert those old projects that you still want to keep alive into a newer platform.

To start the conversion is really easy, just open the .dsp file in Visual Studio 2003. It will convert the project for you automatically, and generate the .vcproj and .sln files. If you are lucky, the next step is press F7 to build the solution and press F5 to run it, and you are done. Unfortunately, 90% of us will need to change the code to make it even compile. VC++6 is less standard compliant than VC++7 and there are some other breaking changes in VC++7.

This series will report problems I've seen when I convert a VC++6 project to VC++7 and some tips to help smooth the process.

Tip 1: for a project that is still actively maintained, during the conversion care must be taken so that changes do not break the software under VC++6. Use this to allow the code changes exists peacefully in VC++6:

#if _MSC_VER >=1500
//this is VC++9.0 or above
#elif _MSC_VER >= 1400
// this is VC++8.0
#elif _MSC_VER >= 1310
// this is VC++7.1
#elif _MSC_VER > 1300
// this is VC++7.0
#else
//assume VC++6
#endif