Tuesday, January 29, 2013

Cool Javascript to Download a File

Found this really cool snippet that you can use to download a file with javascript. It uses a technique to insert a hidden iframe on to the page and then streams the file directly by using the file url as the url of the iframe.

Now you can use logic in your page to trigger downloads of different files.

This is the function you can use and I found it on this web page: http://stackoverflow.com/questions/3749231/download-file-using-javascript-jquery


var downloadURL = function downloadURL(url)
                        {
                            var hiddenIFrameID = 'hiddenDownloader',
                            iframe = document.getElementById(hiddenIFrameID);
                           
                            if (iframe === null)
                            {
                                iframe = document.createElement('iframe');
                                iframe.id = hiddenIFrameID;
                                iframe.style.display = 'none';
                                document.body.appendChild(iframe);
                            }
                            iframe.src = url;
                        };

Saturday, January 12, 2013

SVN Command to Delete All Missing Files

Found this handy command from Stack Overflow to SVN Delete all missing files.


svn st | grep ^! | awk '{print " --force "$2}' | xargs svn rm

I found this from this article:

http://stackoverflow.com/questions/9600382/svn-command-to-delete-all-locally-missing-files

Monday, January 7, 2013

User-Agent Switcher Extension for Chrome

I came across a pretty cool extension for Chrome today. I needed to switch the user agent of my browser to test an application hack. Apparently, one of our Joomla (aka Doomla) sites were hacked recently with an exploit that showed viagara ads on bot ONLY visits.

The extension is called User-Agent Switcher and it works like a charm. I was able to change my user agent to the google bot so that we could get a reproduction of the issue.

This is a screen shot of the extension in your browser:


Adding Menu Icons in Superfish Module for Drupal 7

I had a project dropped on my lap a few weeks ago. Obviously, It was already behind schedule. One of the features was to implement a dropdown menu with a home icon for the home link. Unfortunately, I found out that the superfish module bypasses the drupal methods for the menus. So, this is how I managed to get it modified. Please note that this is not upgrade friendly. You will have implement this solution again if you upgrade the superfish module. I performed the quick and dirty solution since I was already behind schedule. The better approach would be to override methods in your theme template file.

1) Open superfish.module file.

2) Scroll down to theme_superfish_build method.

3) Add your new logic to the last section of the method where there is concatenation of the output html.

My logic was this:

$pattern = '/\S+\.(png|gif|jpg)\b/i';

        if(preg_match($pattern, $menu_item['link']['title'], $matches) > 0)
        {
            $output['content'] .= '<a href="'.url($menu_item['link']['link_path']).'">'.preg_replace($pattern,'<img alt = "' . $menu_item['link']['title'] . '" src = "' . url($matches[0]) . '" />',
                $menu_item['link']['title']).'</a>';
        }
        else
        {
            $output['content'] .= l($menu_item['link']['title'], $menu_item['link']['link_path'], $link_options);
        }

This logic transforms a url path in the title that contains an image file extension into an image tag. This worked good for my solution, but would not have worked well if all my menu items needed an image. That is because the title would be displayed in other modules such as menu block. I would have needed a much more complicated snippet to handle an entire menu.

Sunday, January 6, 2013

Added Development Environment Setup for Vanilla Ubuntu VM

I created a setup archive for installing the required files and applications for the development virtual machines. I went through this process so that I could easily create a new development environment without having to remember everything that I installed and configured. Now it is easy to go from ground zero to full development. The setup archive is tailored for an ubuntu vm.

https://docs.google.com/folder/d/0B37iWxTxZVl8cFhSVURpdUsyQzA/edit

Updated Development Virtual Machines to 12.10

I finally got the virtual machines updated to version 12.10 of Ubuntu. This involved an installation of the operating system in a clean VM and complete reconfiguration. This is because the upgrade from 12.04 to 12.10 did not go as smoothly as I expected. One of the big changes was the removal of the android sdk. I had to do this to reduce the size of the development environments. Got the .ova files down from 7GB to around 3GB.

You can find all of my Java and PHP Development virtual machines at this location:

https://docs.google.com/folder/d/0B37iWxTxZVl8cFhSVURpdUsyQzA/edit

Please review the readme file in the directory before downloading the virtual machines. Thanks.