1. Instead of reversing the string at the end you could construct it in the opposite order. Also, I'm not sure you can declare static variables inside a method C++, although it has been a while since I last used it.
I tested it, it does work. But I agree with ROBO_DONUT, this is a silly place to use recursion, although I assume he was doing it for a school assignment and needed to use recursion to do it.

2. It's a function, not a method.
C# dev here, you might be able to understand why I made the mistake

3. Oh, I didn't read that using recursion is a requirement. Nor did I know this was an assignment. I wouldn't have posted complete code if I knew that were the case.
Well it's not the answer he needs, anyway, so I'll leave it.

4. Okay, fixed some things, this works but the output is reversed, looking for a string reversal function now...
```string convertToBinary(int n)
{
static string buf;
if (n == 0) return buf;
buf.append((n % 2) ? "1" : "0");
return convertToBinary(n/2);

}```
Thanks a lot, I'll try to look for the reversal myself.

This is indeed an assignment, and the use of recursion is required here.
Friendly x 1 (list)

5. Also, I'm not sure you can declare static variables inside a method C++, although it has been a while since I last used it.
Static storage duration. If you define a static variable outside of a function, it has static linking.

6. So I have my player using a vector2 but when it moves diagonal and but the speed seems to increase only when it goes diagonal... Anyone know how to fix the problem so it stays the same speed always.

7. sqrt(2)/2

8. So I have my player using a vector2 but when it moves diagonal and but the speed seems to increase only when it goes diagonal... Anyone know how to fix the problem so it stays the same speed always.
Normalize the vector and then multiply it by a scalar (representing the speed you want it to have).

9. Avoid recursion when it isn't beneficial. If you use it in places where there aren't small upper bounds on the depth of the recursion, you risk a stack overflow. Not to mention the function call overhead.
I find that recursion is often a really nice way of breaking up a problem.

gcc can do tail call optimization anyway, so deliberately avoiding recursion is premature optimization

10. Just trying to draw a simple ball in Java, but it's not drawing. Here is my Ball class:
Code:
```import java.awt.geom.*;
import java.awt.*;
import javax.swing.*;

public class Ball extends JPanel{
int width, height;
double ballX, ballY;
Ellipse2D ball = new Ellipse2D.Double(ballX, ballY, width, height);

public void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;

g2.fill(ball);
}

public void setSizes(int w, int h){
width = w;
height = h;
}

public void setCoords(double x, double y){
ballX = x;
ballY = y;
}

}```
Here is my main class:
Code:
```import javax.swing.*;

public class Main{
public static void main(String[] args){
JFrame frame = new JFrame("Pong");
Ball ball = new Ball();

frame.setSize(600, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setLayout(null);
frame.setVisible(true);

ball.setSizes(50, 50);
ball.setCoords(20, 20);
}
}```
The frame pops up, but the ball doesn't.

11. I find that recursion is often a really nice way of breaking up a problem.

gcc can do tail call optimization anyway, so deliberately avoiding recursion is premature optimization
It's not an issue of deliberately avoiding recursion. In this specific case the problem is actually stated more clearly as a loop (at least in my opinion). Writing it recursively does not make the code significantly more terse/clear.

Additionally, depending on a specific compiler optimization becomes an issue of portability when compiling code without that feature is likely to result in a binary that is unstable. That one function could use well over 1kB in the unoptimized recursive form (on the order of tens or so bytes for register storage, args, local vars, return pointer, all multiplied by the 32 bits the function has to iterate through), which is absurd for a function that just produces a string of 32 characters. This function might be OK because the n in O(n) stack space is small (just 32), but it could quickly become unacceptable if n was much larger. IMHO, it is only acceptable to write recursive functions when you can assume practical limits on the depth of the recursion -- like tree traversal, which is O(log n) (assuming it is balanced).

12. So I figured out how to solve it without using strings. I still appreciate all your help.

```#include <iostream>
#include <string>
using namespace std;

int convertToBinary(int);

int main()
{
int n;
cout << "Enter non-zero integer or 0 to stop: ";
cin >> n;
while (n != 0)
{
int binary = convertToBinary(n);
cout << "The binary of integer " << n << " is " << binary << ".\n";

cout << "Enter non-zero integer or 0 to stop: ";
cin >> n;
}
cout << "Bye!\n";
}

int convertToBinary(int n)
{

if (n == 0)
return 0;
return 10*convertToBinary(n/2) + n%2;

}
```
Funny x 1 (list)

13. So I figured out how to solve it without using strings. I still appreciate all your help.

```#include <iostream>
#include <string>
using namespace std;

int convertToBinary(int);

int main()
{
int n;
cout << "Enter non-zero integer or 0 to stop: ";
cin >> n;
while (n != 0)
{
int binary = convertToBinary(n);
cout << "The binary of integer " << n << " is " << binary << ".\n";

cout << "Enter non-zero integer or 0 to stop: ";
cin >> n;
}
cout << "Bye!\n";
}

int convertToBinary(int n)
{

if (n == 0)
return 0;
return 10*convertToBinary(n/2) + n%2;

}
```
an int can store a max of 11 'binary' bits

14. God, C programmers are weird.

Code:
```public static String toBinary(int i)
{
String out = "";

for (int b=0; b<32; b++)
{
if ((i & (1<<b)) == 0) out += '0';
else out += '1';
}

return out;
}```
EDIT: Oh, so it has to recurse? I should probably read before I code.

15. I'm looking to render objects with multiple sub-meshes.

Should I create a single vertex-array for the model, and then just store multiple index-lists for the sub-meshes? Or should I store a single vertex array and a single index-list and then just store the start/stop for the sub-mesh? (I could see this creating a problem if the index list wasn't carefully built)

I'm looking for more generalities of rendering 'models' that support multiple sub objects (with multiple sub-groups) than anything language specific.

I just don't get how complicated rendering works.

16. I found this image I know it is for website design but what I like is that thing on the top right is there anything like that for visual studio? I could of sworn I have seen some pictures of it in an older thread but can't remember where, would help me a ton!

17. I found this image I know it is for website design but what I like is that thing on the top right is there anything like that for visual studio? I could of sworn I have seen some pictures of it in an older thread but can't remember where, would help me a ton!
I don't use visual studio myself but I've heard it said that MetalScroll is the visual studio equivalent for the code minimap feature in Sublime Text.

18. Productivity Power Tools also has that type of a scrollbar.

19. RockScroll only works on 2005 and 2008 apparently, you must get the adding that trobmaister12 just linked to.

It crashed VS the first time it opened, now it seems to be working, however I disabled everything cept the mapping scrollbar.

20. God, C programmers are weird.

Code:
```public static String toBinary(int i)
{
String out = "";

for (int b=0; b<32; b++)
{
if ((i & (1<<b)) == 0) out += '0';
else out += '1';
}

return out;
}```
EDIT: Oh, so it has to recurse? I should probably read before I code.
god C# programmers are weird

Dumb x 1 Winner x 1 (list)

21. So I have to make a program which uses MySQL,

You input into the program your login and password, it needs to check if that user exists in a MySQL database.

Anyone got any pointers on how to do this safely?

22. So I have to make a program which uses MySQL,

You input into the program your login and password, it needs to check if that user exists in a MySQL database.

Anyone got any pointers on how to do this safely?

You can also read up on salting, wich is a commonly used technique to improve the security of hashed passwords.
Informative x 1 Agree x 1 (list)

23. I'm looking to render objects with multiple sub-meshes.

Should I create a single vertex-array for the model, and then just store multiple index-lists for the sub-meshes? Or should I store a single vertex array and a single index-list and then just store the start/stop for the sub-mesh? (I could see this creating a problem if the index list wasn't carefully built)

I'm looking for more generalities of rendering 'models' that support multiple sub objects (with multiple sub-groups) than anything language specific.

I just don't get how complicated rendering works.
I'm no expert but any of those things work. (Sub) models are really just a convention in your code, when it comes down to it, you're sending a command to draw a range of data. If it's convenient to put the whole thing in 1 vertex buffer and 1 index buffer, then go for it. If you're asking whether you can render an entire model of sub models in one go, then not really. You're almost definitely going to need to change something between draw calls otherwise they may as well be one model.
Useful x 1 (list)

24. I'm no expert but any of those things work. (Sub) models are really just a convention in your code, when it comes down to it, you're sending a command to draw a range of data. If it's convenient to put the whole thing in 1 vertex buffer and 1 index buffer, then go for it. If you're asking whether you can render an entire model of sub models in one go, then not really. You're almost definitely going to need to change something between draw calls otherwise they may as well be one model.
Well my current theory is this:
Each object in 3ds Max exports as an individual object to the SMD file format. This object counts as a 'bone', so the mesh can be keyframe-moved and you don't need to spend your time making a bone, rigging it and animating the bone. This is just a uh 'feature' of the SMD format I guess, so it stays. I think it'd be more work to find a way to merge all of the meshes anyways.

Then within each object, each texture gets exported as a different sub-mesh (the object id stays the same, but the material on the triangle changes). Because of this each object can have sub-meshes. The theory in the end is that you'll draw a model, and lookup it's material, draw the sub-mesh, etc.

I don't know if the final vertex count would be drastically different from storing individual vertex buffers - I imagine most of the time a vertex comes to a point where it switches texture it's probably got a different normal anyways so they're really two vertexes (that just happen to overlap).

At this point it's easier to store an individual vertex list per sub-mesh, because that's how I read the SMD's. I guess I'll move forward with that and see how that goes.

You can also read up on salting, wich is a commonly used technique to improve the security of hashed passwords.
How safe would it be if I did it like this;

in C#

Client connects to SQLDatabase;
Using SQLDatabase;

if recieve( Empty set (0.00 sec) )

else
it will use the info recieved

26. How safe would it be if I did it like this;

in C#

Client connects to SQLDatabase;
Using SQLDatabase;

if recieve( Empty set (0.00 sec) )

else
it will use the info recieved

If you want to protect the stored data, you can encrypt it with a key that is unique for every user and can't be derived from any information in the database.

This is used in the industry to prodect stored data against employees and can be used to secure data where the database can be accessed by SQL.
Encryption also helps with SQL injection and other attacks where the database is queried. (Sony didn't use encryption for most data, so passwords and personal data were immediately available to the hackers once they knew about the exploit and the table names.)
Friendly x 1 Agree x 1 (list)

27. Make sure your whole authentication system runs through SSL. Without a secure transmission line, you can't do any real authentication because you can't trust that your Javascript has made it to the client without interception.

Make sure you only store/transmit passwords as salted hashes. An unsalted hash is as good as the password itself. If you use unsalted hashes, an attacker can grab the hash and use it in any other site which uses unsalted hashes without modification.

28. Is anyone here interested in making some graphics for the game I'm working on?
It's a version of an old viking game called Hnefatafl.

Something like this, but from a top-down perspective:

(Not my game)

Resources

A blank stone tile
One tile called the throne. The kings starting position.
A corner tile which the "King" is trying to get to.
A tile to mark the starting positions of whites pieces.
A tile to mark blacks starting position
A black piece
A white piece
Whites king piece

Currently I just use some simple grey tiles and Fleur-de-li's in different colors for the pieces :(

29. So I have to make a program which uses MySQL,

You input into the program your login and password, it needs to check if that user exists in a MySQL database.

Anyone got any pointers on how to do this safely?
If you do it like this, you can't release it to the public, the MySQL database login information would be accessable to everybody.
Informative x 1 Agree x 1 (list)

30. Hey guys, I'm writing a piece of code in the Processing thing that runs on Java that holds down certain letter on the keyboard using the "Robot" class. The issue I am having is that, while the keys can get pressed, and held down, the keyRelease function DOES NOT WORK, it just causes the button to be held down. I've searched online and cannot find help. This is the last piece of a fairly exciting project so I'd like it working. Here is my code that isn't working:

void draw()
{

while (mainSerial.available() > 0)
{
//println("RUNNING");

/*if(byteData == 127)
{
println("A has been Pressed!");
}*/

//println(byteData);

String stringConvert = binary(byteData,8);

//println(stringConvert);

if(stringConvert.charAt(0) == '0')
{
controller.keyPress(KeyEvent.VK_Z);

//println("BOOBEES");
}
else
{
controller.keyRelease(KeyEvent.VK_Z);
}

Thanks guys

31. Make sure you only store/transmit passwords as salted hashes. An unsalted hash is as good as the password itself.
So is a salted hash, if that's what you're transmitting for authentication purposes. The point of hashing is that an attacker who steals a copy of the database can't learn the secret string that he must send as part of a login, because he can't reverse the hash function. If your site expects the user to send the hash (salted or not) rather than the real password, the attacker does know that, and can send it.

Store salted hashes in the database. Transmit actual passwords (protected by SSL) over the network, to be hashed on the server and then compared against the stored value.

32. You can hash a hash, though, so you could do challenge-response auth without ever transmitting the plaintext password, which was sort of my point. i.e. you store the salted hash of the password in the database, send the client a unique per-session salt, have the client compute the password hash with the static site-specific salt, then again with the challenge per-session salt, and send that back to auth. No plaintext in the database, no plaintext transmitted, and an intercepted hash wouldn't be useful because it's tied to that one session.

The weak link, then, becomes the client-side Javascript, which could be intercepted/modified without SSL. And if you're using SSL, plaintext isn't much of a concern anyway.

So I don't really know what my point is. I'd probably just do it anyway and layer security on top of security because I'm irrational.
Funny x 1 (list)

33. What's a clear way of removing multiple elements in an array?

For a school assignment I have to make a class that holds an array of integers, and add methods that add to it, remove etc. Kinda like an ArrayList. The problem, however, is they want me to make a removeAll(int val) method that removes all occurrences of val from the list. For example, removeAll(4) would change

{1, 2, 4, 6, 3, 4, 4, 6, 5, 6, 4} to
{1, 2, 6, 3, 6, 5, 6, 0, 0, 0, 0}.

For my regular remove() method, I'm using Apache Common's Lang ArrayUtils class to remove the element. Removing all elements with it doesn't work fully, for some reason. My current plan of attack is to find out how many times val appears in the array, and then call ArrayUtils.remove() that many times. But it gives me weird results, for instance shrinking the array. Any other way to attack this? I can't use ArrayList supposedly, and I doubt they'll check if I am or not, but it would be nice to figure out how to do this the way they want me to.

34. Just bought two books, C# 4.0 Pocket Reference and SQL in 10 Minutes.

35. What's a clear way of removing multiple elements in an array?

For a school assignment I have to make a class that holds an array of integers, and add methods that add to it, remove etc. Kinda like an ArrayList. The problem, however, is they want me to make a removeAll(int val) method that removes all occurrences of val from the list. For example, removeAll(4) would change

{1, 2, 4, 6, 3, 4, 4, 6, 5, 6, 4} to
{1, 2, 6, 3, 6, 5, 6, 0, 0, 0, 0}.

For my regular remove() method, I'm using Apache Common's Lang ArrayUtils class to remove the element. Removing all elements with it doesn't work fully, for some reason. My current plan of attack is to find out how many times val appears in the array, and then call ArrayUtils.remove() that many times. But it gives me weird results, for instance shrinking the array. Any other way to attack this? I can't use ArrayList supposedly, and I doubt they'll check if I am or not, but it would be nice to figure out how to do this the way they want me to.
Do a loop, remove all the values that you need to. However are you sure you're supposed to turn them into 0's? What if one of your values was a 0.

Anyways, after you remove the values, you could sort it. QuickSort is a nice one ;)

36. RockScroll only works on 2005 and 2008 apparently, you must get the adding that trobmaister12 just linked to.

It crashed VS the first time it opened, now it seems to be working, however I disabled everything cept the mapping scrollbar.
I ended up disabling half the stuff... as much as I like the new Document Well 2010 Plus tabs, it was a bit buggy on my system so I reverted to the old tabs.

Quick Find/Triple Click are amazingly useful though. And I set the scroll bar not to map mode, but to paint over the scrollbar with changes/caret location/find results/etc.

37. Thanks for the tips guys, I'm going to be in charge of making a megaupload type software for clients to check their status/ upload files.

Need all the security I can get!

I have like 4 months to do this though :D
Funny x 10 (list)

38. You can hash a hash, though, so you could do challenge-response auth without ever transmitting the plaintext password, which was sort of my point. i.e. you store the salted hash of the password in the database, send the client a unique per-session salt, have the client compute the password hash with the static site-specific salt, then again with the challenge per-session salt, and send that back to auth. No plaintext in the database, no plaintext transmitted, and an intercepted hash wouldn't be useful because it's tied to that one session.

The weak link, then, becomes the client-side Javascript, which could be intercepted/modified without SSL. And if you're using SSL, plaintext isn't much of a concern anyway.

So I don't really know what my point is. I'd probably just do it anyway and layer security on top of security because I'm irrational.
Wuala probably hashes passwords twice, at least that's the sanest approach for clientside symmetric encryption.

Helps with plausible deniability too

39. What is so funny about my post :D?

40. What is so funny about my post :D?
have you been living under a rock
Agree x 9 (list)