• What Do You Need Help With? V6
    7,544 replies, posted
[QUOTE=proboardslol;46153172]comment your code d00d [editline]4th October 2014[/editline] Am I the only one who has an innate distrust of business types? Like when they say they'll give you a job just for knowing them, I fear it always turns out that they work for vector marketing or some shit edit: read Barney Toasterstrudel[/QUOTE] I commented the shit out of it, and improved the functionality, I'll post it tomorrow because I'm in bed now!
[QUOTE=NixNax123;46148701]Does anyone have any small projects that I can work on in Java that are simple to do, but just good programming practice and experience?[/QUOTE] [url]https://www.reddit.com/r/dailyprogrammer[/url]
Someone worked with EasyHook before? My injected DLL somehow does not get ejected, it stays in the Process. Already looked at their codeplex site, but did not find any answers yet. Is there any way to properly remove the injected DLL from the process?
I'm looking at an introductory programming class that uses Python. One of the tasks is writing a stopwatch. I'm having trouble with the function that formats time into a string. The string must have this format: A:BC:D where A is minutes, BC is seconds and D is tenths of seconds. I'm having trouble with it once the timer hits 1 minute. I can't find a way to reset the tens/seconds/tenths back to 00.0 and then keep counting from scratch and I dunno how else to do it. Maths has never been my strong suit. Here is what I have: [code]def format(t): timelist = [0, 0, 0, 0] if t < 10: timelist[3] = str(t)[-1] elif t >= 10 and t < 100: timelist[3] = str(t)[-1] timelist[2] = str(t)[-2] elif t >= 100 and t < 600: timelist[3] = str(t)[-1] timelist[2] = str(t)[-2] timelist[1] = str(t)[-3] elif t % 60 == 0: timelist[0] += 1 timeText = str(timelist[0]) + ':' + str(timelist[1]) + str(timelist[2]) + '.' + str(timelist[3]) return timeText[/code] I'm not supposed to import other modules here other than the one we use for the GUI+timer. I've been googling to no avail, I'm pretty sure I'm just being retarded with numbers. But my head is starting to hurt so if someone can give me some pointers I'd appreciate it.
[QUOTE=Duskling;46148857]You could make a program to convert a .jpg to a .png or something along those lines. Or import a .png and change it to black and white. It seems complicated, but once you have the file input correct, you just have to learn the specifications of the file format and create your own parser/lexer. Should be relatively simple and fun with the proper documentation.[/QUOTE] Ok, so I've started out making an Image class (seemed the most logical thing to do) [code]public class Image { /** * filename for image */ public String filename; /** * image extension */ public String ext; /** * width of image */ public int width; /** * height of image */ public int height; /** * various image effects */ public enum Effect { /* * no effect */ NO_EFFECT, /* * black & white effect */ NOIR } /** * image effect */ public Effect effect; /** * loads and displays an image with desired effect * @param filename filename of image to be loaded * @param ext extension of image to be loaded * @param width width of image to be displayed * @param height height of image to be displayed * @param effect effect of image to be displayed */ public Image( String filename, String ext, int width, int height, Effect effect) { this.filename = filename; this.ext = ext; this.width = width; this.height = height; this.effect = effect; // not implemented yet // this.display(); } [/code] But I really don't know how to set up classes in a way that makes sense. I've never been taught, and never had a good resource. So what should I do from here? Is my class alright so far? Can anyone give me an example skeleton of my class to help me out?
[QUOTE=NixNax123;46157265]Ok, so I've started out making an Image class (seemed the most logical thing to do) [code]public class Image { /** * filename for image */ public String filename; /** * image extension */ public String ext; // image width /** * width of image */ public int width; // image height /** * height of image */ public int height; /** * various image effects */ public enum Effect { /* * no effect */ NO_EFFECT, /* * black & white effect */ NOIR } /** * image effect */ public Effect effect; /** * loads and displays an image with desired effect * @param filename filename of image to be loaded * @param ext extension of image to be loaded * @param width width of image to be displayed * @param height height of image to be displayed * @param effect effect of image to be displayed */ public Image( String filename, String ext, int width, int height, Effect effect) { this.filename = filename; this.ext = ext; this.width = width; this.height = height; this.effect = effect; // not implemented yet // this.display(); } [/code] But I really don't know how to set up classes in a way that makes sense. I've never been taught, and never had a good resource. So what should I do from here? Is my class alright so far? Can anyone give me an example skeleton of my class to help me out?[/QUOTE] Everything seems alright. The file extension should be it's own class. You would have a Type ( or something ) base class and then like a PNG class or TGA class, each with their own specifications built right into the class so that you can write importers based of of those classes.
[QUOTE=Duskling;46157882]Everything seems alright. The file extension should be it's own class. You would have a Type ( or something ) base class and then like a PNG class or TGA class, each with their own specifications built right into the class so that you can write importers based of of those classes.[/QUOTE] That makes sense, thank you! I'll report on my progress! [editline]5th October 2014[/editline] [QUOTE=Duskling;46157882]Everything seems alright. The file extension should be it's own class. You would have a Type ( or something ) base class and then like a PNG class or TGA class, each with their own specifications built right into the class so that you can write importers based of of those classes.[/QUOTE] So I'm making a Format class, and the PNG/TGA/etc classes will be subclasses of that. What methods/fields should I give to Format? I'm not quite sure.
[QUOTE=meek;46156340]I'm looking at an introductory programming class that uses Python. One of the tasks is writing a stopwatch. I'm having trouble with the function that formats time into a string. The string must have this format: A:BC:D where A is minutes, BC is seconds and D is tenths of seconds. I'm having trouble with it once the timer hits 1 minute. I can't find a way to reset the tens/seconds/tenths back to 00.0 and then keep counting from scratch and I dunno how else to do it. Maths has never been my strong suit. Here is what I have: [code] I'm not supposed to import other modules here other than the one we use for the GUI+timer. I've been googling to no avail, I'm pretty sure I'm just being retarded with numbers. But my head is starting to hurt so if someone can give me some pointers I'd appreciate it.[/QUOTE] There are two things you can do here to make your life easier. The first is to do with converting from seconds to minutes/seconds/tenths-of-seconds, the easy way to do this is to use the modulo operator and divide and round down, in Python the modulo operator is % and although you've used it at the bottom the else-if chain won't reach it until t is greater then 600, and even then if t is a floating point t % 60 will probably never be 0. The modulo operator gives you the remained when you divide by something so: [code]65 % 60 = 5[/code] As a minute is 60 seconds you can use this to determine how many seconds you have left over after you have your minutes. To get your minutes you can use // which, in Python, divides and rounds down so [code] 65 // 60 = 1[/code] Or if you have less than a minute [code] 55 // 60 = 0[/code] So using these you can turn a number of seconds into minutes, seconds and tenths of seconds. The next is formatting the numbers as a string. Rather than keeping track of the tens and seconds and single digits of seconds separately, the above will give you a two digit number, if you were to just use str() on it you wouldn't always get two digits e.g [code]str(5) = '5'[/code] Python includes some string formatting capabilities that can help you get around this. The simple way is to create a format string that acts as a template and then fill it in with your values, this makes use of % again, but this time in relation to strings rather than numbers so the effect is different. If you just had minutes and seconds you could do "%d:%d", here the %d will eventually be replaced with something, the 'd' means it will be a number and in particular an integer number. To actually do the replacement you would do [code] "%d:%d" % (5,6) = '5:6'[/code] Note: you need to put the things you're putting into the string in brackets if you have more than one item and they're placed in the string in the order they're given. The in order to force the seconds to be two digits you can do "%d:%02d", when replacing this will give: [code]"%d:%02d" % (5,6) = '5:06'[/code] Where the 02 before the d specifies that the number should always be a minimum of two digits (so you could still put 500 into the %02d just fine). This ended up being quite a long post but it should give you everything you need, and while I've only talked about minutes and seconds extending it to m:ss:t shouldn't be too difficult.
I am making a chat application for Windows Desktop (C#), Android (Java) and Browser. What would be the best way to make sure that in all 3 clients user sends and receives messages instantly? I mean is there ONE service that could provide this all? So far I found GCM (Google Cloud Messaging) and WebSockets, however it seems that GCM is same as WebSockets except it's all automated (I think). I mean I could call refresh in all clients every second but that seems like a huge resource waste. Browsr could use Ajax I guess to get newest chat messages. Android could use GCM. But what can Windows use? I've never really properly made Windows software. Any suggestions? Thanks.
[QUOTE=NixNax123;46157896] So I'm making a Format class, and the PNG/TGA/etc classes will be subclasses of that. What methods/fields should I give to Format? I'm not quite sure.[/QUOTE] I'm unsure, never really dealt with file header specifications. You would probably have variables that hold the difference, in bytes, between each part of the file header, as well as ways to store the header format.
I've been messing around with Sublime Text 3 plugins ( my first time using Python ) and I can't seem to figure out what the args argument wants. I've tried using a mapping, which seems to be what it wants, but it gives me this error: [code] >>> view.run_command( 'example', { 'one': 1 } ) Traceback (most recent call last): File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 543, in run_ return self.run(edit, **args) TypeError: run() got an unexpected keyword argument 'one' [/code] Any suggestions?
[QUOTE=HumbleTH;46164995]I've been messing around with Sublime Text 3 plugins ( my first time using Python ) and I can't seem to figure out what the args argument wants. I've tried using a mapping, which seems to be what it wants, but it gives me this error: [code] >>> view.run_command( 'example', { 'one': 1 } ) Traceback (most recent call last): File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 543, in run_ return self.run(edit, **args) TypeError: run() got an unexpected keyword argument 'one' [/code] Any suggestions?[/QUOTE] it means your method definition 'run' doesn't accept keyword arguments.
[QUOTE=vexx21322;46165108]it means your method definition 'run' doesn't accept keyword arguments.[/QUOTE] Thanks! After some searching, I found out I needed ** before the argument.
So I'm looking at the BMP file header format ([url]http://www.fastgraph.com/help/bmp_header_format.html[/url]), and I have a few questions. For the first part, the 4D42 hex, how would I interpret that? Would I just have [code]byte signature = 0x4D42;[/code] ? Also, I'm a bit confused on the whole thing in general. I completely understand bits and bytes (8 bits in a byte etc) but would the file have those bytes in binary? And if an offset is size 2 but must be 0, would that place in the file be 0000000000000000?
[QUOTE=NixNax123;46165386] For the first part, the 4D42 hex, how would I interpret that? Would I just have [code]byte signature = 0x4D42;[/code] ? [/quote] Yes, except that's two bytes. [quote] Also, I'm a bit confused on the whole thing in general. I completely understand bits and bytes (8 bits in a byte etc) but would the file have those bytes in binary? And if an offset is size 2 but must be 0, would that place in the file be 0000000000000000?[/QUOTE] The offset is the field position. The first field, the magic number 4D 42, is right at the start of the file, so at offset 0, and it has a size of 2 bytes. The field after that is, of course, at offset 2, so 2 bytes after the start of the file. And that happens to have a size of 4 bytes. So the next field is at offset 6, and so on. You might wanna take a BMP file and look at it in a hex editor.
-snip- got it working.
[QUOTE=DrTaxi;46165622]Yes, except that's two bytes. The offset is the field position. The first field, the magic number 4D 42, is right at the start of the file, so at offset 0, and it has a size of 2 bytes. The field after that is, of course, at offset 2, so 2 bytes after the start of the file. And that happens to have a size of 4 bytes. So the next field is at offset 6, and so on. You might wanna take a BMP file and look at it in a hex editor.[/QUOTE] So I would have [code]byte s1 = 0x4D; byte s2 = 0x42; [/code] right? And I'll do that! That should help out a lot. [editline]6th October 2014[/editline] Aha! This REALLY helps! [editline]6th October 2014[/editline] Now that I understand how file formats work, I still need some help on creating classes and subclasses. This is my Format class so far: [code]public class Format { public byte[][] header; public byte[] signature; public byte[] offsets; } [/code] with subclass BMP [code]public class BMP extends Format { } [/code] It's probably terrible, but I [B]really[/B] don't know how to create classes to do what needs to be done, because I don't understand what needs to be done, or what needs to go in these classes, or what methods these classes need.
That seems like a good design to me. You're avoiding the [url=http://en.wikipedia.org/wiki/God_object]God object pattern[/url] by splitting up your code into separate classes, which is good. I would recommend that you add some abstract methods in your format classes that actually [i]handle[/i] the saving and loading part of the format. [url=http://docs.oracle.com/javase/tutorial/java/IandI/abstract.html]Abstract methods[/url] are basically methods that you can define in one class, and thus any classes that extend from that class will have to provide an implementation of it.
Seems good to me too, but: [QUOTE=NixNax123;46165890] public byte[] offsets; [/QUOTE] What's the offsets array for?
[QUOTE=Contron;46166604]That seems like a good design to me. You're avoiding the [url=http://en.wikipedia.org/wiki/God_object]God object pattern[/url] by splitting up your code into separate classes, which is good. I would recommend that you add some abstract methods in your format classes that actually [i]handle[/i] the saving and loading part of the format. [url=http://docs.oracle.com/javase/tutorial/java/IandI/abstract.html]Abstract methods[/url] are basically methods that you can define in one class, and thus any classes that extend from that class will have to provide an implementation of it.[/QUOTE] Thank you! It's encouraging knowing that I at least got some stuff right. I was thinking about that, and how it does make a lot of sense, but I wasn't sure how to implement it. Thank you! Also, what do you mean "handle the saving/loading part"? I'm not quite sure what to do with it, I know in the end I want to output the image to a Swing GUI and have an option to save a file/load a file/export a file, but I will need to flesh out all of my formats before I even think about that. [editline]6th October 2014[/editline] [QUOTE=DrTaxi;46166626]Seems good to me too, but: What's the offsets array for?[/QUOTE] To determine the offsets between each section of the format. I wasn't really sure to put in that class, so I just put whatever came to mind.
[QUOTE=LilDood;46158756][super helpful and nice post][/QUOTE] Thank you so much for your reply! It helped me organise things a bit differently. Here is what I have now for the format() function: [code] def format(t): global minutes, seconds, tenths tenths = t % 10 seconds = t // 10 minutes = t // 600 timeText = '%d:%02d.%d' % ( minutes, seconds, tenths) return timeText [/code] Which is MUCH MUCH nicer than what I had lol I forgot to mention t is in tenths of a second, so this function is called every 0.1 seconds. This whole thing is a lot clearer to me now but I am still having trouble "resetting" the seconds back to start counting from 0 again once it ticks past a minute. So essentially 68.3 seconds looks like 1:68.3 instead of 1:13.8 which is what I need it to do. Simply assigning seconds a different value if it's higher than 59 like such: [code] if seconds > 59: seconds = 0 [/code] doesn't seem to work, probably because the function reassigns seconds to t // 10 every time it is called or something? (This is all still magic to me) If you or someone else can help me figure out a way to do this I would be so grateful.
[QUOTE=NixNax123;46166636]Thank you! It's encouraging knowing that I at least got some stuff right. I was thinking about that, and how it does make a lot of sense, but I wasn't sure how to implement it. Thank you! Also, what do you mean "handle the saving/loading part"? I'm not quite sure what to do with it, I know in the end I want to output the image to a Swing GUI and have an option to save a file/load a file/export a file, but I will need to flesh out all of my formats before I even think about that.[/QUOTE] By handling the loading and saving part, I mean that in each format that you add support for (for instance, your BMP class), you can add the relative code needed to loading and saving bitmap files into that class itself, and transform it into RGB or pixel data that your application can handle - independent of whatever format it was procured from. It's a much better way of doing this rather than having, say, a class with a large switch statement which handles loading and saving image files on the specific format. [editline]6th October 2014[/editline] Here's an example for your base Format class: [code] public abstract class Format { /** * Loads an image from this format. */ public abstract void load(); /** * Saves an image in this format. */ public abstract void save(); } [/code] So, if you were to implement Bitmap support (like you've done), you'd simply override these methods: [code] public class Bitmap extends Format { /** * Loads a Bitmap image. */ public void load() { ... } /** * Saves a Bitmap image. */ public void save() { ... } } [/code]
I understand! Thank you! Now I just need to know how to load the data from a bitmap into an array of bytes and convert those bytes to rgb values, and THEN convert those rgb values into an image that I can display. I'm having a work overload.
Is that a question, or are you gonna figure that out yourself?
[QUOTE=DrTaxi;46167259]Is that a question, or are you gonna figure that out yourself?[/QUOTE] I think I could figure out how to load the file info in the byte array, but I'm not sure how to store that info as rgb values and convert that to an image to draw.
[QUOTE=meek;46166960]Thank you so much for your reply! It helped me organise things a bit differently. Here is what I have now for the format() function: [code] def format(t): global minutes, seconds, tenths tenths = t % 10 seconds = t // 10 minutes = t // 600 timeText = '%d:%02d.%d' % ( minutes, seconds, tenths) return timeText [/code] Which is MUCH MUCH nicer than what I had lol I forgot to mention t is in tenths of a second, so this function is called every 0.1 seconds. This whole thing is a lot clearer to me now but I am still having trouble "resetting" the seconds back to start counting from 0 again once it ticks past a minute. So essentially 68.3 seconds looks like 1:68.3 instead of 1:13.8 which is what I need it to do. Simply assigning seconds a different value if it's higher than 59 like such: [code] if seconds > 59: seconds = 0 [/code] doesn't seem to work, probably because the function reassigns seconds to t // 10 every time it is called or something? (This is all still magic to me) If you or someone else can help me figure out a way to do this I would be so grateful.[/QUOTE] Every time the function is called the code in the function is run in order from top to bottom, so seconds is et to t // 10. If you were to put the if section in after seconds has been set like this: [code] def format(t): global minutes, seconds, tenths tenths = t % 10 seconds = t // 10 if seconds > 59: seconds = 0 minutes = t // 600 timeText = '%d:%02d.%d' % ( minutes, seconds, tenths) return timeText [/code] Then seconds would be set to zero if it was greater than 59. But that's not really how you want to do it. When you talk about resetting back to zero, this is what you've already done for the tenths using % 10. When you to seconds = t // 10 you are converting from tenths of seconds to seconds. What you need to do next if remove the excess that you don't need which is what your are doing with the tenths already. For example 11 tenths is 1.1 seconds but you only need the .1 in the tenths and when you do 11 % 10 you get that 1. You're going to need to use both // and % on the same line in the seconds calculation and you may need to use brackets to make sure things happen in the right order.
[QUOTE=KinderBueno;46163636]I am making a chat application for Windows Desktop (C#), Android (Java) and Browser. What would be the best way to make sure that in all 3 clients user sends and receives messages instantly? I mean is there ONE service that could provide this all? So far I found GCM (Google Cloud Messaging) and WebSockets, however it seems that GCM is same as WebSockets except it's all automated (I think). I mean I could call refresh in all clients every second but that seems like a huge resource waste. Browsr could use Ajax I guess to get newest chat messages. Android could use GCM. But what can Windows use? I've never really properly made Windows software. Any suggestions? Thanks.[/QUOTE] Anyone please help?
[QUOTE=KinderBueno;46167906]Anyone please help?[/QUOTE] For something like that you'd be best off rolling your own server and just using that to send and receive messages.
[QUOTE=Contron;46167975]For something like that you'd be best off rolling your own server and just using that to send and receive messages.[/QUOTE] My upload speed is only 10.32 Mbps, that would be mad slow wouldn't it?
So this is my Image constructor so far: [code] public Image( String filename, String ext, int width, int height, Effect effect) { this.filename = filename; this.width = width; this.height = height; this.effect = effect; ext = ext.toLowerCase(); switch(ext) { case "bmp": case "bitmap": // load the bitmap file break; } }[/code] How would I load that bitmap file, if class Bitmap is a subclass of class Format, and has a method load()?
Sorry, you need to Log In to post a reply to this thread.