• What Do You Need Help With? V6
    7,544 replies, posted
Doing some image processing in Java. [url=https://dl.dropboxusercontent.com/u/8416055/DeleteMe/8x8.jpg]Here is the image I am using[/url], it's just a test 8x8 image I made. The code I am using: [code]public void static main(String[] args) { File img = new File("8x8.jpg"); BufferedImage image = ImageIO.read(img); int width = image.getWidth(); int height = image.getHeight(); int pixelWidth = 3; if (image.getAlphaRaster() != null) pixelWidth = 4; // Some image formats have alpha, which is a fourth byte. byte[] pixels = ((DataBufferByte)image.getRaster().getDataBuffer()).getData(); int npixel = 0; // The actual pixel number for (int pixel=0; pixel < pixels.length; pixels += pixelWidth) { int b = (int)(pixels[pixel] & 0xff); int g = (int)(pixels[pixel+1] & 0xff); int r = (int)(pixels[pixel+2] & 0xff); System.out.printf("pixel %d (%d,%d): rgb = (%d,%d,%d)\n",npixel,npixel % width,npixel / height,r,g,b); npixel++; } }[/code] And the output: [code]pixel 0 (0,0): rgb = (118,0,143) pixel 1 (1,0): rgb = (62,26,126) pixel 2 (2,0): rgb = (109,242,247) ... pixel 8 (0,1): rgb = (91,23,134) pixel 9 (1,1): rgb = (63,45,121) pixel 10 (2,1): rgb = (130,210,219)[/code] Of which, only the value for pixel 0 (0,0) is correct. I don't even know where these other values are coming from. I don't think they even exist in the image, in any permutation.
[QUOTE=Contron;44204689]You can pass an array of whatever object in the list to the [URL="http://msdn.microsoft.com/en-us/library/z883w3dc(v=vs.110).aspx"]AddRange[/URL] method, like so: [code] List<string> list = new List<string>(); list.AddRange(new string[]{"Item one", "Item two", "Item three"}); [/code][/QUOTE] You don't even need Arrays, you can just do it like that: [code] List<String> list = new List<String>() { "test1","test2","test3" //... }; [/code] //Edit: Of course this just works when you create a new List
How could I create a subimage in JavaFX simply? Or do I have to resort to: [url]http://stackoverflow.com/questions/13426224/subrectangle-of-an-image-in-javafx[/url]
So I have a really technical software engineering job interview coming up (believe it or not some interviews just ask about your history). Hopefully this is the thread to ask this... Anyone know of good textbooks or online sources I can use to help study in the next week / on the six hour flight over? Schools don't teach everything (never implemented a B-tree/Trie or heard of NP-complete in school) and I know I haven't retained anything :v: [editline]11th March 2014[/editline] Oh also I think I'm pretty bad with Big O notation (like looking at code and saying it runs in whatever timing). And I know Big O is a must for this interview. So something specifically for that would help!
[QUOTE=thrawn2787;44207470]So I have a really technical software engineering job interview coming up (believe it or not some interviews just ask about your history). Hopefully this is the thread to ask this... Anyone know of good textbooks or online sources I can use to help study in the next week / on the six hour flight over? Schools don't teach everything (never implemented a B-tree/Trie or heard of NP-complete in school) and I know I haven't retained anything :v: [editline]11th March 2014[/editline] Oh also I think I'm pretty bad with Big O notation (like looking at code and saying it runs in whatever timing). And I know Big O is a must for this interview. So something specifically for that would help![/QUOTE] My recommendation is to look up CS uni PDFs. It seems that quite a few uni CS departments upload their lecture notes to the public web, available with simple Google searches. For example, here are some lecture notes on asymptotic notation (Big-O, Big-Theta, Big-Omega, etc): [url]http://eniac.cs.qc.cuny.edu/andrew/csci700/lecture2.pdf[/url] I've only skimmed through it, but it's 74 slides, starting with the definitions of the notations, then some examples, and going from there. Beyond that, I recommend just looking up data structures and algorithms. From what I've heard, that seems to be where the majority of stock interview questions for CS-related fields come from. You should be familiar with linked lists, heaps, hash-tables, and binary trees; naive sorting algorithms, comparison-based sorting algorithms, and linear sorting algorithms; finding and solving recurrences, actual and amortized operation costs; and all kinds of simple problems that involve fiddling with sequences in some way. Things that are taught by WWU's CS247 ("Computer Systems" isn't a useful name) wouldn't hurt either. Things like binary, signed and unsigned integers, IEEE floating-point, two's-complement binary representation; bitwise operations (AND, OR, XOR, NOT, etc), binary flags; a general understanding of how things like hard-disks and cache memory operates, simple optimization techniques like loop unrolling and in-lining. Some formal language theory & finite automata stuff may not be a bad idea to brush up on, either. Things like graphs, mathematical functions, injection versus surjection (mathematically); deterministic and indeterministic finite automata; push-down automata; Turing machines; alphabets and grammars. Note that I have no idea what all of this actually shows up in interviews, seeing as I've never been in one. I've just heard that these are all valid concepts to come up. I have listed them from what I feel (and have heard) to be the most important, with the most likely things at the top, and least likely at the bottom. I have also heard people (mostly my algorithms professor) refer to this book as "the bible of CS interviews." You can pick it up for like $25. [t]http://upload.wikimedia.org/wikipedia/en/4/41/Clrs3.jpeg[/t] If the PDF I linked to above doesn't do it for you for asymptotic notation, the first few chapters of this book are devoted to it, by the way.
Wow, nice post! Thanks! Yeah I've studied a lot of this in school. Again, just need to brush up a on a lot of it. I actually have been reading through a few books now but that was prep for the phone interview, which I apparently over studied massively for. I figure the on site interview is much harder, so I was wondering if you guys had any good sources. For those of you in a similar position I found[URL="http://steve-yegge.blogspot.com/2008/03/get-that-job-at-google.html"] Steve Yegge's blog post on interviewing at Google[/URL] pretty helpful. I've been reading through the book he recommends (the algorithm design manual) but he says people recommend the one listed above. And for those of you that haven't interviewed yet but plan to in the future, as I mentioned earlier a lot of companies don't ask technical questions and if they do they aren't tough. They figure most people coming out of school with a CS degree have a certain base knowledge so they care more about your history. The company I'm about to interview with is a bit different. [editline]11th March 2014[/editline] Also that's another thing. I've never actually taken a pure algorithms course, which sucks. At my school it is senior level and I didn't take it last year. It is usually taught in the fall but the Professor who teaches it was on leave last semester.
I'm a huge noob when it comes to this, so far I only know the very basics of C++. I'm learning from an E-book called "Jumping into C++" and one of the practice problems says "Turn the code that we wrote for insertionSort into an insertionSort function that works for any sized array." Now, I'm gonna be honest with you guys, I'm not even sure how the insertionsort function we wrote works, let alone how to edit it to work for an any sized array. This is the one that was already written. [CODE]#include <cstdlib> #include <ctime> #include <iostream> using namespace std; int findSmallestRemainingElement (int array[], int size, int index); void swap (int array[], int first_index, int second_index); void sort (int array[], int size) { for ( int i = 0; i < size; i++ ) { int index = findSmallestRemainingElement( array, size, i ); swap( array, i, index ); } } int findSmallestRemainingElement (int array[], int size, int index) { int index_of_smallest_value = index; for (int i = index + 1; i < size; i++) { if ( array[ i ] < array[ index_of_smallest_value ] ) { index_of_smallest_value = i; } } return index_of_smallest_value; } void swap (int array[], int first_index, int second_index) { int temp = array[ first_index ]; array[ first_index ] = array[ second_index ]; array[ second_index ] = temp; } // small helper method to display the before and after arrays void displayArray (int array[], int size) { cout << "{"; for ( int i = 0; i < size; i++ ) { // you'll see this pattern a lot for nicely formatting // lists--check if we're past the first element, and // if so, append a comma if ( i != 0 ) { cout << ", "; } cout << array[ i ]; } cout << "}"; } int main () { int array[ 10 ]; srand( time( NULL ) ); for ( int i = 0; i < 10; i++ ) { // keep the numbers small so they're easy to read array[ i ] = rand() % 100; } cout << "Original array: "; displayArray( array, 10 ); cout << '\n'; sort( array, 10 ); cout << "Sorted array: "; displayArray( array, 10 ); cout << '\n'; } [/CODE] I'm so lost that I'm not even sure what question to ask. I mean I understand how arrays work but the whole sorting thing is really throwing me for a loop and then there's like 5 problems after this, that I also have no idea how to do. They're all about sorting. I'm the only person I know that knows anything about this stuff, so i can't really ask anyone. Google just made me more confused too. I feel like a little kid asking the big kids that are taking AP calculus what 2 + 2 is.
Insertion sort is probably easier to understand if you don't do it in place (with the same array / list) the first time you learn it. Think of your array as 2 different arrays: the sorted and unsorted arrays. The sorted array begins as "empty". For each number in the unsorted array: find the smallest, remove it from the unsorted array, and place it at the end of the sorted array. Because you are doing the sort in place the sorted array is actually the left i elements (i being the i in the loop) and the unsorted array is the n-i right elements. Your swap function is what is taking elements and putting them into the sorted array, its just that you are swapping it with an unsorted element. It doesn't actually matter where the unsorted thing goes, but it is convenient to just swap it. [URL="http://en.m.wikipedia.org/wiki/Insertion_sort"]Wikipedia's articles[/URL] on most things CS are pretty easy to understand. Note your sort isn't really insertion sort, yours is backwards. It usually takes the next unsorted element, not the smallest, and inserts it into the sorted array where it is supposed to go. Example (your code): Unsorted | sorted | in place 5 4 3 7 | | 5 4 3 7 5 4 7. | 3. | [B][U]3[/U][/B] 4 [U]5 [/U]7 5 7. | 3. 4. | [B]3 [U]4[/U][/B] 5 7 7. | 3 4 5. | [B]3 4 [U]5[/U][/B] 7 | 3 4 5 7. | [B]3 4 5 [U]7[/U][/B] Same example with "normal" Insertion sort 5 4 3 7 | | 5 4 3 7 4 3 7 | 5. | 5 4 3 7 3 7. | 4 5. | 4 5 3 7 7. | 3 4 5. | 3 4 5 7 | 3 4 5 7. | 3 4 5 7 Bold is sorted, underline are the swapped elements
[QUOTE=thrawn2787;44210169]Insertion sort is probably easier to understand if you don't do it in place (with the same array / list) the first time you learn it. Think of your array as 2 different arrays: the sorted and unsorted arrays. [B]The sorted array begins as "empty". For each number in the unsorted array: find the smallest, remove it from the unsorted array, and place it at the end of the sorted array.[/B] Because you are doing the sort in place the sorted array is actually the left i elements (i being the i in the loop) and the unsorted array is the n-i right elements. Your swap function is what is taking elements and putting them into the sorted array, its just that you are swapping it with an unsorted element. It doesn't actually matter where the unsorted thing goes, but it is convenient to just swap it. [/QUOTE] Oh man, that really helped visualize things. Thanks. I also looked it up on wikipedia, I think I'm getting it. Appreciate it man.
I'll try my best to keep this question short. Basically I have a base interface: [code] public interface ISpooler { // Common properties }[/code] From this interface, I have 2 subtypes: [code] public interface ISpoolableBuffer: ISpooler { public byte[] Buffer { get; set; } } public interface ISpoolableChunk: ISpooler { public List<ISpooler> Children { get; set; } }[/code] Lastly, I have them in a parent container: [code] public class SpoolablePackage { public List<ISpooler> Spoolers { get; set; } }[/code] Obviously this means that Spoolers will be jagged and unpredictable. I need a way to flatten this list into one huge list. Since an ISpooler can potentially implement ISpoolableChunk, I need to take into consideration these scenarios. This requires a deep loop within the Children property, and starting the exact same process over again. Here's my current solution: [code] private List<ISpooler> RecurseAndFlatten(List<ISpooler> spoolers) { List<ISpooler> flatList = new List<ISpooler>(); foreach (ISpooler spooler in spoolers) { flatList.Add(spooler); if (spooler is ISpoolableChunk) flatList.AddRange(RecurseAndFlatten(((ISpoolableChunk)spooler).Children)); } return flatList; }[/code] This works just fine. From the quick testing I've used of it, it seems to be capable of flattening the list pretty quickly. My only concern is that the entire list is being built, only to be forgotten about 0.2 seconds later. I'm not intuitive enough to think of a proper "caching" system for this that takes into consideration changes made to the collection. Is there a way to use LINQ for this? I tried to look up for stuff like "Nested LINQ", but I have conditionals to deal with, making it even more difficult to understand. I'd like to know if I'm approaching this correctly, because my OCD is killing me right now with the thought of it not being perfect. :v:
I need a lot of help fast. I've been programming for 10 years now (since I was 10) and I've taken a graphics programming course in uni. One of the prerequisite courses was an Objective C course, which I have not taken. I know java and I am decently knowledgeable when it comes to objective based programming, but: - The course is in C++ - It is not a programming course as in it does not teach you anything new with programming - Each weeks lab has a skeleton code provided giving us a frame and buffers set up to draw to, we just need to fill in the technical stuff - We are using visual studio 2010 to compile - I have flicked through a few C++ websites and source codes to get comfortable with the language, so I am confident I can learn enough to get through this course without failing The course covers writing a graphics engine from scratch, we are learning step by step, starting with week 1, drawing a line, to drawing triangles, to drawing polygons all the way up to shading and lighting. The teacher is very knowledgeable (and Japanese) so I am confident that he can help me with something I don't understand however he has put the other course as a prerequisite so that we do not get caught behind on the labs. What I need: I just need a good source to get quick tips for C++ from. [editline]12th March 2014[/editline] To clarify this course acknowledges the student has a basic understanding of C++ and teaches the logic behind a 3D graphics engine, but requires the student to code it. Flicking through the lecture notes it looks like they have provided a lot of the mathematics behind it we just need to understand it and program it ourselves. [editline]12th March 2014[/editline] Also there's some older students in my class I'll try to sit next to one of them so I can bother them for help.
[QUOTE=war_man333;44204307]Is there a faster way to add strings to a List<String> other than typing myList.Add("String"); 1 million times? I'm thinking something like myList.Add("String","String","String"); ... except that it only takes 1 argument ofcourse. This is C#.[/QUOTE] [QUOTE=SteveUK;44204545][url]http://www.dotnetperls.com/initialize-list[/url][/QUOTE] This works on anything that implements ICollection and has an [I]Add[/I] method iirc. It works for dictionaries too, you just have to enclose key value pairs in {}. [editline]12th March 2014[/editline] [QUOTE=CarLuver69;44210669][...] Is there a way to use LINQ for this? I tried to look up for stuff like "Nested LINQ", but I have conditionals to deal with, making it even more difficult to understand. I'd like to know if I'm approaching this correctly, because my OCD is killing me right now with the thought of it not being perfect. :v:[/QUOTE] Return an [I]IEnumerable<Spooler>[/I], then you can start with the first list [I].AsEnumerable()[/I] and [I].Concat()[/I] the others without making copies. If you need to preserve order, I think the easiest option are enumerables with [I]yield[/I], just [I]yield return[/I] each element. You need to evaluate the whole thing before changing the lists, or an exception will be thrown once you do. [editline]12th March 2014[/editline] [QUOTE=Pat.Lithium;44210727][...] What I need: I just need a good source to get quick tips for C++ from. [...][/QUOTE] Not exactly what you're looking for, but this might be helpful: [URL="http://stackoverflow.com/questions/75538/hidden-features-of-c"]Hidden Features of C++? [closed][/URL]
Currently working on an applet that should run in a browser. Uploaded it to the tomcat server and all. However when I start the applet I get this error. "NoClassDefFoundError - Could not initialize class org.postgresql.jdbc4.Jdbc4Statement" Basically it found the object Statement but could not load a class file. Now no idea what I can do to make it behave and connect to the database..
[QUOTE=diwako;44213014]Currently working on an applet that should run in a browser. Uploaded it to the tomcat server and all. However when I start the applet I get this error. "NoClassDefFoundError - Could not initialize class org.postgresql.jdbc4.Jdbc4Statement" Basically it found the object Statement but could not load a class file. Now no idea what I can do to make it behave and connect to the database..[/QUOTE] Have you made sure to add all the other JARs you want to load on to your classpath?
[QUOTE=Tamschi;44211989]Return an [I]IEnumerable<Spooler>[/I], then you can start with the first list [I].AsEnumerable()[/I] and [I].Concat()[/I] the others without making copies. If you need to preserve order, I think the easiest option are enumerables with [I]yield[/I], just [I]yield return[/I] each element. You need to evaluate the whole thing before changing the lists, or an exception will be thrown once you do.[/QUOTE] Thank you! I never use IEnumerable<T> so obviously I was unaware of such a thing.
[code]public void ToLowercaseNamingConvention(string s) { var r = new Regex(@" (?<=[A-Z])(?=[A-Z][a-z]) | (?<=[^A-Z])(?=[A-Z]) | (?<=[A-Za-z])(?=[^A-Za-z])", RegexOptions.IgnorePatternWhitespace); string lowerCased = r.Replace(s, " "); string[] splittet = lowerCased.Split(' '); foreach (string str in splittet) { try { SoundPlayer thisSound = new SoundPlayer(str + ".wav"); thisSound.Play(); } catch { sound.Play(); } Thread.Sleep(1000); } }[/code] I'm trying to get this to use special characters as it only works with A-Z & a-z... I want it to work with Danish letters - any ideas?
When doing a 2d game, how do you deal with changing resolutions? Is it best to just have the view get bigger/smaller, or code against a base resolution and then just resize the images/sprites to always be the required percentage of the screen size? (and if so would it be better to just use vector graphics and convert them to images in memory so they always have the best look)
I think most modern 2d games scale the graphics to the screen resolution, because it's unfair that people with smaller screens have a more limited view field. If it's a strategy game there can always be a zoom control if that works with your type of game
[QUOTE=djjkxbox360;44217211]I think most modern 2d games scale the graphics to the screen resolution, because it's unfair that people with smaller screens have a more limited view field. If it's a strategy game there can always be a zoom control if that works with your type of game[/QUOTE] Hmm, the anoying thing is keeping it looking good and not really streached
Well you can either use high resolution graphics or like you said is probably the best way
So this I've been wondering since I am VERY, VERY new to programming; I've heard that you should always start with making 2d games for practice and the like, but would it be really hard for a beginner like me to jump into 3d c++ programming? This being said is there any way to program 2d programs with c++, i've had limited luck finding something that works but again I'm awful with finding resources. Thanks in advance guys
[QUOTE=Causicus;44218917]So this I've been wondering since I am VERY, VERY new to programming; I've heard that you should always start with making 2d games for practice and the like, but would it be really hard for a beginner like me to jump into 3d c++ programming?[/QUOTE] Assuming VERY VERY NEW means not even hello worlding: 3D is a maybe if you really can get around the maths. C++? Hell no. I've been programming for 5 years and i still can't get around it entirely. "you should always start with making 2d games" This is very wrong. Just saying. For learning you should try making simpler stuff like calculators and simple utility software.
2D games are usually simpler because you can find higher level libraries for them (where as with 3D you're probably using opengl or directx) + the math is simpler. But yeah either way not a good place to start when learning how to program.
[QUOTE=war_man333;44215814][code]public void ToLowercaseNamingConvention(string s) { var r = new Regex(@" (?<=[A-Z])(?=[A-Z][a-z]) | (?<=[^A-Z])(?=[A-Z]) | (?<=[A-Za-z])(?=[^A-Za-z])", RegexOptions.IgnorePatternWhitespace); string lowerCased = r.Replace(s, " "); string[] splittet = lowerCased.Split(' '); foreach (string str in splittet) { try { SoundPlayer thisSound = new SoundPlayer(str + ".wav"); thisSound.Play(); } catch { sound.Play(); } Thread.Sleep(1000); } }[/code] I'm trying to get this to use special characters as it only works with A-Z & a-z... I want it to work with Danish letters - any ideas?[/QUOTE] Figured it out, just changed the 'algorithm' part to this [code] (?<=[A-Z+Æ+Ø+Å])(?=[A-Z^+Æ+Ø+Å][a-z+æ+ø+å]) | (?<=[^A-Z+Æ+Ø+Å])(?=[A-Z+Æ+Ø+Å]) | (?<=[A-Z+Æ+Ø+Åa-z+æ+ø+å])(?=[^A-Z+Æ+Ø+Åa-z+æ+ø+å])"[/code]
[QUOTE=war_man333;44221152]Figured it out, just changed the 'algorithm' part to this [code] (?<=[A-Z+Æ+Ø+Å])(?=[A-Z^+Æ+Ø+Å][a-z+æ+ø+å]) | (?<=[^A-Z+Æ+Ø+Å])(?=[A-Z+Æ+Ø+Å]) | (?<=[A-Z+Æ+Ø+Åa-z+æ+ø+å])(?=[^A-Z+Æ+Ø+Åa-z+æ+ø+å])"[/code][/QUOTE] That matches + too, just append the letters/ranges without any operator.
[QUOTE=Tamschi;44221779]That matches + too, just append the letters/ranges without any operator.[/QUOTE] Sure does. Thanks. What's the ?<= mean exactly?
[QUOTE=war_man333;44221867]Sure does. Thanks. What's the ?<= mean exactly?[/QUOTE] It's a positive lookbehind, it matches text outside of the resulting match. [URL="http://www.regular-expressions.info/lookaround.html"]There are some slight caveats with groups.[/URL] (This site explains everything you need to know about regex and also the differences between implementations.)
[QUOTE=bootv2;44223404][...] tl;dr I changed to radials and would like to know how to recalculate the directional vector[/QUOTE] Not a good idea, since your system models collisions which work far better in cartesian coords. You can find that with (cos(&#966;), sin(&#966;)) * v, but if you just want to fix the speed at a certain value it's easier to renormalise it after each collision (or to keep the direction as normal vector instead of an angle). You can get back to radial coords using atan2, but I don't think you can do the collision in that system easily.
Well. It's time. I'm going in tomorrow morning for a job interview as a Java developer for a financial company. Any tips? It's a junior Java dev position.
Thank you guys very much for the replies, I think for now i'll start off with lua and work my way up.
Sorry, you need to Log In to post a reply to this thread.