[SOLVED] Uploadify and session problems

Uploadify is a wonderful plugin for jQuery that allows you to upload several files at once,  it does the uploads transparently  using flash (take a look at the demo on this link).

In fact, the great advantage I see is not to be able to upload several files at once, this can be done by javascript with no extra plugins, the great advantage is the progress bar it shows to the user, which is great for obvious usability reasons (user looking a screen where nothing happens… not good :p).

Apart of uploading files, you can also upload any other variables or data (take a look to scriptData). This can be really useful if you want, for example,to send the data in another form at the same time a file is being uploaded.

The great disadvantage of uploadify, is that each file is sent in a separate request. This means that if you are uplading 30 files, each file is sent in a separate HTTP request. Please note that the problem here is not the speed, because you can easily make uploadify sends several files at once, in parallel, the problem appears if you have to send form data on the first request only… The fact that are different requests makes things a little more difficult to handle on the server, but anyway, this only happens on specific cases…

Anyway, I recently used uploadify in a project where users should be logged in, in order to upload files. The thing is, when I first tried uploadify, it didn’t work… files were being apparently uploaded, but they were not stored in the server. I tried again and again, and the same problem… Finally I discovered why.

Uploadify does not send cookies, and because of that, it cannot send session information on the request, so the server does not know that the user sending the files is registered, it thinks it’s an annonymous user. The good thing, is that once I realiced what was the problem, the solution was quite simple.

The solution to keep the session using uploadify is the same as when the client cannot store cookies. Basically is just adding session name and identifier at the end of the URL, as a GET request.

In PHP, adding session to the URL would be something like:

$url = $url . '?' . session_name() . '=' . session_id();

Once I did that, the application was working with uploadify ;)

, , , ,

New web for playing Flash games

I’ve been thinking of making a games website for a while. I’ve finally decided to go ahead and do a website with Flash games.

The truth is, that lately I’ve been really busy with lots of things that have nothing to do with games, but this Saturday I needed to disconnect and  work on something totally different (to dissestress myself :p), so I though on a challenge.  I told myself: “Let’s see if I am able to do a complete website of games before the end of the weekend”

I’m proud to announce NextGameGen, the new website where you can play tons of games for FREE.

I’ve made myself the whole website (even the part that upload and introduces games in the system) between Saturday and Sunday. I dedicated 4 hours on Saturday afternoon, 4 hours on Sunday morning, and 8 hours on Sunday afternoon/night. Quite intensive programming session ;)

The truth is that I’m very happy with the result. In just 16 hours a complete website of games from scratch. I only dedicated 45 minutes extra today, to add a couple of buttons to allow Sharing games in Facebook, twitter & friends, add some ads and fixing  a couple of bugs.

I know there are things that can be improved, and that there are a couple of bugs (invisible to the human eye), but the website is fully functional, so if you want, you can play right now!

The site even recommends some games according to the game you are playing to (although the algorithm is far from being perfect right now).

Now its time to grow the visits of the website. I’m planning to use ShareUsers, which is a FREE service to do automatic link exchange, and to get lots and lots of free traffic from different webs (more about this in another post).

That’s all I have to say. You can try and play some nice games, and I’m here waiting from any feedback or criticism about the games web ;)

, , , ,

MansoGrover: difference between FIXME and TODO

Hello there, this is your old pal Grover, and today I’m going to talk to you about the difference between a FIXME and a TODO in a comment.

  • FIXME: should be used when is a hack, a hardcoded constant, variable, function or something critical, and something that should be removed before the next release. Usually FIXMEs are used to do a fast prototyping, or to move forward in the software product.
  • TODO: should be used when explaining some improvments or when you have to do a (usually complex) change, or you are too lazy to do it in that particular moment.

Remember, if it is something critical, and the software could not be released without that code or fix, then use a FIXME; on the other hand, if the change will not affect the proper behaviour of the program, and you are comfortable in leaving the code as it is, then use TODO.

, ,

Click effect for jQuery

Today I’ve been playing for a while with javascript. The truth is that I haven’t found what I was looking for, but let’s assume that this is because I’m a programmer and not a designer.

Anyway, what I was trying to do is to create some kind of click effect. Ok, let me try again. What I wanted to do, is that when someone clicked on a link, that some kind of circle/rectangle/whatever expanded disappearing. Let’s try with an example. Have you seen those TV ads for games for the Wii? At the beginning there are like three or four circles that disappear. Something like that, but less sophisticate is what I wanted to do.

After trying several things, even after playing with images, I come up with a solution that is quite aproximated, although still needs something extra I don’t know how to do.

The example has two interesting parts.

The first part is where the effect is associated to the elements of class ‘clickable-round’. When you click on any ‘clickable-round’ element, a circle will appear and diffuminate:

$('.clickable-round').click (function (event) {
 $(event.currentTarget).jSimulateClick (event.pageX - 1, event.pageY - 1, 'round');
});

The other interesting fragment associated the event to the elements that contain the class ‘clickable-square’. When you click on any of those elements, the effect will be quite similar to the previous one, but instead of drawing a circle, a square that will go from one pixel to the width and height of the clicked object will appear.

$('.clickable-square').click (function (event) {
  $(event.currentTarget).jSimulateClick (event.pageX - 1, event.pageY - 1);
});

If you want to play with the plugin, my advice is that you start playing with the border width, border color, the duration, or even the size of the circle/rectangle…

You can use this javascript for any personal or commercial application, or do whatever you want with it.

Finally, I would appreciate any comment for improving the effect.

, , ,

jQuery 1.4.1 is out

Some weeks after the release of jQuery 1.4, now the first bug fix release for this fantastic javascript framework is out.

The new version fixes several bugs, and includes some improvements.

Download jQuery 1.4.1 and have a look at the release notes.


jcontroller: A small and simple controller for javascript

It’s been a long time since the last post, so I’ve though Hey! I’m loosing users, I cannot let that happen, let’s get something from any project I’ve done recently, so I can do a post :p

The thing is that I recently noticed that the javascript I’ve been writing lately becomes messy after some time, after the page and the javascript grows a little bit, there are more events, … If you understand what I’m saying then it’s a good time for you too to change.

So I’ve said to myself: “hey! (I always start talking to myself with “Hey”), so Hey! You can do a couple of things, one intelligent and one really dumb”

  • The intelligent: You can go and get a great controller that is fully documented, tested by the community, and start cleaning the mess. For example using a plugin for jQuery (CorMVC),  or even a framework like JavaScriptMVCJamal
  • Or do the dumbest thing, that is, cerate it yourself

The smart reader probably have guessed the stupid I should be a couple of paragraphs before.

Anyway, here it is. I’m glad to introduce jcontroller and his little brother the jcontroller minified version (compressed using yuicompressor).

This controller has it’s own tests (not included), but basically all those tests are passed in Firefox, Chrome e Internet Explorer. Hold on a second!… Wait I’m going to try something… here it is, it also works on Opera. So it seems it’s working fine with the major browsers (I presume it will also work well in Safari, although I haven’t tried it).

What is jcontroller all about?

Basically it’s like any controller that uses the MVC(Model-View-Controller),  it’s just a way to have kind of pretty code instead of a big mess of code

What about the Model or the View?

Are you kidding? What kind of stupid question is that? Well, is not stupid at all… But in fact, the view is controlled by your browser, and the model… well I have a jdata class, but I’m not ready to share it (this class it’s been working for long long time, but I would have to explain some concepts before sharing, so assume there is nothing else).

jcontroller Example

Now I’m going to show you an example, so you can do whatever you want with it. But before showing you the example, I want to say a few words about the keys of the example:

  • The controller is initiated by the ‘init’ method. If you name your controller “controller” then you should call “controller.init()”
  • The controller will call ‘_init’ method at the beginning, so you might want to define it.
  • The functions on your controller that start by ‘_’ are private and cannot be called by users (except _init, _default and _clear which have a special meaning)
  • When the controller loads, automatically looks at the hash part of the URL and calls the proper handler.
  • (ignore this paragraph now) Right now everything works for anchors for the same page, like <a href=”#whatever”> but you can implement your own trigger by returning your own function on the ‘_init’ method
  • (ignore also this paragraph) You can define as many controllers as you want, each controller will be independent of the others, BUT if the controllers are triggered by the same elements, expect them to execute their actions at the same time.

Here are the links for the example:

The example is really simple. It’s that simple that I feel stupid for writing it, but anyway, have a look at it and you will start to understand the capabilities of jcontroller.

Note: Right now jcontroller uses jQuery, but I don’t think it takes more than 10 minutes to change it by any other framework.

Finally, here are the links (again) to jcontroller, so you can download them again:

So, nothing else to say. If you like it, you can use it as you wish (commercially, personally, academically, *ally). If you don’t like it, then I encourage you to print the jcontroller.js in paper and then break it in a hundred pieces, you will probably feel better (you can also leave a constructive message, but just after calming down).

Constructive comments and suggestions are always welcome, and destructive comments are ignored.

Cheers ;)

, ,

Firebug 1.5 crashes on Ubuntu 64-bit

This morning I got an update message from Firefox for updating firebug to the latest 1.5 version. I’ve installed it, but when I tried to click on the icon…. booooom!! Firefox window has dissapeared.

According to this post in the Firebug blog, the crash will be solved on future versions of Firefox (3.5.8).

Just in case you are here because you have the same problem, here are a couple of solutions that work:

Google Chrome for Linux

Today I’ve received an e-mail from Google telling me that they launched the new beta for linux of their browser Google Chrome.  It’s been a while since they first launched a version for Windows.

As you might expect, I’ve downloaded and installed this brand new version of Chrome for Linux and I installed on my Ubuntu 64-bit laptop.

The truth is that it caused me a great impression, when I launched google-chrome command, the browser just appeared in a fraction of a second. I though Opera was quite amazing at rendering the browser, but now I think Chrome is even faster.

The next thing I tried is the typing test of ARTypist, and it worked amazingly well. I know it uses internally a lot of javascript, and it all works great.  Even the CSS displays properly well, and since several months ago I haven’t tried to run ARTypist on Chrome :)

Finally, after visiting another couple of web sites I realized flash worked as well without me having to install any plugin. I don’t know if it has detected the flash plugin was already installed (probably), but it’s great having it working on all pages. At the first sight, it seems the browser seems it’s working well :)

Right now I’m not planning to change Firefox by Chrome, but at least I can test my webs on Chrome without having to open a virtual machine with Windows.

, , , ,

TCPDF: excelent library for generating PDF in PHP

The other day I was looking how to create PDF files in PHP.

The first thing that came to my mind was the PDFlib extension included in PHP since version 4. The problem with this library is that  I thought it was kind of low-level, and I didn’t had any idea on where to start.

In fact, the list of functions of PDFlib is quite big, and probably you can do about anything, but I did not want to be writing a hundred of lines to do a simple PDF, I just wanted to put a background image and write some lines in there.

Anyway, I decided to continue looking more information about this library and I end up finding a library called TCPDF, which is totally free, and seemed a lot more complete and simple. I really don’t know if it’s better or not than the PDFlib, but at least TCPDF has lots of examples. There are super-simple examples of about any aspect of the PDF, so doing your first PDF is a matter of copy-pasting from several examples. Really easy!

The truth is, that I did my FIRST prototype in about 15 minutes. Not bad at all. With this TCPDF library you can generate the PDF as if it was like a HTML file. You can pass the text using HTML tags (even CSS), and then the library internally converts that to the PDF, so you don’t have to think much about generating the PDF.

The only “problem” I see with this library is that the size of the zip file you have to download is around 10MB, which are around 16 MB once uncompressed. Anyway, almost all the size of the library comes from several fonts it includes, documentation and examples. If you remove the documentation and you keep only those fonts you are going to use, this library could be minified to 1 MB only.  Although for web development I think it does not worth to make it smaller. The size does not matter.

For more information about this library you can take a look at www.tcpdf.org

, ,

Transfer a twitter application from one user to another

If you have a twitter account maybe you have played with twitter API, or even you have made a twitter application for integrating the “Sign in with Twitter”, or maybe you have created an application for something else.

Anyway, these days I’ve been working in integrating the Sign in with Twitter and Sign in with Facebook in the typing web (I haven’t released the new changes yet). I’ve been thinking that it will be a good idea to create a user called “artypist” in twitter to post the news of the web, so once I created that user I though it will be a good idea as well to move my ARTypist application from my user (amniotic) to the new artypist user. The only problem I found is that there is no option in twitter that says “Transfer this application to another twitter user”.

After this, my first though was removing the application and creating it back on the other user. This was not possible !  Twitter does not allow to remove applications once created…

A couple of minutes later I got another idea… And this new idea worked!!

To transfer a twitter application  (say APP) from one user (A) to another user (B) the only thing you need to do is to log in twitter as A, then edit the application settings and rename it to APP2, then logout and log in as B, and now you can create the application APP again. As the name has been “released” it can be used by another application :D

I hope this helps somebody!

, ,

prev posts