You're browsing the category: Programming

Java, C++, PHP, you name it.

Programming / Tutorials

Javascript: Random Link Generator

This is a very simple code that you can use to generate random links. You can create a button, link, image with this function, which will randomly choose between the specified URLs to visit.

The first thing would be to create the array with the URLs There are two common ways to do this: The condensed array:

Or the regular array:

You can use any of these methods to create the generator, the next step is to create the function that will generate random links using the javascript Math.random method.

And that’s it! All that’s left is to add the HTML portion of the code, it can be a button, image, link, etc. I will use a link for this example:

This code can be modified to do many different things. For example, if you would like to display random quotes on your website, you could modify this code a little bit to make that happen. I will create a separate tutorial for that, though. Here’s the complete code from this tutorial:

If you have any questions, don’t hesitate to leave a comment.

Programming / Web Development

Thesis: Image Upload and Storage

After two days of stressing out about the profile image system implementation, I finally got it working. I was missing a piece of code that I thought I had written there and that’s why it wasn’t working, I didn’t notice it at first. When programming, it’s usually the tiniest/stupidest errors that are the most frustrating.

Thesis: Image Upload

This is a preview of how it’s working, I’m displaying the images uploaded for now while I test everything out. The image upload script makes two versions of the image. I set a maximum size for the file and create two proportional new sizes, a “big” one which is used for the user profile and sidebar avatar and a “small” one that will be used for status updates, comments, etc. Both image paths are saved to the database.

I also implemented the user profile system, if the user is logged in, you can see your own profile on “profile.php“, or by going to “profile.php?user=Your Username“, which you can also use to see other people’s profiles (even when you’re not logged in). I’m still thinking about rewriting the Apache server rules for that site so I can have something like “website.com/profile/username here“.

My first revision is this Friday and I think I have more than required for the appointment with the professor, let’s see how that goes.