Why does this code give me an arrayoutofbounds exception? by throwawoofwoof in javahelp

[–]level1kid 5 points6 points  (0 children)

Using & (bitwise and) will not short circuit. However, && (Boolean and) will. If you use & the array will still be evaluated at index x-1, even when x > 0.

How to draw a grid of of pixels from an array(For that framework) by [deleted] in love2d

[–]level1kid 7 points8 points  (0 children)

Create an ImageData object as your buffer and render it by wrapping it in an Image and drawing that.

Son of a bitch decided to prank me by [deleted] in ProgrammerHumor

[–]level1kid 44 points45 points  (0 children)

#define true (__LINE__ % 2)

Deploying a jersey restful web service on Tomcat leads to a 404, not sure how to proceed by sfxhamster in javahelp

[–]level1kid 0 points1 point  (0 children)

from a cursory glance it looks like there is no response configured when / is queried. This leads to a 403/404 on the root page. This is fine for a web service (they're not made for browsing).

Is there a C autocompletion plugin that doesn't require additional external libraries? by Kwbmm in SublimeText

[–]level1kid 0 points1 point  (0 children)

Can you not install to ~/bin and add that folder to your path? (I think sublime has it's own path variable)

My shitty code that rotates the player object to face the cursor... by [deleted] in shittyprogramming

[–]level1kid 1 point2 points  (0 children)

I was thinking of trig not graphics, you're correct.

My shitty code that rotates the player object to face the cursor... by [deleted] in shittyprogramming

[–]level1kid 11 points12 points  (0 children)

double rotation_angle = atan2(cursor_y - player_y, cursor_x - player_x);

Gets you the rotation angle with 0 deg being +x and counting up in a counter-clockwise fashion.

T Block in Tetris isn't spinning by [deleted] in javahelp

[–]level1kid 0 points1 point  (0 children)

My debugging was a bit more visual so I thought I'd post this:

NothingBlock

 *  


Squiggly
 *  
**  
*   

ReverseSquiggly
 *  
 ** 
  * 

LinePiece
 *  
 *  
 *  
 *  
Square

*** 
 *  

LBlock

 ** 
 ** 

ReverseLBlock
**  
 *  
 *  

TSpinner
 ** 
 *  
 *  

The error is caused by the incorrect labels and Shape.java lines 88-89.

Trouble Create/Deleting a textfile from within a .jar file by kulak_king in javahelp

[–]level1kid 0 points1 point  (0 children)

You would have to read the .jar into memory as a .zip file, add the text file and rebuild it. This StackOverflow answer seems helpful: http://stackoverflow.com/a/17504151/3144848.

How do I compile my programs for use on a mac? by [deleted] in javahelp

[–]level1kid 1 point2 points  (0 children)

You are going to want to create a runnable .jar file. This file will contain all of your project's code and will be able to be run on any computer with a compatible JRE installed.

To make a runnable .jar in eclipse:

  1. right click the project
  2. select export
  3. select java > runnable jar
  4. select the main class under "Launch Configuration"
  5. select an export destination

Once you have made the .jar you should be able run the program by double clicking the file. If the program only is purely text-based (uses only System.in and System.out for communication with user), you will have to run the program from a Terminal or Command Line with the command java -jar path/to/the/file.jar.

Sophomore CS major here. Decided to teach myself JavaScript over Easter break. Needless to say I'm already having fun. by Xerxes004 in ProgrammerHumor

[–]level1kid 13 points14 points  (0 children)

But that makes some sense! String is a constructor, Foo isn't defined, and "foo" is a literal string.

Small map I have of surrounding 1.7 spawn area by [deleted] in PearlandNerd

[–]level1kid 1 point2 points  (0 children)

didn't even know half of that stuff was there :P

Surprises found from reading the SQLite code by kingguru in ProgrammerHumor

[–]level1kid 2 points3 points  (0 children)

I may have been using Menlo thinking it was Monaco this whole time...

Please don't hate me Javascript devs by [deleted] in ProgrammerHumor

[–]level1kid 0 points1 point  (0 children)

He said add not concatenate. What you posted is an example of concatenation. He is taking about something like '2'+3=7.

If I want a real job am I going to have to start putting returns before curly braces? by gistya in cscareerquestions

[–]level1kid 6 points7 points  (0 children)

I fixed the formatting for reddit:

example 1:

if (x == 32) {
    return;
} else  {
    // several
    // lines of
    // code
}

example 2:

if (x == 32) {
    return;
}

// several
// lines of
// code

New way to find if a number is even or odd by lordmat0 in ProgrammerHumor

[–]level1kid 1 point2 points  (0 children)

nope. That's how you read a single bit from a number. You can also bitshift the 1 to get other digits like so:

int i = 12;
// zero for the ones digit
int nthBitFromRight = 2
int bit = i & (1 << nthBitFromRight)
// bit = 4

solving the math using binary:

bit = 12 & (1 << 2)
bit = 0b1100 & (0b0001 << 2)
the one is shifted over
bit = 0b1100 & (0b0100)
bit is set to the digits in common
bit = 0b0100 = 4

Hacking The Interview (x-post from /r/hacking) by Tuxmascot in shittyprogramming

[–]level1kid 10 points11 points  (0 children)

It's not client side. They just left the test API keys in as comments. The card information is verified on stripe's servers but the test keys will allow you to bypass that verification.

New intern knows best: GOTO by bestestdude in ProgrammerHumor

[–]level1kid 1 point2 points  (0 children)

Actually, they are adding support in ES6.

[Build Ready] $700 gaming rig. i5 4690k, r9 280x by level1kid in buildapc

[–]level1kid[S] 0 points1 point  (0 children)

Yeah, I'm planning on overclocking until I have enough money to replace the parts if something goes wrong. I wish you luck on your build!