~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I'm not sure what you mean by VB comments, can you give an example?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

this is the second thread abt the same problem, will you please tell what was causing it.... Just out of curiosity....

Possibly old Javascript files/site resources given that the problem goes away after clearing the brower cache.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

It's possible to include exceptions by using negative lookbehind assertion feature of regular expressions. Just throw in another alternation which uses lookaround and you should be golden. But this approach would leave behind a nasty regular expression in your code so if possible, try to deal with exceptions after performing the basic splitting rather than modifying the regex.

Also, please create a new thread for your question, and refer this thread if you feel it is related rather than bumping an existing solved thread.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Can someone please state, definitively, what is the preferred method for posting code?

Fenced blocks were removed because as quoted by Dani, "they were incredibly buggy". The preferred way to post code is to indent the code by 4 spaces (or 1 tab) or if you are a clickety-click person, use the 'Code' button. :)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Firstly, I made the font size for the live preview larger at I forget who's recommendation (sorry!)

Hey, that was me! :)

Ardav: Try force refreshing the page; I faced the same issues when trying out things in chrome but the refresh fixed it.

BTW Dani, there is another issue: I can't seem to copy-paste text in the text area on Chrome. Pressing CTRL + V just positions the cursor at the start of the text area.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Preview window as in the entire arrangement: the text area + the view showed below. Apart from SO, I also frequent a site which uses OQSA and the markdown editor there just works. My suggestion was that if you can take a peek at that code, you might be able to understand how they end up with a responsive Javascript driven editor.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

It makes no sense to me to make the preview text any bigger. There should be no reason that it needs to be read. Not only did you just write it so you already know what it says, but the editor itself is now much larger. The only reason it is there is so that you can see formatting.

I guess I'm the weird one out here who looks at the preview text when composing posts instead of the the text area. :)

I am actually considering getting rid of the preview entirely

That would be a bad move IMO, especially given there is no "preview" button. It would force me to write Daniweb posts in the SO markdown editor area and then post them to Daniweb. :/

Any reason it is so difficult to get something like SO preview window for Daniweb? The editor itself seems to be open source given that OSQA (a SO open source clone) uses the same editor. Assuming the current preview window is something you designed from scratch, there is no reason why you folks (James and you) can't take inspiration from that code. :)

Also Sanjay, since both your requests are in line with SO

Ooooh, I swear I didn't have SO in mind. ;) But seriously, confirming before exiting page is a real lifesaver feature. Not compulsory but really good to have to reduce frustrations.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

In that case, it was a wise choice to remove them from the 'formatting help' section. Also, please look into making the preview text same size as the posted text and having demarcation between the post text and the preview text. Right now the preview text seems to float between the text area and the submit button.

EDIT: I would also like to raise a feature request in case it already isn't in the queue: ask user for confirmation before moving out of the current page in case he has something written in the post body. That would prevent accidental close of the tab or a refresh from losing the contents of the post body.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

So should I continue Thinking in C++ or should I use one of the online resources? If the latter, which one? I will be sure to buy the book, but before that, some online education, right?

He should drop back to online tuts if "TICPP" is turning out to be difficult for him. The trick here is to flow through tutorials and settle on the ones which your kid finds worthy of a complete run.

But people say you shouldn't use an IDE when you are new to a language. I am sure you are an experienced C/C++/Java programmer. What do you recommend?

I recommend IDE if using command line tools is going to get the learner frustrated. Mind you, the aim here is to first make your kid learn C++ and not the chops required for being a super-cool C++ hacker. Once the basics are out of the way, learning the toolchain becomes an important point. All that being said, it's wrong assumption on your part that Visual Studio is IDE only. It comes with a command line utility for compiling C++ code. The steps are:

  • Open up command line and navigate to the Visual Studio directory in Program Files
  • Now move to "VC\bin" folder
  • Run: vcvars32.bat
  • Run: cl.exe your_file.cpp (assuming the CPP file is in same directory)
  • The above will create a your_file.exe file in the same directory.
  • Run "your_file.exe" and watch your C++ code execute!

The course starts tomorrow. Isn't it …

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Do you think this website is appropriate?

It seems like a decent free online choice. This thread from SO has a lot of resources for online C++ though over the years I have grown a bit wary of all the beginner resources available on the internet. But definitely worth a try if it helps.

I am using Borland C++ from the command line and not Code::Blocks which was mentioned on the website.

I think it'll be worthwhile to download the free version of Visual Studio since it has a pretty good C++ support (I personally use it to teach C++ programming to kids).

Sorry, I meant "Thinking in C++" instead of Thinking in Java. I meant, should he read Thinking in C++ quarter way or halfway first and then buy the book?

I think the kid should proceed at his own pace and ask you for buying the book if he thinks he wants to continue C++.

And also, Thinking in C++ is proving a little complicated for him.

The sad fact is that C++ is indeed difficult for beginners as compared to say Python or Scheme. I think C++ Primer is the lowest denominator C++ beginner text you'll find on the bookshelf.

BTW, has your kid looked at the CS-101 courses offered by Udacity and Coursera. The interactive learning material should definitely keep him involved.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

All admins, moderators, team colleages are employees or some of them just contribute their time to site

All moderators are voluntary contributors (not employees) to this forum who help out Daniweb with answering questions and forum maintenance in their free time. Except for me, all other co-admins are Daniweb employees (namely Davey & James).

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Looks a lot more prominent now. Any way you can make the preview of the same size?

BTW, not sure if you know this but fenced code blocks don't produce preview and work differently than native code tags. For e.g. fenced code blocks with Python/Py language looks different than the the code produced using indentation in the Python forum.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Should he read the article like, quarter way or halfway first and then buy the book?

Which article? I linked you to the download page for Thinking in C++ in my previous post.

Or should he complete that Thinking in Java first?

One thing at a time; frequently jumping between stuff is bad and leads to confusion, especially when you are trying to learn/teach something new. If he has decided to start C++, concentrate on C++.

Also, that C++ primer book you showed me on flipkart.com was the 4th edition of the book. In my local library I saw the 3rd edition. Should I take the book?

4th Edition is the latest one so is definitely recommended over the old 3rd edition. Like already mentioned, start off with the Thinking in C++ books. If your kid expresses desire to learn more or in depth, grab the paperback copy on Flipkart.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

There aren't many authoritive free resources on the internet for C++ that I know of. One is the free ebook (vol 1 and vol 2) offered by Bruce Eckel, found at: http://nyll.com/ebooks/index.html

If your kid starts enjoying the material in the above mentioned books, spending Rs. 440 on C++ Primer wouldn't be a bad option.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

If he thinks it's awesome to know many languages, C++ with its unique feature set and "close to C" performance should definitely be on the "to dabble in" list. Plus, C++ has tons of game engines written in which makes it a good practical language to write games in.

I'd say go for it! I'd recommend C++ primer and Accelerated C++ as starting points.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Should he learn C++?

This question is incomplete without the follow up answer for "for what purpose?". If for fun, C++ isn't fun to write, at least when compared to the newer breed of managed/scripting languages which make it a lot simpler to do stuff. If for curiosity and usefulness, sure. C++ is pretty much the new standard for native/low level languages. And of course, the third possibilty might be "just because he wants to", in which case it's not like anything can stop him. ;)

The challenge for you here would be to ensure he doesn't get frustrated. Moving from Java to C++ or vice versa can be frustrating because these languages look so similar but are quite different when it comes to expressing solutions.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Plz explain this line. What is IE6?

That means 1 * 10^6 i.e. 1 followed by 6 zeroes. I use this number to convert from nanoseconds (10^-9) to milliseconds (10^-3).

Is the given cpu time included in real time?

These are two different things. The "real time" is the "wall clock" time. This means that you run your Java code, start a stopwatch and stop it when the program completes. The time you get is the "real time" taken by your code to execute. Even if you don't explicitly create threads, the JVM has its own set of threads: the main thread which executes your code, the GC thread etc. If your code is doing a lot of IO and waiting around for stuff, it's quite possible that the "CPU" time might be quite lower than the real time but if you are doing extensive computations on a multi-core box, the figures might be reversed.

You can always verify your timings by running the same program using the *nix time command as already mentioned in my previous post but it will give you the time in millisecond resolution and not nanosecond.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

if your program has no I/O, and there's nothing else running on the machine at the same time, then for most purposes you can assume CPU time == real time

If the program in multi-threaded, the CPU time gives the "total" time spent by each CPU/core. So even if the real/wall time is 1s, it's quite possible that the CPU time might be 4s for a multi-threaded CPU intensive code.

@corol
There are two techniques which you can put to use:

  1. Use the JMX API to get an approximate CPU time for all threads
  2. Use the time unix command when executing your Java process

For (1), you can have a look at the Thread MBean. Here is a small snippet:

public class TestIt {

    public static void main(String[] args) throws Exception {
        int numThreads = 5;
        long start = System.currentTimeMillis();
        for (int i = 0; i < numThreads; ++i) {
            new MyThread().start();
        }
        ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
        long[] allThreadIds = threadMXBean.getAllThreadIds();
        System.out.println("Total JVM Thread count: " + allThreadIds.length);
        long nano = 0;
        for (long id : allThreadIds) {
            nano += threadMXBean.getThreadCpuTime(id);
        }
        System.out.printf("Total cpu time: %s ms; real time: %s", nano / 1E6, (System.currentTimeMillis() - start));
    }

}

class MyThread extends Thread {

    public void run() {
        int sum = 0;
        for (int i = 0; i < 1000000; ++i) {
            sum += i;
        }
        sum = sum + 1;
    }

}

Of course, this snippet has problems of its own. This code won't consider …

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Markdown is better not because it has great preview etc. but because you don't require special keywords to do the formatting which is so much easier for the end user. Markdown is clearly inspired by the newsgroup way of doing stuff. For e.g. I don't need to use the pseudo XML syntax with square brackets to tell the parser that I want so and so text segment quoted. I can just use > and be done with it. Similarly with bold and italics. What's more, Markdown text doesn't look like a load of markup text written to do some simple formatting. It just works with the minimum possilbe noise.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I asked it quite a while back here and was told it might pop up in a week or so after critical issues are taken care of. Sorely disappointed that it won't be. I think this is a pretty basic feature supported by a lot of forum packages out there. Hope it makes its way into the TODO list...

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I think that's a known bug. I deleted posts made by "bedexchange" on this sub-forum since they were breaking the rules but the forum view still hows his name even though the post no longer exists. I thought this was just a problem for admins/moderators but seems that isn't the case here.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Just FYI, the link: http://www.daniweb.com/stats/toplist is broken for me.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I think the way it works is that if you have other "unread" PM in your mail box, those are pushed to the top. So if you move between pages in your inbox, maybe moving to the last page or moving to the first "read" PM, you might be able to find your PM. I have my own share of problems with the inbox but auto-deletion is not one of them. :)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hi folks,

Please join me welcoming our two new moderators: ardav and pyTony.

@pyTony & @ardav
Congratulations on your new role at Daniweb. Celebrations ahoy! :)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

since you here are explicitly saying you want a new Object, a new String will be created in the pool, and your second variable will point to that one

This isn't correct AFAIK; instantiating new strings on demand doesn't send them to the "string pool" unless the newly created string is specifically/explicitly interned.

and right now I can't think of a single reason why you would want to do that

Creating a new String isn't a common occurrence though it might be required in some cases. Two reasons I can think of:

  • You are working with a mixed-mode binary protocol which has binary content interleaved with textual content. If you want to create a String out of bytes, you need to use the string constructor
  • You are reading large amounts of textual data from an external source (each line containing around 1K-10K words) but you need to work with just a small chunk of that text. The substring method returns a shallow copy of the string so the substring always refers to the char array of the original string. This is a problem because if you are doing substring on a very large string, you'll end up hanging around with more data than you require. In this case, creating a new String is a good way of making sure the large string is eligible for garbage collection.

As an example for the above explanation:

public class Testi {

    public static void main(String[] args) throws Exception …
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

BTW, on the Python feud, people respond differently to a new language like python. Personally, I think I got put off from python by the drastically different syntax, but mostly by the lack of clarity in type specifications, scoping rules, abstract memory model, etc.

I don't think kids or those starting out with programming need to worry about such things. Nothing is more unrewarding than sitting down to solve a problem only to find the language getting in the way, time and time again. Is C++ or C a bad choice? Absolutely no. Is it a bad first language? If you are trying to learn programming, yes, I would say so.

and those who see those things as annoying things to worry about in C++ it is not surprising they adopt Python very easily, but those who see these things as great tools to create robust software will have a hard time letting go of it

I can sense this going in the direction of "this is what separates the boy's from the men". Python is pretty much capable of creating a "robust" software. Heck, I have seen Python being used as a backbone for creating pricing related apps in a "big bank".

Those of us who have tried to teach programming to kids would be pretty much aware of the problems one faces when using a language like C or C++ as the first language. I know I have. I'd personally recommend the top to …

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hi folks,

Spring 2012 anime is just around the corner! The chart stating the names of the anime to be aired along with their tentative dates can be found at: http://atxpieces.wordpress.com/2012/03/01/spring-v3/

I would definitely be watching the below:

  1. Zetman
  2. Accel World
  3. Eureka 7 : Astral Ocean
  4. Fate Zero II (Hell yeah!)
  5. Jormungand
  6. Kimi To Boku 2 (An exceptional slice of life anime)

If you are planning to watch this season, what's on your list? :)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> The idea is that no system is perfect ...

Sure, I understand that. I was just curious about your statement related to "double exposure" and was wondering whether you had arranged an implementation wherein threads tagged with "java" in the MySQL forum would also show up in the Java forum with both the links (the one present in MySQL and Java forum) referring to the same thread.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Therefore, you can post in the PHP forum with the tag MySQL and your thread will get double exposure

This is possible even now, except for the double exposure part. :)
What exact measures do you have in mind to ensure wide adoption of tags to the point that they are actually useful?

I can see the concept of tags working good for a given forum (i.e. MySQL, Oracle tags in Database forum) but cross-forum, not so much.

For e.g. someone wants Python client to communicate with a Java server which is hooked to MySQL database and he is having problems interfacing the three of them. A minor portion of the crowd would try to break down the issue into different parts and post in it relevant forum. But, a majority of them decide to post it as a single blob.

In that case, which part of the forum does this thread go in? If someone decides to post it in MySQL with "python" and "java" tags, what is the probability of it being picked up by folks at the Java/Python forum?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Any specific reason you want to load resource relative to a class and not relative to a classloader using MyClass.class.getClassLoader().getResourceAsStream("my/pkg/file.txt") ?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Peter, zeroliken was actually replying to "frivolous". It seems that the order of the first two posts was reversed.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

If those string belong to a fixed set of values, consider using an enum instead of strings which have the added benefit of type safety. There might be other ways of achieving what you desire but difficult to suggest without more context.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The simplest solution would be to introduce a new "command" like consoleWriteLn (similar to print v/s println when using System.out). So if the user uses "consoleWrite" it would correspond to System.out.print whereas if the user uses consoleWriteLn .

BTW, why not use shorter commands like print and println ?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Such a feature already exists; look for a "message like image" next to the feed icon at the top of your post.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Here are my findings; `mmap` is wicked fast for large file sizes if they can completely fit in memory. Unfortunately, having a 32 bit machine limited by testing capabilities.

My config:

Windows XP 32 bit 3GiB RAM
  Intel i3 3.07 GHz
  SATA-II 3 GiB/s; 7200 RPM
  Python 2.7.2

My output:

Input file size: 348 MiB; iteration count: 20.0
        Function name: shutil_copy; total time: 78.0966309964 sec; one iteration: 3.90483154982
        Function name: mmap_copy; total time: 11.2840840173 sec; one iteration: 0.564204200866
        Function name: mmap_copy_chunked; total time: 225.959542146 sec; one iteration: 11.2979771073
        Function name: copy1; total time: 78.7868789942 sec; one iteration: 3.93934394971
        Function name: copy2; total time: 73.7354360477 sec; one iteration: 3.68677180238
        Function name: copy3; total time: 100.388904075 sec; one iteration: 5.01944520376
Input file size: 15 MiB; iteration count: 100.0
        Function name: shutil_copy; total time: 2.5043987676 sec; one iteration: 0.025043987676
        Function name: mmap_copy; total time: 2.87714018718 sec; one iteration: 0.0287714018718
        Function name: mmap_copy_chunked; total time: 30.966067508 sec; one iteration: 0.30966067508
        Function name: copy1; total time: 2.38466791661 sec; one iteration: 0.0238466791661
        Function name: copy2; total time: 18.5943323786 sec; one iteration: 0.185943323786
        Function name: copy3; total time: 2.03054891633 sec; one iteration: 0.0203054891633

Code:

import mmap
import os
import shutil

# uses generator to load segments to memory
def copy1(src, dst):
    def _write(filesrc, filedst):
        filegen = iter(lambda: filesrc.read(16384),"")
        try:
            while True:
                filedst.write(filegen.next())
        except StopIteration:
            pass

    with open(src, 'rb') as fsrc:
        with open(dst, 'wb') as fdst:
            _write(fsrc, fdst)

# loads entire file to memory
def copy2(src, dst):
    with open(src, 'rb') as fsrc:
        with open(dst, …
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

"Saviour Of Sanity" for those crying out help ("sos") in these forums. ;-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

This is not an issue but a concious site-wide decision. IIRC, this was put in place to ensure we don't end up getting members who post for the sole purpose of "exposing" their sig links to "teh internet". As a user, you have no control over this behaviour, so no, it can't be resolved.

Similar thread in the past.

happygeek commented: absolutely +0
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Assuming the text is from the wikipedia description of PI, there are a few problems. First, the text is completely garbled; how did you generate the text file? Second, why UTF-16? Did you specifically encode the file as UTF-16? If yes, then is it without BOM or with BOM?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Fixed title; you can always try to get the title edited by "flagging" it as bad post.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

OK, now that we have confirmed that you have some characters with surrogate pairs, the next point would be to understand what is the Charset used when opening the file stream for reading. Make sure that you don't rely on the default OS charset (windows-1252, latin etc.) and explicitly pass UTF8. Something like (not tested):

new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF8"));

Since UTF-8 is backwards compatible with ASCII (or ASCII is acceptable UTF-8), you'll be able to read regular characters along with characters having surrogate pairs.

If it still doesn't work, post/attach a small fragment of your text file.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

What kind of file is it? What kind of "text" does it contain? If it contains ASCII encoded text, you'll always get the char count of a string same as the number of code-points. Read this, try to understand it and get back in case of more queries.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Please don't conflate strong disagreement and resetment towards advice given with impoliteness.

Plus, my first post was meant to push OP to do a bit more research about BigIntegers and you pretty much handed the answer. Questions posted (especially by studnents) are much more about the learning involved in reaching the answer rather than "getting" the answer.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

So? It still doesn't change the fact that it will fail for certain inputs as mentioned above and the worst thing is that regular tests which don't exercise the limits won't be able to uncover this problem.

Please don't provide sub-standard advice to beginners who wouldn't know the difference between "working" and "correct" code. It's a pity that my post, which tried to push adil in the right direction was downvoted. If someone wants to challenge my post above, I would be more than happy to provide reasons/discuss.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Convert it to long first using Long.parseLong() and then convert the long to BigInteger using BigInteger.valueOf(long val)

This won't work if the string representation is outside the "long" data type range, which is one of the main motivation for using BigInteger...

thanks dear it worked, but isn't there any direct way for such a conversion??

There is no direct way to do these conversions given that like C++, Java doesn't support operator overloading.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

In what way is the BigInteger constructor which accepts a string not working out for you?

Philippe.Lahaie commented: the constructor that receives a char array was definitly the right answer all along ;) +6
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Try wrapping the `value` elements in a parent element called `values` and have a look at this thread.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

`clone` here is working as expected. It's cloning the "TreeMap" which is why "put" in the cloned one doesn't affect the "old" one. It's not cloning the key or value; so basically keys and values are "shared" across the two Map instances. This is only an issue if you are modifying the "state" instances which will modify the "state" object of both old and new maps.

I would personally use Java's equivalent of a copy-constructor rather than cloning stuff i.e. Map<String, State> cloned = new TreeMap<String, State>(original); since it at least doesn't throw type safety warnings (clone returns Object).