Open Side Menu Go to the Top

10-01-2014 , 03:18 AM
I don't have a reddit account and have been on the site maybe 20 times total. 100% via google.

Pretty happy about that, seems like a huge time sink. But who am I kidding >40k posts on a poker forum...lol
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
10-01-2014 , 08:18 AM
Hah, we joined more or less the same time... You out posted me by about 8-1.
Then again, I'm not the most communicative person there is, so that was to be expected, I guess.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-01-2014 , 09:40 AM
Quote:
Originally Posted by Gullanian
Might be faster to multi thread it if you haven't already as well (probably done that as well thou )
That's a great point Gullanian, I am sure it would be.

From my humble experience with networks and multi-threading I did notice a great difference between single and multi threaded cases.

And it does seem like jsoup isn't fully taking advantage of my bandwidth when I am observing the process (it uses 0.1-0.8 Mbps while bandwidth is a bit under 5Mbps).

It's also going to be a fun way of taking advantage of my new i7 4770k.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-01-2014 , 10:40 AM
Quote:
Originally Posted by kazana
Hah, we joined more or less the same time... You out posted me by about 8-1.
Then again, I'm not the most communicative person there is, so that was to be expected, I guess.
Well most of my posts are from my werewolf playing days (retired from the game after I hit my final achievement)
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-01-2014 , 10:41 AM
Yeah, just ran it with 10-threads mode, loaded this entire thread in 2 minutes.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-01-2014 , 10:51 AM
Great Down from 5 minutes is a nice improvement. I'd play with the thread counts, try 3, 10, 25, 100 and see which works best. I imagine the sweet spot probably is around the 10.

However keep in mind would recommend you are careful as you might get shut off for excessive traffic or cause headaches for a webmaster somewhere out there.

As the data you're looking at it largely unchanging (and any changes would be completely minor in the context you're looking at them in) you might also consider caching the text you download so if you run again on the same thread it will be a lot faster.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-01-2014 , 12:25 PM
Barrin,

my whole class failed and he's letting us retake it for 90% of the original. I'm gonna do it since I got a 71.

The problem was given an input like 4 4.1 3 2.7 1 5.0 0 etc etc

you were supposed to take 4 times 4.1, add it to the running sum, find the average and number of numbers per "line" which ends at 0. a 0 makes a new line if there are any numbers after it.

I spent 20 minutes trying to get the correct number of lines to pass the tests, and then there was a stupid off by one error caused by EOF that I couldn't figure out and started panicking and spaghetti coded my way to a C. Was a little frustrating because I went home and figured it out in less than 10 mins. I think I don't do well under that pressured environment where you can see the countdown clock staring you in the face and all you have is that crap ass text editor. And the tests he gives you to check your code don't really help that much for debugging whatever's wrong.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-01-2014 , 04:34 PM
We got that email too. I think it's for all of his sessions.

I got 100% but not after having a full panic mode when my code wasn't outputting anything. I also spent the first 10 mins doing problem 2 when I thought I was doing problem 1. But yea I feel your pain in regards to the pressure. Two problems in 60 minutes is pretty rough.

My problem was the same as yours but with words. Luckily that was one of the problems I practiced. Did you go through most of the practice problems? If you do them, the test should be pretty easy.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-01-2014 , 05:08 PM
I did half of them, would have done fine probably if it was with strings because that was mostly what I studied, going through streams line by like and token by token.


Gonna retake and expect to get 100. I didnt even know our text editor had the "go" option so i was trying to debug just from his final checker and thats a little confusing. I use eclipse for all my hw.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-02-2014 , 03:18 AM
So, I've never been much of an open source dude or someone programs stuff on their own time that has them downloading random libraries off the internet, but I have a week off between jobs this week and a friend asked if I could write a simple program for him so I was like sure, sounds good.

He wants me to go through MP3 files in a folder and set the ID3 tags for the song name/artist name according to the filename. I figured there has to be a library available to do this and sure enough, Google leads me to id3lib.

So, I download the library and include files and start writing code. When I get to the part where I'm actually reading tags out of these files, though, things aren't working quite as advertised.

Documentation on the ID3Field class, which is a representation of an individual field containing a piece of data (like song name or artist name):

Quote:
All strings in id3lib are handled internally as Unicode. This means that when you set a field with an ASCII source type, it will be converted and stored internally as a Unicode string. id3lib will handle all necessary conversions when parsing, rendering, and retrieving. If you set a field as an ASCII string, then try to read the string into a unicode_t buffer, id3lib will automatically convert the string into Unicode so this will function as expected. The same holds true in reverse. Of course, when converting from Unicode to ASCII, you will experience problems when the Unicode string contains characters that don't map to ISO-8859-1.
In practice: I have an ID3Field for which GetRawText() (returns const char*) returns NULL but GetRawUnicodeText() (returns const unicode_t*) returns valid memory.

There is an overloaded Get() function into which I can pass a char* or unicode_t* buffer and have it copy the string for me; calling the unicode_t version does not fill the buffer with the same data that I get by calling GetRawUnicodeText(). I'm not sure what it's filling in exactly, it looks like garbage data. Calling the char version does not copy any data in.

Documentation on the function that gets the size of a text field:

Quote:
The value returned is dependent on the type of the field. For ASCII strings, this returns the number of characters in the field, not including any NULL-terminator. The same holds true for Unicode---it returns the number of characters in the field, not bytes, and this does not include the Unicode BOM, which isn't put in a Unicode string obtained by the Get(unicode_t*, size_t, index_t) method anyway.
In practice: this function returns to me the size of the unicode field in bytes (2 * the number of characters), directly contradicting the bolded.

Is this a typical experience when one is like "hay I'm sure there's already a library to do this"? Because holy **** I did not feel like debugging all the quirks of this library (and having to write **** code to get around them) when I started writing what should have been a pretty simple program.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-02-2014 , 04:10 AM
Quote:
Originally Posted by goofyballer
Is this a typical experience when one is like "hay I'm sure there's already a library to do this"? Because holy **** I did not feel like debugging all the quirks of this library (and having to write **** code to get around them) when I started writing what should have been a pretty simple program.
Yes, even when people try to write reusable code it rarely solves exactly the problem you want to fix.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-02-2014 , 05:19 AM
A couple random C++ questions. I've been doing mostly C work (and doing basic polymorphic stuff with C++ but not super serious stuff, nothing with templates) for the last six years, my new job is more serious C++11 so I've been reading The C++ Programming Language and Effective C++ to get prepared.

1. All the stuff I'm reading is like "use vectors, they're great! don't use pointers, they're evil! pass everything around by reference!"

So I'm like, ok, cool, let's give this a shot.

Code:
class Test
{
public:
	Test( int init ) : x( init ) { cout << "ctor " << x << "\n"; }
	Test( Test& Other ) : x( Other.x ) { cout << "copy " << x << "\n"; }
	~Test() { cout << "dtor " << x << "\n"; }
private:
	int x;
};

void func()
{
	const int vect_size = 2;
	vector<Test> vect;
	vect.reserve( vect_size );
	cout << "starting creation\n";
	for ( int i = 0; i < vect_size; i++ )
	{
		vect.push_back( Test( i ) );
	}
	cout << "ending creation\n";
}
The output here:

Code:
starting creation
ctor 0
copy 0
dtor 0
ctor 1
copy 1
dtor 1
ending creation
dtor 0
dtor 1
I'm not necessarily surprised at how this works - that it's constructing the objects in the for loop, then copying them to put them in the vector - but I guess I'm wondering if there isn't a more efficient way to do this for objects that I want the vector to have full ownership of? The only way I can think of to ensure the constructor is only called once is to be like

vect.push_back( new Test( i ) )

but then my vector isn't a vector<Test>, it's a vector<Test*>, and I'm using pointers, and aaahhh pointers are evil, and aaahhh I have to free the memory myself still!! How should this code be written instead?

I noticed that if I implement a move constructor in Test, the "copy" lines in the output change to "move", which certainly could be faster if there's big arrays of data involved but I don't think would help me out here.

2. iirc, people have told me this sort of syntax is bad:

Code:
struct TestStruct
{
    int a;
    char b;
};

void f()
{
    TestStruct bob = { 1, 'z' };
}
because it creates a temporary struct object with the values { 1, 'z' } and then copies it into bob. However, when I dress up TestStruct with the same kind of constructor/destructor/copy/etc output that I used in question 1, I only see the constructor running once for that initialization. What's the deal there?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-02-2014 , 06:50 AM
I jettisoned id3lib when I got a runtime assert deep in id3lib.dll about opening a null filename via an object that I absolutely initialized with a valid filename (I mean, ffs, it was able to read the info out of it properly) when I tried to save my changes back to the mp3 file.

So, I instead got TagLib, which was much easier to work with code-wise but required me to install CMake to run some crazy nutso scripts to build the libraries (y u no give me binaries???). Oh and the linker gave me errors about every function in the library being undefined until a 2012 answer on StackOverflow told me that I needed to #define TAGLIB_STATIC in my code to link it statically because I don't want to have to send my friend a dll and this wasn't anywhere in the instructions. And also I had to set code generation in visual studio to /MT or else the linker barfed all over every library object.

But once I got past that it worked great! Jesus this type of development seems exhausting.

Last edited by goofyballer; 10-02-2014 at 06:51 AM. Reason: taglib is pretty kool though, everything I need to do with it = 4 lines of code
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-02-2014 , 09:29 AM
stack overflow driven development ftw
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-02-2014 , 11:23 AM
I'm shocked, just shocked that this thread isn't buzzing over Windows 10.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-02-2014 , 11:42 AM
That's because everyone is gosu and uses <insert some unheard linux distro>
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-02-2014 , 01:03 PM
I found this entertaining though:

http://www.pcworld.com/article/26907...gacy-code.html

Quote:
To save time, some third-party Windows desktop developers used a shorthand to check the version name (not number) of Windows they were installing their app to. Instead of coding apps to check for Windows 95 or Windows 98, developers coded instructions to check for "Windows 9."
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-02-2014 , 03:20 PM
why didnt they just come up with a code name for the new windows, like Vista or XP and others. That way the general public is all "herp derp, what happened to 9? lol microsoft" and you can still not ****up everyones ****ty code? Or am I not understanding it correctly
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-02-2014 , 04:03 PM
I don't think skipping 9 is a big deal and I suspect they want to get away from code names and get onto standard version numbers.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-02-2014 , 05:17 PM
found this on reddit

Code:
 package org.jvnet.hudson.plugins.platformlabeler;

import net.robertcollins.lsb.Release;

import hudson.remoting.Callable;
import java.util.HashSet;

class PlatformDetailsTask implements Callable<HashSet<String>, Exception> {

    /** Performs computation and returns the result, or throws some exception. */
    public HashSet<String> call() throws Exception {
        final String arch = System.getProperty("os.arch");
        String name = System.getProperty("os.name").toLowerCase();
        String version = System.getProperty("os.version");
        if (name.equals("solaris") || name.equals("SunOS")) {
            name = "solaris";
        } else if (name.startsWith("windows")) {
            name = "windows";
            if (name.startsWith("windows 9")) {
                if (version.startsWith("4.0")) {
                    version = "95";
                } else if (version.startsWith("4.9")) {
                    version = "me";
                } else {
                    assert version.startsWith("4.1");
                    version = "98";
                }
            } else {
                if (version.startsWith("4.0")) {
                    version = "nt4";
                } else if (version.startsWith("5.0")) {
                    version = "2000";
                } else if (version.startsWith("5.1")) {
                    version = "xp";
                } else if (version.startsWith("5.2")) {
                    version = "2003";
                }
            }
        } else if (name.startsWith("linux")) {
            Release release = new Release();
            name = release.distributorId();
            version = release.release();
        } else if (name.startsWith("mac")) {
            name = "mac";
        } else {
                // Take the System.properties values verbatim.
        }
        HashSet<String> result = new HashSet<String>();
        result.add(arch);
        result.add(name);
        result.add(version);
        result.add(arch + "-" + name);
        result.add(name + "-" + version);
        result.add(arch + "-" + name + "-" + version);
        return result;
    }
}
https://searchcode.com/?q=if%28versi...indows+9%22%29

why the **** did that get so widespread?

edit: this one was great -
Code:
if (version.match(/Windows 9(5|8)/))
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-02-2014 , 06:08 PM
Quote:
Originally Posted by goofyballer
I'm not necessarily surprised at how this works - that it's constructing the objects in the for loop, then copying them to put them in the vector - but I guess I'm wondering if there isn't a more efficient way to do this for objects that I want the vector to have full ownership of? The only way I can think of to ensure the constructor is only called once is to be like

vect.push_back( new Test( i ) )

but then my vector isn't a vector<Test>, it's a vector<Test*>, and I'm using pointers, and aaahhh pointers are evil, and aaahhh I have to free the memory myself still!! How should this code be written instead?
Have you had a look at boost ptr_vector? That might help.

No idea regarding the struct initialisation question. I always set structs' members verbatim.

The only argument I personally know against using that form of initialisation is that it is highly error prone. If anyone changes the struct without spotting the initialisation you can run into serious headaches.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-02-2014 , 06:22 PM
Lol Windows haters. Shellshocked much?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-02-2014 , 07:14 PM
Quote:
Originally Posted by goofyballer
but then my vector isn't a vector<Test>, it's a vector<Test*>, and I'm using pointers, and aaahhh pointers are evil, and aaahhh I have to free the memory myself still!! How should this code be written instead?
....

I dress up TestStruct with the same kind of constructor/destructor/copy/etc output that I used in question 1, I only see the constructor running once for that initialization. What's the deal there?
You can wrap your Test* in a unique_ptr to avoid dealing with the raw pointers. I believe the answer to your second question is that it's just a compiler optimisation and is compiled the same as:

Code:
TestStruct bob{ 1, 'z' };
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-02-2014 , 07:40 PM
Quote:
Originally Posted by clowntable
Lol Windows haters. Shellshocked much?

I'm actually not a hater. I think the one OS for all platforms could be really cool - but I also doubt it will be anything more than marketing talk.

To be fair I haven't really looked at windows since a beta of Windows 8 that a co-worker was using. It looked ok, but I still see no reason to switch back from an Apple.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-02-2014 , 09:49 PM
Quote:
Originally Posted by skier_5
You can wrap your Test* in a unique_ptr to avoid dealing with the raw pointers. I believe the answer to your second question is that it's just a compiler optimisation and is compiled the same as:

Code:
TestStruct bob{ 1, 'z' };
Ah, that makes sense. So then it becomes...

Code:
	vector<unique_ptr<Test>> vect;
	for ( int i = 0; i < vect_size; i++ )
	{
		vect.push_back( unique_ptr<Test>( new Test( i ) ) );
	}
And my output becomes:

Code:
starting creation
ctor 0
ctor 1
ending creation
dtor 0
dtor 1
Very nice.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

      
m