Simple file upload using jQuery and AJAX

Here’s something that came in helpful the other day at work – “Simple file upload using jQuery and AJAX“.  We were on the right track, but this blog post helped iron out the last few details.  In particular, this bit:

$.ajax({
        url: 'submit.php?files',
        type: 'POST',
        data: data,
        cache: false,
        dataType: 'json',
        processData: false, // Don't process the files
        contentType: false, // Set content type to false as jQuery will tell the server its a query string request
        success: function(data, textStatus, jqXHR)
        {
            if(typeof data.error === 'undefined')
            {
                // Success so call function to process the form
                submitForm(event, data);
            }
            else
            {
                // Handle errors here
                console.log('ERRORS: ' + data.error);
            }
        },
        error: function(jqXHR, textStatus, errorThrown)
        {
            // Handle errors here
            console.log('ERRORS: ' + textStatus);
            // STOP LOADING SPINNER
        }
    });

And a clarification of the parameters:

2 attributes need to be set to false:

  • processData – Because jQuery will convert the files arrays into strings and the server can’t pick it up.
  • contentType – Set this to false because jQuery defaults toapplication/x-www-form-urlencoded and doesn’t send the files. Also setting it to multipart/form-data doesn’t seem to work either.

There’s a GitHub repository with all the necessary example code.

Chrome apps … mind blown!

Don’t ask me how, but I’ve ended up in the Google Chrome Web Store, where I spent the last three hours – especially in the Productivity -> Developer Tools category.  I knew, there were plenty of apps to make Chrome OS / Chrome Browser super awesome, but it seems it’s been a while since I looked in there … My mind is officially blown!

I don’t need much from my Fedora laptop – a browser, a terminal, and some instant messaging apps.  But these days apparently that’s too much.  A lot of the things I do through the regular day can be handled right from the browser apps.

mysql

Here are some examples.

  1. Text editors.  There is a slew of them!  Simple and complex, specialized and generic, fast and … not so much.  Have a look at Caret for example.  It’s Sublime-like editor, based on the Ace editing component.  It offers a selection of themes, syntax highlighting for all the major languages, multiple tabs, project settings, and more!
  2. SSH client.  Yup, that’s right.  You can connect to your remote servers right out of the browser, using, for example, ServerAuditor.
  3. MySQL clients.  Choose between a simple command-line one, like MySQL Console.  Or a full-featured one, with ERDs and database browser, like Chrome MySQL Admin.
  4. Git, GitHub, and Gist tools.  Which there is a variety of…
  5. Web server (yes, really, a web server running in the web browser!) – Web Server fro Chrome, debugger (Xdebug), and compiler (Compiler.work).

Most of these offer session saving, networking synchronization, Google Drive data saving, social network integration, etc.

Wow!  The browser world has come a long way since Netscape 3 …

 

WWW SQL Designer

www sql designer

I came across the WWW SQL Designer today, and I have only one thing to say…

Holy Molly!  I’ve been looking for a tool like this for a long long time!  It is a web-based database designer, which can export designs into MySQL.  It’s super easy to use and it does exactly what it is supposed to.  No non-sense.  Simply amazing!

Deploying with git

Git is an excellent version control, but it’s more than just that.  A lot of people use it to deploy their projects as well.  Most suggestions (for example, this tutorial from Digital Ocean) around the web employ the post-commit (or other) hooks to push the code to a remote server.  While this works well, I prefer to do it differently.  I like the pull model better, where the deployment is triggered outside of git, and relies on git to fetch the code updates and run some sort of a build script, which handles database schema changes, cache resets, filesystem permissions, etc.  Such approach also allows to limit remote access to the servers (especially the production ones), and separate responsibilities of a developer and a deployer.

With the many pull, merge, fetch, and update options that git provides, it is sometimes difficult to choose what’s the right set of commands to use.  I’ve figured it out via a rather lengthy trial-and-error process.  But if you don’t want to go through all the pain of that, here’s a nice blog post that tells you exactly how to do that.  I’m copy-pasting the commands here just for the future reference.

cd "${DEPLOY_TREE}"
git fetch --all
git checkout --force "${TARGET}"
# Following two lines only required if you use submodules
git submodule sync
git submodule update --init --recursive
# Follow with actual deployment steps (run fabric/capistrano/make/etc)

And I suggest you read the full article for the explanation of why this is a better way and what are some of the issues with other strategies.