Compdigitec Labs

Creating jQuery UI Tabs

By admin | August 21, 2011

jQuery UI Tabs are an easy way to make tabs in your web applications or web sites easily with less code. Consider the following tab structure:

<div id="tabgroup">
	<ul>
		<li><a href="#tab1">Tab 1</a></li>
		<li><a href="#tab2">Tab 2</a></li>
		<li><a href="#tab3">More Tabs</a></li>
	</ul>
	<div id="tab1">Hello</div>
	<div id="tab2">World</div>
	<div id="tab3">from jQuery UI Tabs</div>
</div>

To turn this into a fully featured functioning tab system, all one has to execute in the <head> is this provided you have included jQuery and jQuery UI with any CSS in your <head> (default CSS can be included like such: <link rel=”stylesheet” type=”text/css” href=”http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/ui-lightness/jquery-ui.css” />):

jQuery(document).ready(function() {
	jQuery("#tabgroup").tabs();
});

This tab structure also degrades reasonably without JavaScript - one is able to view the contents of all of the tabs and the anchor links are usable - unlike some other tab techniques.

Topics: (X)HTML | No Comments »

Light build of Mozilla Firefox

By admin | June 30, 2011

Most of the time, a stock Firefox installation from Mozilla’s website or the apt repository usually works just fine on most machines. However, if you prefer a more plain and vanilla Firefox install without all the latest bells and whistles, then one can manually compile a build from source code. This has the advantage of being faster and leaner than the stock Firefox because the unwanted features are simply not present, although you will not have all the latest web bells/whistles with this method (e.g. WebM, WebGL, HTML5 video, etc).

Download a copy of the Firefox source, and extract it. Then run ./configure as follows:

--enable-application=browser --enable-official-branding --disable-debug --with-x --disable-profiling --disable-gnomevfs --disable-gconf --disable-accessibility --disable-ogg --disable-webm --enable-splashscreen --disable-angle --enable-crashreporter --disable-smil --disable-installer --disable-updater --disable-update-packaging --disable-parental-controls --disable-tests --enable-faststart --disable-safe-browsing --disable-meegocontentaction --enable-optimize=-O2 --disable-logging --enable-install-strip --disable-necko-wifi --disable-glibtest

A few points to note:

Then run make. If you want to test your build, you can find it under dist/bin of your extracted tarball. Change to that directory and then one can test it like so:

LD_LIBRARY_PATH=. ./firefox-bin -ProfileManager -no-remote

This will allow you to test without clobbering your existing profile. When you are done, you can run make install (beware of conflicts with the repository’s firefox) or if you would rather use checkinstall to make a package, checkinstall --fstrans=no.

Topics: Linux | No Comments »

Launch non-exe extension files as executables

By admin | May 1, 2011

Windows does not come with a built-in way of launching executables that are without the exe extension. However, we have written a small tool called “anylaunch” which allows one to execute any file as if it were an executable. (Non-PE files will still give an error since they are not executables “XYZ is not a valid Win32 application”)

Download (anylaunch.exe) or compile from source below:

#include <iostream>
#include <windows.h>
#include <cstdlib>
//#define ZeroMemory(p,size) memset((p),0,(size))
using namespace std;

int main(int argc, char* argv[])
{
	if(argc-1 < 1) {
		cout << "No process specified" << endl;
		return 0;
	}

	STARTUPINFO si;
	PROCESS_INFORMATION pi;
	// must blank it
	memset(&si,0,sizeof(si));
	si.cb = sizeof(si);
	si.lpReserved = NULL;
	si.lpTitle = NULL;
	// required for GUI app
	si.dwFlags = STARTF_USESHOWWINDOW;
	si.wShowWindow = SW_MINIMIZE;

	bool res = CreateProcess(NULL,argv[1],NULL,NULL,FALSE,0,NULL,NULL,&si,&pi);
	if(res == false) {
		printf("CreateProcess failed (error code %d)\n", GetLastError());
		return 1;
	}

	CloseHandle(pi.hProcess);
	CloseHandle(pi.hThread);
	return 0;
}

Download or compile the anylaunch executable and put it into the same directory as your script or into the system directory. You can use it in a command line, batch scripting or another program like so:
anylaunch “<process command line here>”

Simple examples (assuming anylaunch is in system path or current folder):

Although the biggest use of this tool is to launch non-exe PE files, like so:

file yes.123

yes.123: PE32 executable for MS Windows (GUI) Intel 80386 32-bit
Then we can use anylaunch to launch this PE file:

anylaunch yes.123
Non-exe process in Task Manager

Non-exe process in Task Manager

You may run into some problems while running this. If your command line arguments to your target application are not showing up, you should put your entire command line into one argument and escaping quotes (anylaunch “C:\\Program Files\\Mozilla Firefox\\firefox.exe” not anylaunch C:\Program Files\Mozilla Firefox\firefox.exe). Some other common problems:

Accessing a file that does not exist or is inaccessible (The system cannot find the file specified.):

cat somefile.rnd

cat: somefile.rnd: No such file or directory

anylaunch somefile.rnd

CreateProcess failed (error code 2)

Trying to run an invalid Windows application

file Untitled.png

Untitled.png: PNG image, 800 x 600, 8-bit/color RGB, non-interlaced

anylaunch.exe Untitled.png

CreateProcess failed (error code 11) (An attempt was made to load a program with an incorrect format.)
CreateProcess failed (error code 193) (%1 is not a valid Win32 application.)
etc… (invalid format error, or win32 errors, etc)

Topics: Windows | No Comments »

Distributing small Java applications (i.e. convert to EXE)

By admin | April 30, 2011

Many times it can be said that it is not very friendly getting a .class file to run. Here is a better way to get them to run - it involves first converting it to an executable .jar and then optionally converting to an executable file on Windows.

Prerequisites:

Procedure:

Topics: Linux | No Comments »

Debugging comments on old posts in WordPress

By admin | March 7, 2011

Sometimes on a WordPress blog all comment entry points on old blog posts will stop working. This can be caused by a number of problems:

  1. Posts are set to expire. If you select the option “Automatically close comments on articles older than x days” under Settings->Discussion, then posts will automatically close comments after x days.
  2. Your blog is not set to enable commenting. Enable “Allow people to post comments on new articles” under Settings->Discussion.
  3. The specific post is not allowing comments. Edit the post in question and under the “Discussion” section ensure both “Allow comments” and “Allow trackbacks and pingbacks on this page” are both selected.

If the above three steps still do not help, then you can run the following database queries to enable comments globally:

UPDATE wp_posts SET comment_status = REPLACE (comment_status, 'closed', 'open') WHERE post_status = 'publish' AND post_type = 'post';
UPDATE wp_options SET option_value = 0 WHERE option_name = 'close_comments_for_old_posts'

Topics: PHP | No Comments »

Setting up a ProFTPd port-based VirtualHost

By admin | February 13, 2011

ProFTPd is a very powerful FTP server software that is most commonly used on Linux servers to provide a FTP service to the public, Intranet or Web Services. ProFTPd, much like its HTTP counterpart, Apache, contains the ability to host multiple different services on one physical computer by using “Virtual Hosts”, which makes it appear as it were multiple hosts hosting different content. Unfortunately, FTP does not support named-based virtual hosting like HTTP does, so to allow customers/clients to be able to FTP you must use a different port.

Procedure

  1. Open up your ProFTPd configuration file (by default it is /etc/proftpd.conf) using your favourite text editor:
    sudo nano -w /etc/proftpd.conf
  2. Add a VirtualHost. The following snippet sets up a “virtual” server on Port 3003 for all bound IP addresses (IPv6 and IPv4). You can change the 3003 to the port you want to host, change the ServerName to a useful description of the host and DefaultRoot to the root of the FTP.
    <VirtualHost ::0.0.0.0>
    	Port 3003
    	Umask 022
    	ServerName "VirtualHost FTP"
    	DefaultRoot /home/www/customer3003
    </VirtualHost>
    
  3. If you do not want IPv6 support or it gives you problems on your specific host, then you can bind it to all IPv4 addresses on Port 3003 (same as above otherwise):
    <VirtualHost 0.0.0.0>
    	Port 3003
    	Umask 022
    	ServerName "VirtualHost FTP"
    	DefaultRoot /home/www/customer3003
    </VirtualHost>
    
  4. If you want, you can also modify it to bind to only certain ports to the specified port. When you are comfortable with your configuration, save the file and exit.
  5. Reload the FTP server and connect away:
    sudo /etc/init.d/proftpd restart

What did not work

Topics: Linux | No Comments »

Microsoft Word 2010 and colour depth

By admin | February 5, 2011

Normally, the appearance of the Office 2010 application on the Windows operating system is the one with a high colour depth with the modern icons. However, if you are accessing an Office 2010 application through a remote access application like VNC or Remote Desktop or if you have a graphics card which is not capable of supporting high colour or higher or if the graphics card is misconfigured, then you might end up with a really “classic” look in Microsoft Word using Office 2000-style icons and a low colour scheme:

Microsoft Word in low colour

Microsoft Word in low colour

To restore the appearance to the full colour style, simply set the colour depth of the operating system to 16-bit or higher by right clicking on the Desktop, selecting Properties and going to the Settings tab, or by selecting Display Resolution, Advanced and going to the Monitor tab. If you want to trigger this look, simply set your colour depth using the same method to 256 colours, and you should be all set.

Topics: Windows | No Comments »

Getting the direct link of a SkyDrive file transparently using PHP

By admin | January 31, 2011

Windows Live SkyDrive is one of the best online storage/file hosting solutions available online. It provides you with 25 GBs of free storage associated with your Windows Live ID, and allows you to upload as many files as you want to it. However, Windows Live SkyDrive’s direct links are not stable for more than a day, unlike Google Docs where the direct link is stable and permanent. Here is a PHP function that can be used to obtain the direct link of a SkyDrive file using the public URL of the file.

<?php
/*
 *      (C) Copyright 2011 Compdigitec. All rights reserved.
 *      Redistribution and use in source and binary forms, with or without
 *      modification, are permitted provided that the following conditions are
 *      met:
 *
 *      * Redistributions of source code must retain the above copyright
 *        notice, this list of conditions and the following disclaimer.
 *      * Redistributions in binary form must reproduce the above
 *        copyright notice, this list of conditions and the following disclaimer
 *        in the documentation and/or other materials provided with the
 *        distribution.
 *      * Neither the name of the Compdigitec nor the names of its
 *        contributors may be used to endorse or promote products derived from
 *        this software without specific prior written permission.
 *
 *      THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *      "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *      LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 *      A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 *      OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 *      SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 *      LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 *      DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 *      THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *      (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 *      OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/**
 * Gets the direct link of a URL with a given public Skydrive URL
 * @param string $liveurl The public SkyDrive URL
 * @return string|false The direct URL of the skydrive or false if error
 */
function get_skydrive_direct_link($liveurl) {
	$file = file_get_contents($liveurl);

	// find file loc
	$pos = strpos($file,'<a id="spPreviewLink" href="');
	if($pos === false) return false;
	$pos += strlen('<a id="spPreviewLink" href="');

	$buffer = "";
	while(substr($file,$pos,1) != '"') {
		$buffer .= substr($file,$pos,1);
		$pos++;
	}

	$buffer = html_entity_decode($buffer);

	$directlink = substr($buffer,0,strlen($buffer)-7);

	$host = parse_url($directlink,PHP_URL_HOST);
	if(strpos($host,"livefilestore.com") === false) {
		return false;
	}
	return $directlink;
}
?>

To use this function, feed it the public URL and it will return the direct link of the file:

$direct = get_skydrive_direct_link("http://cid-abcdef1234567890.office.live.com/self.aspx/FolderName/FileName.exe");
// Returns something like http://public.bay.livefilestore.com/y1pZwjyu-qfXUWjM-si2IeNs-juO0PjZE-Sk5EVvZxgeenjCxxv9vHiUy8q1RGafKnbaGSC2alqAoIbDvAYegznaZ/FileName.exe
$not_direct = get_skydrive_direct_link("http://not.skydrive.example.com/not/a/skydrive/FileName.exe");
// Returns FALSE (if it is not a SkyDrive upload)

You can use this script as part of an independent web service or as part of your existing PHP application under the BSD license. There is a link generator on this website available that you can use to try it out or use with your application without needing the script to be installed.

Topics: PHP | 3 Comments »

Redirect non-www domain to www in Apache

By admin | January 24, 2011

Search engines will often consider the non-www and www sites of a domain as separate websites (example.com vs www.example.com). In order to solve this, you will often want to redirect the non-www part of the website (example.com) to the www part (www.example.com). So this way if your visitor types example.com or www.example.com they will wind up at your home page at www.example.com.

First have your site configuration file (with the VirtualHost) opened in your favourite text editor, then make sure the ServerName of the VirtualHost is set to the www version:

<VirtualHost *:80>
	ServerAdmin you@example.com
	ServerName www.example.com

	<!-- other VirtualHost configs here... -->
</VirtualHost>

Then add another VirtualHost at the bottom of that (in the same file), replacing your variables:

<VirtualHost *:80>
	ServerName example.com
	Redirect permanent / http://www.example.com/
</VirtualHost>

This should look something like this in the end (all in one file):

<VirtualHost *:80>
	ServerAdmin you@example.com
	ServerName www.example.com

	<!-- other VirtualHost configs here... -->
</VirtualHost>

<VirtualHost *:80>
	ServerName example.com
	Redirect permanent / http://www.example.com/
</VirtualHost>

When you are done save the file, close it and reload Apache:

sudo /etc/init.d/apache2 reload

This is a very safe and effective way to enforce your SEO and this solution does not require the rewrite engine either, which makes it very fast and safe. It performs the 301 redirect in the search-engine-approved manner and it will make sure your search engine popularity is not being cut in half by the www and non-www.

Topics: Linux | No Comments »

Quickly generate CRUD (Create, read, update, delete) stored procedures in SSMS with SSMS Tools Pack

By admin | December 23, 2010

SSMS Tools Pack generated CRUD

SSMS Tools Pack generated CRUD

Normally, in SQL Server Management Studio to generate some stored procedures one would have to go through series of dialogs and manual actions using the “Script To” menu. This process is both painful to do by hand and is also very error-prone. Now there is an automated tool that can automate the process of writing stored procedures for us - SSMS Tools Pack.

To automatically generate the select, insert, update and delete procedures all one must do (after installing the free add-on), is right click on a table, go to “SSMS Tools” and “Generate CRUD“, and then Execute the query that it generates. This makes database development much easier compared to doing it by hand.

Topics: Windows | 1 Comment »

If you found this article helpful or interesting, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more useful and interesting articles! « Older Entries Newer Entries »