Search Results

Search found 2845 results on 114 pages for 'michael cheng'.

Page 10/114 | < Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >

  • Why JavaScript Statement "ga = ga || []" Works?

    - by Morgan Cheng
    Below javascript statements will cause error, if ga is not declared. if (ga) { alert(ga); } The error is: ga is not defined It looks undeclared variable cannot be recognized in bool expression. So, why below statement works? var ga = ga || []; To me, the ga is treated as bool value before "||". If it is false, expression after "||" is assigned to final ga.

    Read the article

  • BorderLayout problem with JSplitPane after adding JToolbar (Java)

    - by Alex Cheng
    Hello all. Problem: My program layout is fine, as below before I add JToolbar to BorderLayout.PAGE_START Here's a screenshot before JToolbar is added: Here's how it looked like after adding JToolbar: May I know what did I do wrong? Here's the code I used: //Create the text pane and configure it. textPane = new JTextPane(); -snipped code- JScrollPane scrollPane = new JScrollPane(textPane); scrollPane.setPreferredSize(new Dimension(300, 300)); //Create the text area for the status log and configure it. changeLog = new JTextArea(5, 30); changeLog.setEditable(false); JScrollPane scrollPaneForLog = new JScrollPane(changeLog); //Create a split pane for the change log and the text area. JSplitPane splitPane = new JSplitPane( JSplitPane.VERTICAL_SPLIT, scrollPane, scrollPaneForLog); splitPane.setOneTouchExpandable(true); //Create the status area. JPanel statusPane = new JPanel(new GridLayout(1, 1)); CaretListenerLabel caretListenerLabel = new CaretListenerLabel("Caret Status"); statusPane.add(caretListenerLabel); //Create the toolbar JToolBar toolBar = new JToolBar(); -snipped code- //Add the components. getContentPane().add(toolBar, BorderLayout.PAGE_START); getContentPane().add(splitPane, BorderLayout.CENTER); getContentPane().add(statusPane, BorderLayout.PAGE_END); //Set up the menu bar. actions = createActionTable(textPane); JMenu editMenu = createEditMenu(); JMenu styleMenu = createStyleMenu(); JMenuBar mb = new JMenuBar(); mb.add(editMenu); mb.add(styleMenu); setJMenuBar(mb); Please help, I'm new to GUI Building, and I don't feel like using Netbeans to drag and drop the UI for me... Thank you in advance.

    Read the article

  • Replace LinkedList element value through LinkedList.Enumerator

    - by Yan Cheng CHEOK
    I realize there are no way for me to replace value through LinkedList.Enumerator. For instead, I try to port the below Java code to C# // Java ListIterator<Double> itr1 = linkedList1.listIterator(); ListIterator<Double> itr2 = linkedList2.listIterator(); while(itr1.hasNext() && itr2.hasNext()){ Double d = itr1.next() + itr2.next(); itr1.set(d); } // C# LinkedList<Double>.Enumerator itr1 = linkedList1.GetEnumerator(); LinkedList<Double>.Enumerator itr2 = linkedList2.GetEnumerator(); while(itr1.MoveNext() && itr2.MoveNext()){ Double d = itr1.Current + itr2.Current; // Opps. Compilation error! itr1.Current = d; } Any other technique I can use?

    Read the article

  • How to implement Session timeout in Web Server Side?

    - by Morgan Cheng
    I beheld a web framework implementing in-memory session in this way. The session object is added to Cache with timeout. When the time is out, the session is removed from Cache automatically. To protect race condition, each request should acquire lock on given session object to proceed. Each request will "touch" the session in Cache to refresh the timeout. Everything looks fine, until this scenario is discovered. Say, one operation takes a long time, longer than timeout. Another request comes and wait on session lock which is currently hold by the long-time request. Finally, the long-time request is over, it releases the lock. But, since it already takes longer time than timeout, the session object is already removed from Cache. This is obvious because the only request holding the lock doesn't have a chance to "touch" the session object in cache. The second request gets the lock but cannot retrieve the expired Session object. Oops... To fix this issue, the second request has to re-create the Session object. But, this is just like digging a buried dead body from tomb and try to bring it back to life. It causes buggy code. I'm wondering what's the best way to implement timeout in session to handle such scenario. I know that current platform must have good session mechanism. I just want to know the under-the-hood how.

    Read the article

  • How does session_start lock in PHP?

    - by Morgan Cheng
    Originally, I just want to verify that session_start locks on session. So, I create a PHP file as below. Basically, if the pageview is even, the page sleeps for 10 seconds; if the pageview is odd, it doesn't. And, session_start is used to obtain the page view in $_SESSION. I tried to access the page in two tabs of one browser. It is not surprising that the first tab takes 10 seconds since I explicitly let it sleep. The second tab would not sleep, but it should be blocked by sessiont_start. That works as expected. To my surprise, the output of the second page shows that session_start takes almost no time. Actually, the whole page seems takes no time to load. But, the page does take 10 seconds to show in browser. obtained lock Cost time: 0.00016689300537109 Start 1269739162.1997 End 1269739162.1998 allover time elpased : 0.00032305717468262 The page views: 101 Does PHP extract session_start out of PHP page and execute it before other PHP statements? This is the code. <?php function float_time() { list($usec, $sec) = explode(' ', microtime()); return (float)$sec + (float)$usec; } $allover_start_time = float_time(); $start_time = float_time(); session_start(); echo "obtained lock<br/>"; $end_time = float_time(); $elapsed_time = $end_time - $start_time; echo "Cost time: $elapsed_time <br>"; echo "Start $start_time<br/>"; echo "End $end_time<br/>"; ob_flush(); flush(); if (isset($_SESSION['views'])) { $_SESSION['views'] += 1; } else { $_SESSION['views'] = 0; } if ($_SESSION['views'] % 2 == 0) { echo "sleep 10 seconds<br/>"; sleep(10); } $allover_end_time = float_time(); echo "allover time elpased : " . ($allover_end_time - $allover_start_time) . "<br/>"; echo "The page views: " . $_SESSION['views']; ?>

    Read the article

  • How to build Graceful Degradation AJAX web page?

    - by Morgan Cheng
    I want to build web page with "Graceful Degradation". That is, the web page functions even javascript is disabled. Now I have to make design decision on the format of AJAX response. If javascript is disabled, each HTTP request to server will generate HTML as response. The browser refreshes with the returned HTML. That's fine. If javascript is enabled, each AJAX HTTP request to server will generate ... well, JSON or HTML. If it is HTML, it is easy to implement. Just have javascript to replace part of page with the returned HTML. And, in server side, not much code change is needed. If it is JSON, then I have to implement JSON-to-html logic in javascript again which is almost duplicate of server side logic. Duplication is evil. I really don't like it. The benefit is that the bandwidth usage is better than HTML, which brings better performance. So, what's the best solution to Graceful Degradation? AJAX request better to return JSON or HTML?

    Read the article

  • Use auto_ptr in VC6 dll cause crash

    - by Yan Cheng CHEOK
    // dll #include <memory> __declspec(dllexport) std::auto_ptr<int> get(); __declspec(dllexport) std::auto_ptr<int> get() { return std::auto_ptr<int>(new int()); } // exe #include <iostream> #include <memory> __declspec(dllimport) std::auto_ptr<int> get(); int main() { { std::auto_ptr<int> x = get(); } std::cout << "done\n"; getchar(); } The following code run perfectly OK under VC9. However, under VC6, I will experience an immediate crash with the following message. Debug Assertion Failed! Program: C:\Projects\use_dynamic_link\Debug\use_dynamic_link.exe File: dbgheap.c Line: 1044 Expression: _CrtIsValidHeapPointer(pUserData) Is it exporting auto_ptr under VC6 is not allowed? It is a known problem that exporting STL collection classes through DLL. http://stackoverflow.com/questions/2451714/access-violation-when-accessing-an-stl-object-through-a-pointer-or-reference-in-a However, I Google around and do not see anything mention for std::auto_ptr. Any workaround?

    Read the article

  • Crashing when pushing a XIB based view controller onto navigation controller stack

    - by Michael
    I was attempting to clean up the implementation for a sub-panel on a navigation controller stack, so that the navigation bar could be customized in the XIB instead of doing it manually in the viewDidLoad method. The original (working) setup had the XIB set up with the "File's Owner" class set to the view controller class, and then the view at the top level. This works fine. In the "Interface Builder User Guide", p. 71, it describes the recommended way to build the XIBs for sub-panels ("additional navigation levels"). This approach leaves the "File's Owner" class as NSObject, but adds a UIViewController at the top level, and nests the view (and navigation item) underneath it. The UIViewController's view automatically gets connected to the contained view. When I try to push the controller init'd with this new XIB, the app crashes because of a missing view: SettingsViewController *controller = [[SettingsViewController alloc] initWithNibName:@"SettingsView" bundle:nil]; [self.navigationController pushViewController:controller animated:YES]; 2010-04-23 11:17:37.135 xxxx[1173:207] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "SettingsTestView" nib but the view outlet was not set.' I've double checked everything, and tried building a clean XIB from scratch, but get the same result. I looked through a number of the code sample projects, and NONE of them use the documented/recommended approach--they all use the File's Owner class and manually set up the navigation bar in viewDidLoad like I originally had it. Is it possible to get it working the "recommended" way? Thanks! Michael

    Read the article

  • Multiple Tables or Multiple Schema

    - by Yan Cheng CHEOK
    http://stackoverflow.com/questions/1152405/postgresql-is-better-using-multiple-databases-with-1-schema-each-or-1-database I am new in schema concept for PostgreSQL. For the above mentioned scenario, I was wondering Why don't we use a single database (with default schema named public) Why don't we have a single table, to store multiple users row? Other tables which hold users related information, with foreign key point to the user table. Can anyone provide me a real case scenario, which single database, multiple schema will be extremely useful, and can't solve by conventional single database, single schema.

    Read the article

  • Algorithm to detect how many words typed, also multi sentence support (Java)

    - by Alex Cheng
    Hello all. Problem: I have to design an algorithm, which does the following for me: Say that I have a line (e.g.) alert tcp 192.168.1.1 (caret is currently here) The algorithm should process this line, and return a value of 4. I coded something for it, I know it's sloppy, but it works, partly. private int counter = 0; public void determineRuleActionRegion(String str, int index) { if (str.length() == 0 || str.indexOf(" ") == -1) { triggerSuggestionList(1); return; } //remove duplicate space, spaces in front and back before searching int num = str.trim().replaceAll(" +", " ").indexOf(" ", index); //Check for occurances of spaces, recursively if (num == -1) { //if there is no space //no need to check if it's 0 times it will assign to 1 triggerSuggestionList(counter + 1); counter = 0; return; //set to rule action } else { //there is a space counter++; determineRuleActionRegion(str, num + 1); } } //end of determineactionRegion() So basically I find for the space and determine the region (number of words typed). However, I want it to change upon the user pressing space bar <space character>. How may I go around with the current code? Or better yet, how would one suggest me to do it the correct way? I'm figuring out on BreakIterator for this case... To add to that, I believe my algorithm won't work for multi sentences. How should I address this problem as well. -- The source of String str is acquired from textPane.getText(0, pos + 1);, the JTextPane. Thanks in advance. Do let me know if my question is still not specific enough.

    Read the article

  • How to troubleshoot PHP session file empty issue?

    - by Morgan Cheng
    I have a very simple test page for PHP session. <?php session_start(); if (isset($_SESSIONS['views'])) { $_SESSIONS['views'] = $_SESSIONS['pv'] + 1; } else { $_SESSIONS['views'] = 0; } var_dump($_SESSIONS); ?> After refreshing the page, it always show array 'views' => int 0 The environment is XAMPP 1.7.3. I checked phpInfo(). The session is enabled. Session Support enabled Registered save handlers files user sqlite Registered serializer handlers php php_binary wddx Directive Local Value Master Value session.auto_start Off Off session.bug_compat_42 On On When the page is accessed, there is session file sess_lnrk7ttpai8187v9q6iok74p20 created in my "D:\xampp\tmp" folder. But the content is empty. With Firebug, I can see cookies about the session. Cookie PHPSESSID=lnrk7ttpai8187v9q6iok74p20 It seems session data is not flushed to files. Is there any way or direction to trouble shoot this issue? Thanks.

    Read the article

  • Help to Install Eclipse for A Netbeans Users

    - by Yan Cheng CHEOK
    I had been using Netbeans all the while to develop Swing application. So far, I am a Happy Netbeans User Currently, I had a project (GWT, J2EE and Swing), which I need to use Eclipse (Please do not ask Why) Here is the step I had been taken. Download Eclipse IDE for Java EE Developers (190 MB) from http://www.eclipse.org/downloads/ I thought this should be the correct choice, as I see most features are found in that edition http://www.eclipse.org/downloads/packages/compare-packages After struggling a while to get use to the user interface of Eclipse, I still cannot find a Visual GUI Editor! After doing some Googling, I realize I need to install something called Plugins However, tones of plugins which had similar features has confused me, as I found http://www.cloudgarden.com/jigloo/index.html http://www.eclipse.org/vep/WebContent/main.php http://code.google.com/p/visualswing4eclipse/ This makes me even more confuse? Which plugin I should use to develop a Swing based application? Most of them seems not up-to-dated. Or, is there any complete bundle I can download, where 1 click, will install all the necessary Swing development tools for me? I just miss my Netbeans :( I really appreciate their team, who make the installation work so easy. One click button install, all the necessary tools just come to me

    Read the article

  • Google liked drop down menu

    - by Yan Cheng CHEOK
    Hello, whenever we go to Google Page and click on the "more", a menu will be dropped down. I would like to have the following effect on my web site too. May I know which JavaScript library can help me to achieve the similar effect?

    Read the article

  • IE7 div floating bug

    - by Michael Frey
    I have the following <div id="border" style="width:100%; border:8px solid #FFF"> <div id="menu" style="width:250px; float:left;" > Some menu </div> <div id="content" style="padding-left:270px; width:520px;" > Main page content </div> </div> This gives me a left aligned menu and the content to the right of it, all surrounded by a border. On all browsers including IE8 it displays correctly. But on IE7 the content only starts below the menu, and leaves a big open space to the right of the menu. I have searched all kind of solutions and tried all kinds of combinations of right, left, none for float. clearing left right both. It always displays different on the browsers. Any help is appreciated. Michael

    Read the article

  • Question about using adaptive layout + print style sheet

    - by Michael
    Hey everyone, In my web design class, we looked at creating different style sheets for different window sizes and using a javascript that detects the window size and loads the right style sheet. In the head, I'm linking to three external style sheets, as well as a link to the javascript file. So the adaptive layout works fine. However... I also need to be able to use a print style sheet with this particular webpage (it's the requirement for this project). The problem is this that the way the javascript was written makes it so that it ignores the print style sheet. When I go to print preview, it ignores the print style sheet and the preview shows me all of my webpage unstyled. It looks like just the html when opened in a browser. I am using the javascript by Kevin Hale at ParticleTree, and I'm sure there are those familiar with this :] http://particletree.com/examples/dynamiclayouts/ I would like to know what needs to be changed so that the print style sheet isn't ignored. I've shown this to my professor. However, her email wasn't clear enough, but I understand that somehow the script is ignoring the print.css and that's why the print preview shows a css-less preview. Since it's the weekend, I won't be able to get an answer until Monday, and I was hoping someone can help me out. Thank you very much! Michael

    Read the article

  • Is it necessary to "escape" character "<" and ">" for javascript string?

    - by Morgan Cheng
    Sometimes, server side will generate strings to be embedded in inline JavaScript code. For example, if "UserName" should be generated by ASP.NET. Then it looks like. <script> var username = "<%UserName%>"; </script> This is not safe, because a user can have his/her name to be </script><script>alert('bug')</script></script> It is XSS vulnerability. So, basically, the code should be: <script> var username = "<% JavascriptEncode(UserName)%>"; </script> What JavascriptEncode does is to add charater "\" before "/" and "'" and """. So, the output html is like. var username = "<\/scriptalert(\'bug\')<\/script<\/script"; Browser will not interpret "<\/script" as end of script block. So, XSS in avoided. However, there are still "<" and "" there. It is suggested to escape these two characters as well. First of all, I don't believe it is a good idea to change "<" to "&lt;" and "" to "&gt;" here. And, I'm not sure changing "<" to "\<" and "" to "\" is recognizable to all browsers. It seems it is not necessary to do further encoding for "<" and "". Is there any suggestion on this? Thanks.

    Read the article

  • Best Pratice to Implement Secure Remember Me

    - by Yan Cheng CHEOK
    Sometimes, I came across certain web development framework which doesn't provide authentication feature as in Authenication ASP.NET I was wondering what is the security measure needs to be considered, when implementing "Remember Me" login feature, by hand coding? Here are the things I usually did. 1) Store the user name in cookie. The user name are not encrypted. 2) Store a secret key in cookie. The secret key is generated using one way function based on user name. The server will verify secret key against user name, to ensure this user name is not being changed. 3) Use HttpOnly in cookie. http://www.codinghorror.com/blog/2008/08/protecting-your-cookies-httponly.html Any things else I could miss out, which could possible lead a security hole.

    Read the article

  • Need to close a popup after javascript completes image upload then load new page

    - by Michael Robinson
    I got a problem. I have a image upload script that runs on a popup up when you select "upload button", after it is complete instead of closing it stays in the uploader.html window. I need it to close and go to a new page. Here is some of the xml that the script uses, can I change the "urlOnUploadSucess" line to close the popup and load a new page on the original page I came from? .....<upload preload="Preloading images:" upload="Uploading images to server:" prepare="Processing and image compression:" of="of" cancel="Cancel" start="Start" warning_empty_required_field="Warning! One of the required fields is empty!" confirm="Will be uploaded:"/> <urls urlToUpload="upload.php?" urlOnUploadSuccess="http://www.baublet.com/purchase.html" urlOnUploadFail="http://www.baublet.com/tryagain.html" urlUpdateFlashPlayer="http://www.baublet.com/flashalternative.html" useMessageBoxesAfterUpload="false" messageOnUploadSuccess="Images were successfully uploaded!" messageOnUploadFail="Error! Images failed to upload!" jsFunctionNameOnUpload=""/> ..... Thanks, Michael

    Read the article

  • char array to LPCTSTR

    - by Yan Cheng CHEOK
    May I know how I can perform the following conversion? // el.strCap is char[50] // InsertItem is expecting TCHAR pointer (LPCTSTR) // How I can perform conversion? // I do not have access in both "list" and "el" source code // Hence, there is no way for me to modify their signature. list.InsertItem(i, el.strCap); And No. I do not want to use WideCharToMultiByte They are too cumbersome to be used.

    Read the article

  • Case Insensitive Ternary Search Tree

    - by Yan Cheng CHEOK
    I had been using Ternary Search Tree for a while, as the data structure to implement a auto complete drop down combo box. Which means, when user type "fo", the drop down combo box will display foo food football The problem is, my current used of Ternary Search Tree is case sensitive. My implementation is as follow. It had been used by real world for around 1++ yeas. Hence, I consider it as quite reliable. My Ternary Search Tree code However, I am looking for a case insensitive Ternary Search Tree, which means, when I type "fo", the drop down combo box will show me foO Food fooTBall Here are some key interface for TST, where I hope the new case insentive TST may have similar interface too. /** * Stores value in the TernarySearchTree. The value may be retrieved using key. * @param key A string that indexes the object to be stored. * @param value The object to be stored in the tree. */ public void put(String key, E value) { getOrCreateNode(key).data = value; } /** * Retrieve the object indexed by key. * @param key A String index. * @return Object The object retrieved from the TernarySearchTree. */ public E get(String key) { TSTNode<E> node = getNode(key); if(node==null) return null; return node.data; } An example of usage is as follow. TSTSearchEngine is using TernarySearchTree as the core backbone. Example usage of Ternary Search Tree // There is stock named microsoft and MICROChip inside stocks ArrayList. TSTSearchEngine<Stock> engine = TSTSearchEngine<Stock>(stocks); // I wish it would return microsoft and MICROCHIP. Currently, it just return microsoft. List<Stock> results = engine.searchAll("micro");

    Read the article

  • Handling Google clientLogin Captcha Example

    - by Yan Cheng CHEOK
    I have a desktop application. I try to perform authentication using http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html However, whenever I get a Captcha challenge, I use a HTTP GET request (I test using web browser) to get the image to present to user. https://www.google.com/accounts/Captcha?ctoken=Y-DrsDJRiWNOP3gR7fq0PAq4Yxvi3UXewu7P7jgAKjk0eZKQ358nbh27-JZ3-nlzXvfKOD3JvZNXwmlRunyz8jPKzqmkOLw2LYb3ZWjg-tE%3A0gMUFttsSH7QwganSJd1aw However, I always get the images : Sorry, we are unable to handle your request at this time. Please try again later. Any idea what I had did wrong? Thanks!

    Read the article

< Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >