Adding titles to your xterm sessions and icon

September 29th, 2008, admin

###########################################################
xbar () # puts new label on Xwindow title bar and icon
###########################################################
# This function displays the title on the window bar in X
# You can pass the title you want with a parameter
{
# NOTE: in vi editor to create the Esc (which appears here as “^[") use Ctrl-v,Esc
# And to create the Ctrl-G (which appears here as "^G" use Ctrl-v,Ctrl-g 
echo "Setting the title bar and icon label in your X session"
if [ "x$1" != "x" ];then
echo ” Setting title… ”
echo ^[]1;$*^G 
echo ” Setting icon label… ”
echo ^[]2;$*^G
else
echo ” Setting title… ”
echo ^[]1;$LOGNAME@$HOSTNAME^G
echo ” Setting icon label… ”
echo ^[]2;$LOGNAME@$HOSTNAME^G
fi
#The title of a XTERM window can be set using the following
#escape sequence:
#
# ESC ] 0 ; title ^G
#
#Example:
#
# echo “^[]0;This is a title^G”
return
}

Converting MySQL queries to XML

September 20th, 2008, admin
/**
 * @param mysql_resource - $queryResult - mysql query result
 * @param string - $rootElementName - root element name
 * @param string - $childElementName - child element name
 */
function sqlToXml($queryResult, $rootElementName, $childElementName)
{ 
    $xmlData = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n";
    $xmlData .= "<" . $rootElementName . ">";

    while($record = mysql_fetch_object($queryResult))
    {
        /* Create the first child element */
        $xmlData .= "<" . $childElementName . ">";

        for ($i = 0; $i < mysql_num_fields($queryResult); $i++)
        {
            $fieldName = mysql_field_name($queryResult, $i); 

            /* The child will take the name of the table column */
            $xmlData .= "<" . $fieldName . ">";

            /* We set empty columns with NULL, or you could set 
                it to '0' or a blank. */
            if(!empty($record->$fieldName))
                $xmlData .= $record->$fieldName;
            else
                $xmlData .= "null"; 

            $xmlData .= "</" . $fieldName . ">";
        }
        $xmlData .= "</" . $childElementName . ">";
    }
    $xmlData .= "</" . $rootElementName . ">"; 

    return $xmlData;
}

USAGE :

/* Sql query */
$result = mysql_query("SELECT * from company");

/* If you want to process the returned xml rather than send it
    to the browser, remove the following line.
*/
header("Content-Type: application/xml");
echo sqlToXml($result, "companies", "company");

MySQL is a very popular free yet powerful database system. But even in great databases, the tables may get fragmented with overhead due to continuous update, or delete and insert operation on data stored in database. Beside, it’s also possibility that the databases may get corrupted. Thus, performing health check on database and optimize MySQL server regularly is an important task.

It’s a bit troublesome if the database administrators have to login to the server or launching the phpMyAdmin to optimize the databases one by one or table by table manually. Sometimes DB admin may simply forgets to do the job or set the frequency of optimization to lesser times. It’s recommended that every tables in MySQL databases are checked at least once a day on a busy server.

It’s possible to automate the optimization of MySQL process by using crontab function in Linux/Unix/CentOS/FreeBSD. The cron job to check and optimize MySQL databases can be created by using mysqlcheck client utility comes MySQL installation. mysqlcheck client can checks, repairs, optimizes, and analyzes tables in MySQL database.

To create a new cron job, login to the server as root or any other user, and then edit the crontab file (in most operating system, crontab -e will open crontab file in default text editor) to add in the following line of text. For users using cPanel, click on “Cron job” where you can set up crontab at daily, hourly and other interval. Experience webmasters can also set up a crontab file in rc.hourly or rc.daily or other cron directory. Note that if you login as a MySQL or normal user with no access privileges to all database, it’s not possible to optimize all databases, unless user ID and password for root is specified as in example below.

0 1 * * * mysqlcheck -Aao –auto-repair -u root -p[password] > /dev/null

The above statement has the syntax similar to “mysqlcheck [options] –all-databases”, where –all-databases parameter is the default action is no databases is specified thus can be omitted. The command will run mysqlcheck client to automatically analyze and optimize all databases at 1 am everyday. Note that there is not space between -p and your password for root. You can change the running time to your preference, and also change the options for mysqlcheck command. If you just want to check and optimize certain databases or certain tables without the database, use the following syntax:

mysqlcheck [options] db_name [tables]
mysqlcheck [options] –databases DB1 [DB2 DB3...]

You may want to remove –auto-repair switch from the above command, as a table repair operation might cause data loss under some circumstances the operation due to causes include but are not limited to filesystem errors. For those who has changed the character set and collation of MySQL databases may also need to use –default-character-set option. More information on all available switches and options available can be found here.

Worm hits unsecured space station laptops

September 5th, 2008, admin

wormsNASA has confirmed that laptops taken on to the International Space Station (ISS) carried the W32.Gammima.AG virus, which steals the login details for online games popular in the Far East, such as “Maple Story” and “Talesweaver.” NASA calls the virus a “nuisance,” and says it’s on “non-critical” laptops. NASA says it is unclear which country brought the virus-infected laptop onboard the International Space Station. 

Perhaps you’ve seen this movie: A virus infects a human-piloted spacecraft, and within days the mission is compromised and Earth is lost to the alien attackers. There’s now a report that the first part of that storyline has come true — only it’s a computer virus on the International Space Station. [ ... ]

chromeNow that the enormous amount of noise over the debut of the Google chrome browser has died out a bit, what does it look like from a security viewpoint? 

For some reason, they based their browser on WebKit that Apple’s safari browser also uses. The dependencies in security between the versions was the way that intrepid hacker Aviv Raff discovered that like the earlier version of Apple’s Safari Browser, the new Google browser was vulnerable to a carpet bombing attack. The attack would allow an attacker to drop malware on a desktop (the social hook here was free coffee coupons in the demo) and get people to launch it off on their desktop.  [ ... ]

Fluxbox on OpenBSD

August 9th, 2008, admin

Xorg Setup

shell>Xorg -configure

This command will automatically detect your hardware specification and generate the xorg.conf.new as a template under your user home directory.

You can test your xorg.conf by using the command below

shell>Xorg -config /root/xorg.conf.new

Once you have proper xorg.conf.new under your user home directory, copy it to the /etc/X11

shell>cp xorg.conf.new /etc/X11/xorg.conf

Now you are done with Xorg.

If you want to use xdm instead of gdm, normally you can just

shell>echo “xdm_flags=\”\”" > /etc/rc.conf.local [ ... ]

Batch files (.BAT) and Windows NT Command Script (.CMD) files run in console window when double-clicked. This means that the Command Prompt window will be visible until the .BAT/.CMD file execution is complete. To make .BAT or .CMD file execution less intrusive, you can configure it to run minimized. Or if the .BAT or .CMD file does not require user input during run time, you can launch it in invisible mode using a Script. Both options are discussed below.

Running .BAT or .CMD files in minimized mode

  1. Create a shortcut to the .BAT or .CMD file. To do so, right click on the file, click Send To,Desktop (create shortcut)
  2. Right click on the shortcut and choose Properties
  3. In the Run: drop down, choose Minimized
  4. Click OK
  5. Double-click the shortcut to run the batch file in a minimized window state.

 

Running .BAT or .CMD files in invisible mode

Windows Script Host’s Run Method allows you run a program or script in invisible mode.

 

Sample Code

Set WshShell = CreateObject(”WScript.Shell”) 
WshShell.Run chr(34) & “C:\Batch Files\syncfiles.bat” & Chr(34), 0
Set WshShell = Nothing

Copy the lines above to Notepad and save the file with .VBS extension. Edit the .BAT file name and path accordingly, and save the file. Double-click the .VBS file to run it.

vistaWindows Aero is a pleasing graphical user interface which includes transparencies, taskbar thumbnails, animations and other features. Windows Aero is the default theme in most editions of Windows Vista. If you want to turn off Aero for performance gain, use these steps.

[ ... ]

outlookWhen you open Windows Mail, the splash screen appears for few seconds before the program window is displayed. Splash screens are used in programs to display a image or a form while the program loads. You can disable the splash screen for Windows Mail if you find it annoying. Disabling the splash screen may not improve the program load time.

  1. Click Start, type Regedit.exe and press ENTER
  2. Navigate to the following registry key: HKEY_CURRENT_USER \ Software \ Microsoft \ Windows Mail
  3. From the Edit menu, click New, click DWORD (32-bit) Value
  4. Name the value as NoSplash
  5. Double-click NoSplash and set its data to 1
  6. Exit the Registry Editor.

Imagine, you’re connecting to a mySQL database with PHP, but hell, you want a bit more robustness. So why would you want just one database? You’d use a failover right? So if the first database is down or just doesn’t connect, it can connect to the next one. Here’s how to do that (I’m assuming you’re already replicating between databases so that they’re roughly in sync). [ ... ]

Lijit/Wijit
Tags
Feeds
Ads