Compdigitec Labs

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 | 7 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 | 8 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 | 8 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 | 6 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 | 8 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 | 5 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 | 18 Comments »

TilEm, a TI-83 Plus emulator for Linux

By admin | December 2, 2010

Update: If you’re using Debian Jessie or Sid, tilem is now available in the repository.

TilEm emulator

TilEm emulator

TilEm is a Z80 based emulator for the Linux operating system. It is capable all the Z80 based series of TI graphing calculators with the exception of the TI-81.This little emulator will emulate all the features of the hand-held graphic calculator complete with a display and calculator interface with 100% compatibility.

However, TilEm is not packaged by default with Ubuntu, so we have provided a package for use with Ubuntu and Debian systems: tilem.deb (366 KB)

Simply click to install. Note that you must have your own TI-83+ images – you can try asking your educational institution, obtaining a flash update from Texas Instruments, downloading it yourself using a serial or parallel cable or searching Google for “ti 83 plus rom image“. Be sure to get a .rom file or a file which contains a .rom.

Once you have your ROM image, it is simply a matter of copying the rom to the ~/.TilEm/ti83p/ folder. For example, if you have a ROM file called “ti83p_2.rom” then just copy or move the file to the aforementioned folder. Then start TilEm by typing tilem in the terminal.

Topics: Linux | 10 Comments »

Converting between int and std::string in C++

By admin | November 20, 2010

#include <iostream>
#include <sstream>
#include <cstdlib>
using namespace std;

int main() {
	// convert int to string
	int some_int = 52;
	stringstream ss;
	ss << some_int;
	string result_s;
	ss >> result_s;
	// result_s = 52
	cout << result_s << endl;

	// convert string to int
	string some_string = "1234";
	int result_i = atoi(some_string.c_str());
	// result_i = 1234
	cout << result_i << endl;
}

Topics: Linux, Windows | 6 Comments »

Correcting IP address of PHP behind a reverse proxy

By admin | November 14, 2010

As described in our previous post, normally the PHP REMOTE_HOST variable only appears as the address of the trusted proxy server. As was also described in the past, this messes up all of the PHP scripts not explicitly designed to work with REMOTE_HOST. But now we have a solution for this – the apache mod_rpaf. This mod is capable of changing the IP variables in the server superglobal to the actual IP.

Prerequisites
Install the libapache2-mod-rpaf:

sudo apt-get install libapache2-mod-rpaf

Procedure

  1. Open /etc/apache2/httpd.conf and add the following text, replacing 1.2.3.4 with the name of your trusted proxy server:
    <IfModule mod_rpaf.c>
    	RPAFenable On
    	RPAFsethostname On
    	RPAFproxy_ips 1.2.3.4
    </IfModule>
    
  2. Save the file and restart the Apache server:
    sudo /etc/init.d/apache2 restart

Note: If you are getting 502 Bad Gateway errors coming out of your gateway and you are using IIS, disable the TCP port forwarding in IIS Admin. It can be found in the ARR page -> Proxy. Then uncheck “include client TCP numbers”.

Topics: Internet, Linux | 10 Comments »

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 »