cHao
  • Member for 10 years, 11 months
  • Last seen more than a week ago
  • Richmond, VA
Floating-point binary/decimal/octal/hex converter
Accepted answer
3 votes

Behind all the ifs in main(), I see lurking a parameter: unsigned inputBases[] = { 2, 10, 8, 16 }; unsigned inputBase = inputBases[choice - 1]; std::string input; std::getline(std::cin, input); ...

View answer
Nested try/catch with PDO in PHP
3 votes

Exception handlers that don't either handle exceptions or rethrow them, generally shouldn't exist. An exception signals that a breakage has occurred -- one serious enough that the thrower thinks that ...

View answer
Very Basic Java Piano
3 votes

If this class is intended to represent the whole UI, window and all, you might consider extending JFrame and using this rather than frame. Right now, when you initially create a VirtualKeyboard, it's ...

View answer
Swapping adjacent nodes of a linked list
Accepted answer
3 votes

Consider having swapAdjacent(NULL) return NULL. Once it does, you can get rid of the whole if (nextNode == NULL) statement, and just unconditionally say temp->next = swapAdjacent(nextNode);. You ...

View answer
Is coding to an interface with regards to PDO the right thing to do?
Accepted answer
3 votes

This feels quite over-engineered to me, when i can do the work of all three classes in one line of code. echo new PDO('mysql:host=localhost;dbname=test', 'root', 'root'); The big question to ask ...

View answer
Simple static integer stack
3 votes

If you have to implement a stack backwards, ok. :) It's a common thought pattern; i used to do it all the time too. But the truth is, it makes a lot of things easier if you consider the stack to ...

View answer
Filter Class to sanitize and transform input data - Improvements?
Accepted answer
3 votes

OK...first off: this isn't OOP. OOP is about objects talking to each other, delegating tasks to each other to get stuff done. What you're doing here is just using classes as modules. There's ...

View answer
RPN Evaluator that writes the results to a text file
3 votes

Once you've underflowed the stack, an expression is invalid. Every operation from that point til the next ; could be considered broken. Even if the expression later "recovers" and contains enough ...

View answer
Simple PHP Router
Accepted answer
3 votes

I'm not seeing why you preg_match_all, considering you (can!) really only deal with the first match. Why not something like if (preg_match($pattern, $url, $params)) { array_shift($params); ...

View answer
Breakout-style game
Accepted answer
2 votes

First, the small stuff. getBallDiamiter has a misspelling. movement kinda sucks as a method name. move would be better, but makes ball.move(30, 100) a bit ambiguous. It's better if classes that don'...

View answer
Matching parentheses
Accepted answer
2 votes

One thing you can do is insert beforehand the characters you want to track. var _inputDictionary = new Dictionary<char, int>(); foreach (char c in "{}[]()") { ...

View answer
Fetching a post from the database based on a query parameter
Accepted answer
2 votes

There are two things that jump out at me: You assume $_GET['post'] exists. If someone just goes to post.php without specifying a parameter, $_GET['post'] is not set -- and any attempt to read it ...

View answer
Allocating memory and releasing the same
Accepted answer
2 votes

I could see passing the pointer to another thread, and the other thread deleting the object. (Gives me the willies, but it at least makes sense.) But if PostThreadMessage itself is doing the ...

View answer
First PHP login system
2 votes

$userName = $_POST['name'] or ""; doesn't do what it looks like it does. or has a lower precedence than just about any other operator in PHP, including =. So that line is equivalent to ($userName = $...

View answer
Simple sign up form
Accepted answer
2 votes

add is doing both validation and insertion. It'd probably be better if the two tasks were separated. That'd make it possible to validate something without trying to add to the DB just yet. :P I ...

View answer
PHP PDO Custom class ple
2 votes

Those constants, DB_HOST etc, since there's no easy way to redefine them, pretty much ensure that you can only ever have one database per run of your app. Maybe this is an issue for you; maybe it's ...

View answer
OOP PHP form ok?
2 votes

If you have more than one button or input field per form, or are ever using the same instance for more than one form, then no, this code is not OO at all. Even if you only have one, it's quite a ...

View answer
Check if the given string has duplicates
1 votes

There are considerably more than 25 ASCII characters. Did you mean ASCII letters? Cause if the test was for characters, this code will break. But even if it's just letters, (case aside,) there are 26 ...

View answer
Monitoring real-time air waves
1 votes

This loop looks odd... static void *demod_thread_fn(void *arg) { while (!do_exit) { if (do_exit) { return 0; } ... } return 0; } Looks ...

View answer
Inserting new rows into an existing table
Accepted answer
1 votes

Before I continue, the following must be said: Stop using mysql_query. Seriously. There have been very good replacements for going-on a decade now. And considering this code does not appear to ...

View answer
Secure image upload class
1 votes

Using static methods is not appropriate if your only good reason for doing so is performance. I can confidently say that outside of a benchmark, neither you nor anyone else will ever notice the ...

View answer
Matching a pattern in many lines of text
1 votes

Why are you creating a new ArrayList each time, then filling it with (read: basically copying each element of) a list you created from an array? You have no need right here for the dynamic-ness of a ...

View answer
Switching back and forth between forms
1 votes

The hiding thing strikes me as a little bit odd. Generally one doesn't care about hiding the main form. If the intent is to switch between "pages" in the app, a tab pane or wizard-style setup might ...

View answer
Best way to iterate over JSON
Accepted answer
1 votes

You could use a recursive function to traverse your object and generate the HTML. Something like: function generateList(items, depth) { if (!depth) depth = 0; var ul = new Element('ul'); ...

View answer
Is this how an MVC controller supposed to be?
0 votes

The biggest thing that bugs me about this is that Controller::__construct is basically handling the whole request. A constructor should be doing as little work as possible -- ideally only getting the ...

View answer
Increasing opacity based on an element's location
0 votes

You could easily loop over the element names... for (var i = 2; i <= 36; ++i) { if (scrolled > ($wheresThisAt + (i-1)*20)) { $('#salamander-' + i).css('opacity', 1); } else ...

View answer
1
2