Search Results

Search found 243 results on 10 pages for 'yan cheng cheok'.

Page 5/10 | < Previous Page | 1 2 3 4 5 6 7 8 9 10  | Next Page >

  • Is this a correct way to stop Execution Task

    - by Yan Cheng CHEOK
    I came across code to stop execution's task. private final ExecutorService executor = Executors.newSingleThreadExecutor(); public void stop() { executor.shutdownNow(); try { executor.awaitTermination(100, TimeUnit.DAYS); } catch (InterruptedException ex) { log.error(null, ex); } } public Runnable getRunnable() { return new Runnable() { public void run() { while (!Thread.currentThread().isInterrupted()) { // What if inside fun(), someone try to clear the interrupt flag? // Say, through Thread.interrupted(). We will stuck in this loop // forever. fun(); } } }; } I realize that, it is possible for Runnable to be in forever loop, as Unknown fun may Thread.sleep, clear the interrupt flag and ignore the InterruptedException Unknown fun may Thread.interrupted, clear the interrupt flag. I was wondering, is the following way correct way to fix the code? private final ExecutorService executor = Executors.newSingleThreadExecutor(); private volatile boolean flag = true; public void stop() { flag = false; executor.shutdownNow(); try { executor.awaitTermination(100, TimeUnit.DAYS); } catch (InterruptedException ex) { log.error(null, ex); } } public Runnable getRunnable() { return new Runnable() { public void run() { while (flag && !Thread.currentThread().isInterrupted()) { // What if inside fun(), someone try to clear the interrupt flag? // Say, through Thread.interrupted(). We will stuck in this loop // forever. fun(); } } }; }

    Read the article

  • Complete list of Fonts which support

    - by Yan Cheng CHEOK
    Currently, if I change the locale setting of my application by Locale.setDefault(Locale.ENGLISH); Locale.setDefault(Locale.SIMPLIFIED_CHINESE); What I understand from this JFreeChart forum is that, I am not using correct font. Once you get the reference of the LegentTitle, you can set it to any font. Apparently, JFreeChart's default is "Tahoma" and it doesn't support Chinese characters. May I know, how I can programmatic determine, as list of available Fonts in my system, which support Chinese? I can hard code it to Serif (It fully support Chinese, doesn't it?), its look n feel doesn't looks good to me. I would like to have more choices.

    Read the article

  • Is It Safe to Cast Away volatile?

    - by Yan Cheng CHEOK
    Most of the time, I am doing this way. class a { public: ~ a() { i = 100; // OK delete (int *)j; // Compiler happy. But, is it safe? // Error : delete j; } private: volatile int i; volatile int *j; }; int main() { a aa; } However, I saw an article here: https://www.securecoding.cert.org/confluence/display/seccode/EXP32-C.+Do+not+access+a+volatile+object+through+a+non-volatile+reference Casting away volatile allows access to an object through a non-volatile reference. This can result in undefined and perhaps unintended program behavior. So, what will be the workaround for my above code example?

    Read the article

  • Java Font Display Problem

    - by Yan Cheng CHEOK
    I realize that, in my certain customer side, when I use the font provided by Graphics2D itself, and decrease the size by 1, it cannot display properly. private void drawInformationBox(Graphics2D g2, JXLayer<? extends V> layer) { if (MainFrame.getInstance().getJStockOptions().getYellowInformationBoxOption() == JStockOptions.YellowInformationBoxOption.Hide) { return; } final Font oldFont = g2.getFont(); final Font paramFont = new Font(oldFont.getFontName(), oldFont.getStyle(), oldFont.getSize()); final FontMetrics paramFontMetrics = g2.getFontMetrics(paramFont); final Font valueFont = new Font(oldFont.getFontName(), oldFont.getStyle() | Font.BOLD, oldFont.getSize() + 1); final FontMetrics valueFontMetrics = g2.getFontMetrics(valueFont); /* * This date font cannot be displayed properly. Why? */ final Font dateFont = new Font(oldFont.getFontName(), oldFont.getStyle(), oldFont.getSize() - 1); final FontMetrics dateFontMetrics = g2.getFontMetrics(dateFont); Rest of the font is OK. Here is the screen shoot (See the yellow box. There are 3 type of different font within the yellow box) :

    Read the article

  • Is there any need for me to use wstring in the following case

    - by Yan Cheng CHEOK
    Currently, I am developing an app for a China customer. China customer are mostly switch to GB2312 language in their OS encoding. I need to write a text file, which will be encoded using GB2312. I use std::ofstream file I compile my application under MBCS mode, not unicode. I use the following code, to convert CString to std::string, and write it to file using ofstream std::string Utils::ToString(CString& cString) { /* Will not work correctly, if we are compiled under unicode mode. */ return (LPCTSTR)cString; } To my surprise. It just works. I thought I need to at least make use of wstring. I try to do some investigation. Here is the MBCS.txt generated. I try to print a single character named ? (its value is 0xBDC5) When I use CString to carry this character, its length is 2. When I use Utils::ToString to perform conversion to std::string, the returned string length is 2. I write to file using std::ofstream My question is : When I exam MBCS.txt using a hex editor, the value is displayed as BD (LSB) and C5 (MSB). But I am using little endian machine. Isn't hex editor should show me C5 (LSB) and BD (MSB)? I check from wikipedia. GB2312 seems doesn't specific endianness. It seems that using std::string + CString just work fine for my case. May I know in what case, the above methodology will not work? and when I should start to use wstring?

    Read the article

  • Transferring binary file from web server to client

    - by Yan Cheng CHEOK
    Usually, when I want to transfer a web server text file to client, here is what I did import cgi print "Content-Type: text/plain" print "Content-Disposition: attachment; filename=TEST.txt" print filename = "C:\\TEST.TXT" f = open(filename, 'r') for line in f: print line Works very fine for ANSI file. However, say, I have a binary file a.exe (This file is in web server secret path, and user shall not have direct access to that directory path). I wish to use the similar method to transfer. How I can do so? What content-type I should use? Using print seems to have corrupted content received at client side. What is the correct method?

    Read the article

  • Should I use threeten instead of joda-time

    - by Yan Cheng CHEOK
    Hello all, I came across http://www.jroller.com/scolebourne/entry/why_jsr_310_isn_t. 1) I am currently migrating Java Calendar to joda-time. I was wondering, should I use threeten instead of joda-time? Is threeten production ready? 2) Can threeten library and joda-time libraries exist together in a same application? As I am using some 3rd parties libraries, which is using joda-time library too. 3) Will joda-time become an abandon project since there is threeten? Thanks.

    Read the article

  • Get ID of a clicked parent ID

    - by Yan Cheng CHEOK
    I try using evt.parent.attr("id") inside jsddm_close, but it doesn't work. <script type="text/javascript"> var ddmenuitem = 0; function jsddm_open() { // When "help-menu" being click, I will toggle drop down menu. ddmenuitem = $(this).find('ul').eq(0).toggle(); } function jsddm_close(evt) { // When everywhere in the document except "help-menu" being clicked, I will close the drop down menu. // How I can check everywhere in the document except "help-menu"? if (ddmenuitem) ddmenuitem.hide(); } $(document).ready(function() { $('#jsddm > li').bind('click', jsddm_open); $(this).bind('click', jsddm_close); }); </script> <ul id="jsddm"> <li><a href="#">Home</a></li> <li><a href="#" id="help-menu"><u>Help</u><small>xx</small></a> <ul> <li><a href="#">menu item 1</a></li> <li><a href="#">menu item 2</a></li> </ul> </li> </ul>

    Read the article

  • Any side effect of not using USES_CONVERSION

    - by Yan Cheng CHEOK
    Recently, I have a utilities function of // T2CA #include "ATLCONV.H" std::string Utils::CString2String(const CString& cString) { #if _MSC_VER > 1200 // Convert a TCHAR string to a LPCSTR // construct a std::string using the LPCSTR input CT2CA tmp(cString); std::string strStd (tmp); #else // Deprecated in VC2008. // construct a std::string using the LPCSTR input std::string strStd (T2CA (cString)); #endif return strStd; } I do several simple test it seems work fine. However, when I google around, I see most usage of T2CA in VC6, before they call, they will invoke USES_CONVERSION; Is there any thing I had missed out? Shall I invoke my function by : #else // Deprecated in VC2008. // construct a std::string using the LPCSTR input USES_CONVERSION; std::string strStd (T2CA (cString)); #endif

    Read the article

  • Unicode version of base64 encoding/ decoding

    - by Yan Cheng CHEOK
    I am using base64 encoding/decoding from http://www.adp-gmbh.ch/cpp/common/base64.html It works pretty well with the following code. const std::string s = "I Am A Big Fat Cat" ; std::string encoded = base64_encode(reinterpret_cast<const unsigned char*>(s.c_str()), s.length()); std::string decoded = base64_decode(encoded); std::cout << _T("encoded: ") << encoded << std::endl; std::cout << _T("decoded: ") << decoded << std::endl; However, when comes to unicode namespace std { #ifdef _UNICODE typedef wstring tstring; #else typedef string tstring; #endif } const std::tstring s = _T("I Am A Big Fat Cat"); How can I still make use of the above function? Merely changing std::string base64_encode(unsigned TCHAR const* , unsigned int len); std::tstring base64_decode(std::string const& s); will not work correctly. (I expect base64_encode to return ASCII. Hence, std::string should be used instead of std::tstring)

    Read the article

  • How to achieve to following C++ output formatting?

    - by Yan Cheng CHEOK
    I wish to print out double as the following rules : 1) No scietific notation 2) Maximum decimal point is 3 3) No trailing 0. For example : 0.01 formated to "0.01" 2.123411 formatted to "2.123" 2.11 formatted to "2.11" 2.1 formatted to "2.1" 0 formatted to "0" By using .precision(3) and std::fixed, I can only achieve rule 1) and rule 2), but not rule 3) 0.01 formated to "0.010" 2.123411 formatted to "2.123" 2.11 formatted to "2.110" 2.1 formatted to "2.100" 0 formatted to "0" Code example is as bellow : #include <iostream> int main() { std::cout.precision(3); std::cout << std::fixed << 0.01 << std::endl; std::cout << std::fixed << 2.123411 << std::endl; std::cout << std::fixed << 2.11 << std::endl; std::cout << std::fixed << 2.1 << std::endl; std::cout << std::fixed << 0 << std::endl; getchar(); } any idea?

    Read the article

  • How to implement Comet server side with Python?

    - by Morgan Cheng
    I once tried to implement Comet in PHP. Soon, I found that PHP is not suitable for Comet, since each HTTP request will occupy one process/thread. As a result, it doesn't scale well. I just installed mod_python in my XAMPP. I thought it would be easy to implement Comet with Python asynchronous programming. But still cannot get a clue how to implement it. Is there any idea how to implement Comet in mod_python?

    Read the article

  • GDB doesnt like my typedef

    - by yan bellavance
    It seems that the following is to deep for the debugger in Qt even though the program uses it without problem typedef QMap <int, QStringList> day2FileNameType; typedef QMap <int, day2FileNameType> month2day2FileNameType; typedef QMap <int, month2day2FileNameType> year2month2day2FileNameType; year2month2day2FileNameType y2m2d2f; now the first 2 typeDefs work okay with the debugger but the third one retrieving data for watch view (over 100 pending request) Is it wrong for me to try and use such a typedef as year2month2day2FileNameType?

    Read the article

  • can I access a struct inside of a struct without using the dot operator?

    - by yan bellavance
    I have 2 structures that have 90% of their fields the same. I want to group those fields in a structure but I do not want to use the dot operator to access them. The reason is I already coded with the first structure and have just created the second one. before: struct{ int a; int b; int c; object1 name; } str1; struct{ int a; int b; int c; object2 name; } str2; now I would create a third struct: struct{ int a; int b; int c; } str3; and would change the str1 and atr2 to this: struct{ str3 str; object1 name; } str1; struct { str3 str; object2 name; } str2; Finally I would like to be able to access a,b and c by doing: str1 myStruct; myStruct.a; myStruct.b; myStruct.c; and not: myStruct.str.a; myStruct.str.b; myStruct.str.c; Is there a way to do such a thing. The reason for doing this is I want keep the integrety of the data if chnges to the struct were to occur and to not repeat myself and not have to change my existing code and not have fields nested too deeply. RESOLVED: thx for all your answers. The final way of doing it so that I could use auto-completion also was the following: struct str11 { int a; int b; int c; }; typedef struct str22 : public str11 { QString name; }hi;

    Read the article

  • shared library path inconsistent from one host to another

    - by yan bellavance
    I built my qt app so that all the Qt modules it uses are contained in the same directory as the executable. It works on the machine I used to build the app and I made sure to test this by removing those shared libraries everywhere except in the current directory of the app. Doing a ldd shows that its looking for those libraries in the current directory and putting the executable by itself fails to open the exectuable. So this is all good but when I transfer this directory to a host machine it still cant find those libraries. what could be the problem?

    Read the article

  • How to write Asynchronous LINQ query?

    - by Morgan Cheng
    After I read a bunch of LINQ related stuff, I suddenly realized that no articles introduce how to write asynchronous LINQ query. Suppose we use LINQ to SQL, below statement is clear. However, if the SQL database responds slowly, then the thread using this block of code would be hindered. var result = from item in Products where item.Price > 3 select item.Name; foreach (var name in result) { Console.WriteLine(name); } Seems that current LINQ query spec doesn't provide support to this. Is there any way to do asynchronous programming LINQ? It works like there is a callback notification when results are ready to use without any blocking delay on I/O.

    Read the article

  • How to protect critical section in PHP?

    - by Morgan Cheng
    I did some search about this topic but found nothing valuable. If I don't use PHP default session handler, there is no session lock at request level. So, I have to protect critical section by myself. In Java, we have synchronized. In C#, we have lock. In PHP, how to do that?

    Read the article

  • How does Windows LIve ID work?

    - by Morgan Cheng
    I happens to find this nice article explaining how OpenID works. Clearly, OpenID consumer and OpenID server transfer information through URL query string. I'm wondering how Live ID accomplish similar functionality. It seems the info is not exchanged through query string in URL. And, since Live ID login server have different domain name from consumer domain, it is not applicable to transfer info through cookie. I tried to google tutorial of Live ID, but the result is full of jargon and hard to understand. Is there any easy-to-understand tutorial about How Live ID works?

    Read the article

  • How does GMail implement Comet?

    - by Morgan Cheng
    With the help of HttpWatch, I tried to figure out how GMail implement Comet. I Login in GMail with two account, one in IE and the other in Firefox. Chatting in GTalk in GMail with some magic words like "WASSUP". Then, I logoff both GMail accounts, filter any http content without "WASSUP" string. The result shows which HTTP request is the streaming channel. (Note: I have to logoff. Otherwise, never-ending HTTP would not show content in HttpWatch.) The result is interesting. The URL for stream channel is like: https://mail/channel/bind?VER=8&at=xn3j33vcvk39lkfq..... There is no surprise that GMail do Comet in IE with IFRAME. The Http content starts with " Originally, I guessed that GMail do Comet in Firefox with multipart XmlHttpRequest. To my surprise, the response header doesn't have "multipart/x-mixed-replace" header. The response headers are as below: HTTP/1.1 200 OK Content-Type: text/plain; charset=utf-8 Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: Fri, 01 Jan 1990 00:00:00 GMT Date: Sat, 20 Mar 2010 01:52:39 GMT X-Frame-Options: ALLOWALL Transfer-Encoding: chunked X-Content-Type-Options: nosniff Server: GSE X-XSS-Protection: 0 Unfortunately, the HttpWatch doesn't tell whether a HTTP request is from XmlHttpRequest or not. The content is not HTML but JSON. It looks like a response for XHR, but that would not work for Comet without multipart/x-mixed-replace, right? Is there any way else to figure out how GMail implement Comet? Thanks.

    Read the article

  • 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

  • Progress-bar (Video Preloader)

    - by Yan
    I have a spark component VideoDisplay which displays a video. I want to add a ProgressBar to it which will show load progress of the video and when the video is loaded ProgressBar to disappear. How to do that? Thanks,

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10  | Next Page >