Jump to content

Aeternus

Senior Members
  • Posts

    349
  • Joined

  • Last visited

Everything posted by Aeternus

  1. So what would you say are some of the advantages of Ruby as a language, of Rails as a framework? and then what would you say some of the disadvantages are? What did you use before these two and how much of a difference has it made to your development?
  2. That's what I suggested but rather than having an array of numbers, I just kept an array of the labels and swapped their text/values around
  3. Why not just shove the numbers 1 to 9 in an array and then rearrange that array to randomise the numbers in it and then set each label to it's corresponding array element. Or, you could just set them to defaults to begin with and then randomise the labels in the form or store references to those labels in an array and randomise them by swapping values around in a particular way. There are plenty of good ways/algorithms to randomise sets of numbers or other data reasonably well, although if you need them randomise in such a way as to maintain certain rules about placement and sums of rows etc then you'd have to do a little more work. This would avoid the need for lots of ifs and checks as you can only rearrange the numbers that are already there and so you aren't introducing new numbers that you have to check against all the time. [ Edit ] Something along the lines of this (I had to do in in VB.Net as I don't have anything other than VS 2005 on my windows box and I don't use it alot especially not for VB, so I don't know if/whether I can use normal old school VB6 on there, you can probably get the general idea though) - Public Class Form1 Private arrayOfLabels(9) As Label Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load arrayOfLabels(0) = Label1 arrayOfLabels(1) = Label2 arrayOfLabels(2) = Label3 arrayOfLabels(3) = Label4 arrayOfLabels(4) = Label5 arrayOfLabels(5) = Label6 arrayOfLabels(6) = Label7 arrayOfLabels(7) = Label8 arrayOfLabels(8) = Label9 End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim randGen As New Random() Dim i As Integer, swapA As Integer, swapB As Integer For i = 1 To 100 swapA = randGen.Next(9) swapB = randGen.Next(9) swap(swapA, swapB) Next End Sub Private Sub swap(ByVal swapA As Integer, ByVal swapB As Integer) Dim strTemp As String strTemp = arrayOfLabels(swapA).Text arrayOfLabels(swapA).Text = arrayOfLabels(swapB).Text arrayOfLabels(swapB).Text = strTemp End Sub End Class The way it uses the Random class/object isn't ideal as it should really be passing a better seed into it (it just uses the current time in microseconds or something atm I think which doesn't always work out if you are generating alot of numbers very quickly as the time might not have moved over or the seeds will be very close together etc) but I'm sure the Randomise code in VB6 that 5614 provided would be more use and could be dropped in. The way in which it uses the random numbers to rearrange the values as well could certainly be improved as doing a reasonably large amount of random swaps probably isn't the best way but you get the general idea.
  4. http://java.sun.com/developer/technicalArticles/Programming/serialization/ and http://java.sun.com/j2se/1.5.0/docs/api/java/io/Serializable.html Should give you some idea. The basic idea is that you can save the state of the object as a byte stream by "serializing" it, that can be saved to a file, or sent over a network and then you can then "deserialize" it later on or at the other end. Java does most of this automatically but there are some complications, and so to show that your class/object should be able to do this (ie you have checked that there aren't any problems*) you implement the Serializable interface, which doesn't actually include any methods for you to implement, it just acts as a check that the object is ok to be serialized. * Some things like network connections or file connectors might not make sense to be serialized as part of the serialized object being saved to file or sent over a network or a variety of other things. So you can provide certain methods with your class that can be called instead of the default Java serialization stuff so you can do certain things when the object is serialized or deserialized and reset certain variables to sane defaults or new values (these are discussed in the links above) and certain fields can be set to "transient" so that their values/state won't be saved when you serialise the object. My explanation might be a bit dodgy and perhaps a little wrong/broken in some places but the links above should provide more info.
  5. Well no... it is - long long not long long . As you used System.out.println() not System.out.print() so there is a new line after each word. Secondly, the reason it doesn't print - int long is because I commented out the method that takes int, so that method doesn't exist to print int, so since the range of values for short is a subset of those for long, it matches to that method first over the new feature that matches up to encapsulating classes (as I said, I'd imagine this is for backwards compatibility). If the code had been - public class Test{ public static void go(Long n){System.out.println("Long ");} public static void go(Short n){System.out.println("Short ");} public static void go(int n){System.out.println("int ");} public static void go (long n){System.out.println("long ");} public static void main(String[] ardg){ short y =6; long z =7; go(y); go(z); } } Then it would print int long as it will match to the closest range to itself, which is best as otherwise methods may for instance return short or long if they take those types, and may do different calculations to handle larger numbers and may return something entirely different or in a range that might not be castable to short later on etc. IE if you have a method that takes short then if you pass a short to a method of that name, then it should use the method that takes short rather than using one of the other compatible integer types because you obviously declared another method which takes short for a reason. For instance, as you probably guessed, if I added another method taking short as well, it would then be - short long
  6. I'm guessing you are talking about - The Art of Computer Programming by Donald Knuth (a very famous Mathematician/Computer Scientist) You should be able to find it pretty much anywhere by just searching for "The Art of Computer Programming", there are several volumes to it I think, it's certainly a well known book.
  7. A more illustrative example for (1) - import java.io.*; class Food { public String booga = "booga"; Food() {System.out.print("1");} } class Fruit extends Food implements Serializable { Fruit(){System.out.print("2");} } public class Banana2 extends Fruit { int size = 42; Banana2() { }; public static void main(String[] af){ Banana2 b = new Banana2(); b.booga = "cheese"; try{ ObjectOutputStream oob = new ObjectOutputStream(new FileOutputStream("bla.txt")); oob.writeObject(b); oob.close(); ObjectInputStream oib = new ObjectInputStream(new FileInputStream("bla.txt")); Banana2 b1 = (Banana2) oib.readObject(); oib.close(); System.out.println(" restored "+b.size+" "+b1.booga); } catch(Exception e){System.out.println(e);} } } gives - 121 restored 42 booga NOT 121 restored 42 cheese Because the fields inherited from Food (which doesn't implement serializable, are not serialized and when they are created from readObject, they gain their default value and the constructor's of the parents further up the tree are run, allowing these fields to be initialised again to sane values (especially useful if you inherit from things involving files or network connections which can't easily be serialised.
  8. 1) I think this is because, it can't technically serialise the parts of the object belonging to the super class Food (even though it can serialise the fields, the constructor Food() might have to set certain things up that aren't carried over and are needed for Fruit, Banana2 etc to work once deserialized), therefore it must call the Food constructor to setup anything that wasn't serialized and so on inherited from Food. You'll notice that the problem goes away when you do - class Food implements Serializable { Food() {System.out.print("1");} } class Fruit extends Food { Fruit(){System.out.print("2");} } public class Banana2 extends Fruit { int size = 42; public static void main(String[] af){ Banana2 b = new Banana2(); try{ ObjectOutputStream oob = new ObjectOutputStream(new FileOutputStream("bla.txt")); oob.writeObject(b); oob.close(); ObjectInputStream oib = new ObjectInputStream(new FileInputStream("bla.txt")); Banana2 b1 = (Banana2) oib.readObject(); oib.close(); System.out.println(" restored "+b.size+" ");} catch(Exception e){System.out.println(e);} } } 2) The only exception I can see that could be thrown there is InterruptedException, although the TimeoutException would be nice considering as far as I can see notify will never be called and it'll get stuck like that (unless there are other threads elsewhere in the code calling notify(). 3) somestatement;; is just - somestatement; {anemptystatement}; Ie, just imagine there were actually a command/statement inbetween the two, but it didn't actually do anything, that is what that is. You can add as many extra ;'s as you want, each one just finishes an empty statement.
  9. Oops, sorry, I didn't realise that you were using Java 1.5 and that it automatically realised that a particular class was an encapsulation of one of it's primitive types. In that case, I think this is merely because of the fact that the range of short is contained within int (ie the set of numbers in short is a subset of those in int), and so I'd imagine it chooses to match to a method that uses a similar primitive type rather than to a class. You'll note that you can do - int x = (short)4; and you won't recieve any warnings or errors because this is acceptable and there is no loss of precision etc. You'll also note that if you change it to - public class Test{ public static void go(Long n){System.out.println("Long ");} public static void go(Short n){System.out.println("Short ");} //public static void go(int n){System.out.println("int ");} public static void go (long n){System.out.println("long ");} public static void main(String[] ardg){ short y =6; long z =7; go(y); go(z); } } It will print - long long Since both short and long fit in the long primitive type and it seems to priotise these above the encapsulating classes when matching a method definition to the parameter types (this is probably to try and maintain backward compatibility with the way that things worked before you could do this, so that if someone had a class similar to yours, but wasn't expecting Long or Short to match since it wouldn't have pre 1.5 (or whenever this came in), it will still match to the method taking int, as they would have expected).
  10. http://java.sun.com/j2se/1.4.2/docs/guide/lang/assert.html#usage-conditions It explains here why. It sounds like it's because with a public method, it will go on to be used by another class or even another coder and will be used alot more outside of the general scope of this class. Asserts are generally not run at runtime (afaik) and you have to specify during runtime that you want them enabled. This is great for debugging but when you have finished, you will still need your public methods to check the validity of parameters passed in, even outside of debugging, because another class or even another coder might pass in a value that is unacceptable, whereas the private and protected methods are only being passed parameters from within the same class or at least a very limited scope, and so you can control the parameters that they are passed and the assertions that their arguments are valid should hold true, as long as you check to make sure that anything that might change this from outside (ie when arguments/parameters are passed to a public method) are valid.
  11. 1) http://forum.java.sun.com/thread.jspa?threadID=624912&messageID=3559863 It is basically because they are meant for entirely different circumstances. You'll notice that compare (from Comparator - 2 params) and compareTo (from Comparable - 1 param) take different numbers of parameters. compareTo is meant for when you have an object that you will be passing around and that object will need to be compared to other objects later on (for instance in a sortable collection). One object can then be compared to another by simply doing object1.compareTo(object2). Comparator and compare() are meant (afaik, I haven't used it, only Comparable) for situations where a class/object (usually not the one you are implementing Comparator in/on) needs the ability to compare two objects (ie not compare itself to something else), possibly in a way/ordering that isn't the same as they would normally order themselves using Comparable. 2) and 3) are to do with a new feature in Java 1.5 called Generics. This allows you to use generic types/classes rather than specifying exactly that class/type a method will take as a parameter or will return or will use to store something inside etc. The class it will actually use can be inferred from the use of it later on in the code. In the case of ArrayList and other collections (although it can be used in more than Collections), you pass the class that will be used as the "base" class for that collection when you create the ArrayList object. It then stores for instance String (as you passed that in) or any subclass of string, rather than storing Object or any subclass of object as it normally does. This is beneficial in a couple of ways. First of all, it means that a compiler error can be generated if you pass in something of the wrong type into the ArrayList because it knows what type of objects the ArrayList is meant to store. For instance in (3), you tried to pass an Object into something that was meant to store String s and so it gave you an error as Object is not a subclass of String. Even though you are storing this ArrayList as a Collection which may use a different class as it's generic type, I'm pretty sure you are still confined by the original type used in ArrayList. Secondly, you benefit from not having to typecast things all the time. Normally when you got something out of the ArrayList, you'd have to typecast it to String as get() for instance would return an Object, not a String. Now because the class that the ArrayList stores has been defined, rather than returning Object, it will return String, and so assuming you only want to deal with String (ie you haven't passed in some subclass of String and need to typecast it to that) you don't need to type cast it anymore. There are other benefits to this and you can read more about this at - http://java.sun.com/j2se/1.5.0/docs/guide/language/generics.html http://java.sun.com/developer/technicalArticles/J2SE/generics/ Obviously, I used the example of extending String here, but you couldn't actually do this as String is declared final but you get the idea with other classes/types. As far as I know, Generics are the same concept as C++ Templates although I haven't used either yet, only read about them (never needed them yet). I haven't really used this much myself yet so I may have got some things wrong. Please correct me if I've made an error somewhere.
  12. Remember that Java is case sensitive. Long and Short are classes that encapsulate each of the primitive types they are named after and allows you to use them anywhere that an object is taken as a parameter or when you need to use some of the methods of those classes - http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Long.html http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Short.html For your code to work correctly, you need to remember that Java is case sensitive and use the correct types - long and short, rather than the additional classes available to use them with. public class Test{ public static void go(long n) { System.out.println("Long "); } public static void go(short n) { System.out.println("Short "); } public static void go(int n) { System.out.println("int "); } public static void main(String[] ardg){ short y =6; long z =7; go(y); go(z); } } should work.
  13. Sorry if I came on a little strong without much explanation, it was a little silly. First of all, I'm only talking about VB not VB.Net, I've had no experience at all with VB .Net and so simply can't comment on it. While my experience with VB in general isn't huge, there are quite a few things that I dislike about it - 1) Case Insensitivity This is done in other languages as well, but in general if you are looking at a teaching language, I feel that one that forces you to code with case sensitivity in mind will help in the long run. A lot of languages are case sensitive and for a reason and there are alot of standards on how things should be correctly named and things can end up in a mess when you realise for the 10th time that you've forgotten that something was meant to be capitalised etc because you aren't used to having to deal with this. 2) Visual Studio badness (at least as a teaching tool) While this isn't VB's fault and VB doesn't have to be taught in Visual Studio, it very often is, and teaching people with point and click programming, in my opinion just leads to disaster, with them simply not understanding what is going on underneath. Some people view this as a good thing, as it might allow people who haven't programmed before to get stuck in more easily but I think there are alot of other, just as accessible languages and tools out there that don't coddle people. 3) The way OOP works in VB just isn't good and I don't think it's a good way to learn this You can see here - http://www.informit.com/articles/article.asp?p=18230&seqNum=3&rl=1 - some of the features of Object Oriented Programming that VB left out, some of which seem to me to be pretty much pillars of modern OOP and yet VB doesn't offer them and so to do the same thing a beginner would have to implement work arounds and write unnecessary code which can have a bad impact. That's all I could really think of straight away, it's been quite a while since I've really done anything with VB so if I think of anything else I'll mention it. I'm sure some other users who have voiced a mistrust/dislike of the language in the past could provide quite a few more. Alot of the other things that I dislike about it are mostly syntax issues (such as the fact you have to specify when you want things to go across multiple lines with &_ etc and the fact that alot of keywords don't seem to be very descriptive in terms of what they do) but these don't necessarily affect teaching. There are several more things listed here although not all of them affect it's use as a teaching language, some do though - http://visualbasic.about.com/od/imhoinmyhumbleopinion/a/aaVerityStob1.htm I obviously didn't write this so I can't really vouch for it. I suppose some things would depend on who the target audience were for teaching. For instance, if it was being used to teach people who would go onto program then there are lots of arguments out there online about whether comp sci/software eng students should be taught lower level languages or high and what fundamentals the language should expose. If a person is simply learning a language as a hobby for basic DIY programming, then some things might not matter so much. I could be wrong on some of these notes here, they could have changed or I could simply be misinformed. If so, fair enough, please correct me. I'm not trying to attack anyone who codes in VB or learnt VB as a starting language. I'm sure whatever language one starts in they can do well, I just don't think VB does a good job of helping in this respect. I'm sure alot of my dislike for VB comes from irrational feelings built up to the way in which I have seen it taught in school and college to pupils, as some form of easy way out without really learning the fundamentals. No language is perfect and I'm certainly not saying Visual Basic doesn't have it's place but I just don't think it is a very good choice for a teaching language. Sorry if any of this doesn't make sense or sounds like rambling or similar, it is rather late here and well meh I'm sure someone will add to this or correct me / beat me with a clue stick in the morning
  14. You still aren't taking into account the fact that the numbers must be opposite each other. Given that you are taking away the possibility of those opposite numbers, you have the 30 die you mention but you must divide that by 15 giving you two. The basic idea here is that you end up always having a vertex on the cube with 1, 2 and 3 meeting and the only option left to you is whether or not the numbers go around that vertex clockwise or anticlockwise as all the other ways of changing the numbers are just rotations of one of the others. You can also think of it like this. Normally, as you said, you would do 6 x 5 x 4 x 3 x 2 x 1, but then as hgupta said, you would need to do 6 x 4 x 2 in this case as the first number's choice removes the 5 possibilities for the second, then the thirds removes the 3 for the 4th (as they HAVE to be opposite). This would leave us with 720/15 = 48 as hgupta said. However, with the rotations, as you said the number has to be divided by 24, so 48/24 = 2. I could be wrong, I am rather tired and my head isn't necessarily in the right place but meh.
  15. ajb, no, first of all he is restricting the number of choices, because certain numbers must be opposite each other, so the placement of one number immediately determines the placement of the other. Second of all, depending on the way the original question was intended, you can produce distinct dice "nets" that would appear as seperate possibilities but are essentially the same dice. For Instance take - --1 --2 3-6-4 --5 and --6 --2 4-1 3 --5 They would seem to be different possibilities but in fact are just rotations of each other.
  16. Are you allowed to assume that each face is unique somehow or do you have to take into account that several different setups will work out the same once you rotate them?
  17. http://www.w3schools.com/ can be ok, although I find it a little lacking in terms of teaching one to understand what is going on. It tends to give lots of examples, which is good, but I find it misses alot but is reasonably good just to get one started.
  18. Very impressive, what sort of research did you do beforehand and how long did it take you?
  19. Are you behind a router? It might be your IP on that network and then you are behind a NAT I mentioned this, the problem with alot of clients is that they will automatically take the image and make it an attachment. That src is one that refers to the attachment sent with the email rather than an external online source. What is happening, is thunderbird (your client) is accessing the image (hence why it logs your details) and then attaching that to the email and sending it. The exact same thing happened to me using thunderbird and rather than fiddling with it and trying to work it out, I just copied the raw email, changed the src and used sendmail to send it. I'm not quite sure what you need to do in Thunderbird to change this, I don't really use it very much (I tend to access all my mail via squirrelmail).
  20. Yeah, you have the right idea. some@email.com should be the email of the recipient and id should be something you can put in so you know which email it is. This isn't very automated but you could automate this in a number of ways. readnotify seem to do it within their own smtp servers but you could do it by making a simple webmail interface and sending the mail using php's mail() function (this would be easiest) but often this will get stopped by spam filters (and unless you do quite alot more programming, it wouldn't be sent through your mail server properly, although it would still have the correct email).
  21. Something like - <?php // Get some information about the user/client $logString = 'Date : ' . date('Y/m/d H:i:s') . "\nIP : " . $_SERVER['REMOTE_ADDR'] . "\nUser Agent : " . $_SERVER['HTTP_USER_AGENT'] . "\nEmail Addr : " . $_GET['email'] . "\nEmail Id : " . $_GET['id'] . "\n\n\n"; // Open the file for writing (append) $fh = fopen('test.txt', 'a'); fwrite( $fh, $logString ); fclose($fh); // Send the client some image header( 'Content-Type: image/png' ); // Set the Content-Type HTTP Header $fh = fopen( 'test.png', 'r' ); // Might as reuse $fh while ( !feof($fh) ) { // While we haven't reached the end of the file $data = fgets( $fh, 1024 ); // Get 1024 bytes into $data from the file echo $data; // Print that to output (ie send it to the client) } fclose($fh); // We must've reached the end of the file, so close the file handler ?> should work. It logs the IP (ish, transparent proxies can sometimes give you the wrong IP, so sometimes HTTP_HOST_IP or something like that can be used and so on but this suffices for an example and for simplistic use), Email and date accessed etc when the image is loaded at - http://somedomain.com/image.php?email=some@email.com&id=howeveryouwanttoidentifythatmessage. You can then just put that as the image src of an img in a HTML email, making sure that it actually does that and doesn't instead download the image and send it as an attachment (as alot of email clients seem to do - you might be better off sending a raw mail rather than using a mail client if you want to do this as often clients will do alot of things behind the scenes that you are unaware of). The image you want to show should be test.png in the same directory as the php script but you can change that pretty easily (or if you really can't (:S), just ask and I'll explain how). You might have to fiddle with permissions of the image to make sure it's readable by the webserver and you might also have to create test.txt or alter the script to put the log file wherever you wish. This script isn't particularly sophisticated and is really just an example to give you an idea of how it might work. It simply shows the image test.png, and puts entries in the log "test.txt" every time it is accessed (whether by an email client or web browser or whatever, as many times as it is accessed, this is something that would be changed if you wanted to make it more sophisticated) in the form - Date : 2006/06/18 20:14:18 IP : some.ip.here.ok? User Agent : Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.2) Gecko/20060515 Thunderbird/1.5.0.2 Email Addr : someemail@email.org Email Id : Testing You would have to tailor the url of the image (ie the email= and id= parts) each time you wrote a new email to a different person, giving each mail an id you'd recognise it by and the email being their email and this could become rather tedious, to automate it you'd really have to either write some sort of script for your mail client or have your mail relayed through some sort of server or script that would do this for you (it wouldn't be THAT hard to make a script to do this but if you don't have much experience programming it might be somewhat challenging). This doesn't address the problem you might have with some clients only accepting certain extensions. However you can quite easily fix this if your webserver allows you to use mod_rewrite rules in your .htaccess files. You can put something like - RewriteEngine On RewriteRule /([^/]+)/([^/]+)/image.png image.php?email=$1&id=$2 Or something to that effect in the .htaccess file in the same directory as your php file and then use the link - http://domain.com/someemail@cheese.com/someid/image.png obviously making sure not to use / in your id (or email but thats probably obvious anyways). Check out the apache mod_rewrite docs for more info. You can also do this using the $_SERVER['PATH_INFO'] variable within the actual php script without resorting to the mod_rewrite rules and using explode() etc, it's entirely up to you. Some of this depends on you having an Apache Webserver (which is more often the case when looking primarily for PHP hosting) but if you have an IIS (Internet Information Services - an MS WebServer as well as other things), you might have to change a few bits and pieces (ie the mod_rewrite rules are Apache only (well... afaik :S)). If you NEED it to work with IIS specifically, then mention that and I should be able to tailor things to IIS. I hope this helps you get an idea of what one might be able to do.
  22. An iFrame is an Inline Frame' date=' which implies that it is a frame in a html document, so it allows one to display a seperate site or url in that frame within another website which can be resized and all sorts of other things like other html elements. There don't seem to be any in the source you posted (they use the <iframe></iframe> tag - See here). All that seems to be is a few images and some background music with some fancy properties (for instance Lowsrc specifies a low resolution version of the image to load first before the high res). It seems the urls used include an id (4pyjvpqt0tvfhv) which might be what is being used to identify the individual email being sent. It could possibly be using the background sound (likely, due to the - volume) or one of the images (perhaps why it has Lowsrc and src, so the Lowsrc is displayed and the src is kept going) to keep a connection open (ie it never finishes sending the content and keep things going until the user closes the email/client). This would allow it to determine how long the email was being read (or estimate at least). This seems a bit dodgy but it might be how it's doing it .
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.