Thursday, December 30, 2010

Girl and Vulture

Still disturbing as when I first saw it in Time magazine several years ago...
Background. Original image was sourced from here.

Wednesday, September 1, 2010

Ways to Create Logical Backups for an MS SQL Server 2005 Database

There are three ways, that I know of, that allow you to create logical backups of an SQL Server database.

(1) Detach and copy the data and log files (.mdf) from the data directory;
(2) Create a backup file (.bak) from the Tasks -> Backup menu when you right-click on the database in SQL Server Management Studio (Express) and;
(3) Create an SQL backup file in DDL-format (.sql) using the Microsoft SQL Server Database Publishing Wizard;

Tuesday, August 31, 2010

Truncate or Delete All Tables in an Oracle Schema

It took a lot of poring over forums, faqs and of course a visit to the awesome programmer wiki to finally get a single block of PL/SQL code that did just this!

Most of the code comes from this answer and its basic algorithm is already described in this OTN forum post.

CREATE OR REPLACE PROCEDURE sp_truncate AS 
BEGIN
-- Disable all constraints
FOR c IN
(SELECT c.owner, c.table_name, c.constraint_name
FROM user_constraints c, user_tables t
WHERE c.table_name = t.table_name
AND c.status = 'ENABLED'
ORDER BY c.constraint_type DESC)
LOOP
DBMS_UTILITY.EXEC_DDL_STATEMENT('ALTER TABLE ' || c.owner || '.' || c.table_name || ' disable constraint ' || c.constraint_name);
DBMS_OUTPUT.PUT_LINE('Disabled constraints for table ' || c.table_name);
END LOOP;

-- Truncate data in all tables
FOR i IN (SELECT table_name FROM user_tables)
LOOP
EXECUTE IMMEDIATE 'TRUNCATE TABLE ' || i.table_name;
DBMS_OUTPUT.PUT_LINE('Truncated table ' || i.table_name); 
END LOOP;

-- Enable all constraints
FOR c IN
(SELECT c.owner, c.table_name, c.constraint_name
FROM user_constraints c, user_tables t
WHERE c.table_name = t.table_name
AND c.status = 'DISABLED'
ORDER BY c.constraint_type)
LOOP
DBMS_UTILITY.EXEC_DDL_STATEMENT('ALTER TABLE ' || c.owner || '.' || c.table_name || ' enable constraint ' || c.constraint_name);
DBMS_OUTPUT.PUT_LINE('Enabled constraints for table ' || c.table_name);
END LOOP;

COMMIT;
END sp_truncate;
/

In case you want to be able to issue a rollback then you should change the TRUNCATE TABLE (a DDL statement) to a DELETE FROM (a DML statement) so that Oracle can recover the data from its redo logs.

Executing this stored procedure is as simple as:
exec sp_truncate;

Run PL/SQL Fragments Directly in SqlPlus*

BEGIN
FOR i IN (SELECT table_name FROM user_tables)
LOOP
EXECUTE IMMEDIATE 'TRUNCATE TABLE ' || i.table_name;
END LOOP;
COMMIT;
END;
Ok so you want to run the fragment above that you got from a forum post somewhere and only have access to the command line SqlPlus* utility to do so.
You add more semi-colons, press the enter key repeatedly and hope it magically parses the snippet and determines that you must want to execute the contents of the BEGIN ... END block right?

Unfortunately it doesn't work that way :). You need to tell it to parse the contents of the buffer by adding the forward slash / to the end. Voila!
BEGIN
FOR i IN (SELECT table_name FROM user_tables)
LOOP
EXECUTE IMMEDIATE 'TRUNCATE TABLE ' || i.table_name;
END LOOP;
COMMIT;
END;
/

Please see this post for truncating/deleting all tables in a schema using a stored procedure in PL/SQL.

Friday, July 2, 2010

Changing the Author Name in Xcode

So you want to change the author name from the default (the full name of the logged in Mac user) from:
// Created by Firstname Lastname on 6/21/10.
to something more creative:
// Created by SpeedingLunatic on 6/21/10.

Here's how. Run this from a Terminal:
defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions '{ "FULLUSERNAME" = "SpeedingLunatic";}'

Tuesday, April 27, 2010

Charsets, PageEncodings and a JSP page.

I recently had an issue where the prototype HTML page for a JSP displayed OK on my browser but the converted JSP rendered some non-ASCII characters with weird symbols. To top that up, the JQuery animation refused to work.

The fix was simple, I had to re-save the .jsp file by providing a pageEncoding attribute at the top in my (Eclipse) IDE:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
so that the page characters will not be saved with the default JSP encoding of ISO-8859-1.

The charset (contentType="text/html; charset=UTF-8") is the encoding with which the rendered JSP (final output) will be served to a browser while the page encoding (pageEncoding="UTF-8") is the encoding which the JSP compiler will use to understand the contents of the JSP page (saved as a text file) so that it can compile it correctly to a .class file.

Thursday, April 22, 2010

View Status of Network Services

netstat is a simple command line utility for viewing network status available on Windows, Linux and Mac OSX.
To view network status of services using TCP sockets:
netstat -abn -p tcp
for UDP sockets:
netstat -abn -p udp
Tested on both Windows and Mac OSX.

netstat -pant
for TCP Sockets. Tested on a RedHat Linux VM

Saturday, April 3, 2010

Debugging Password-less SSH Authentication

Whenever I need to frequently log into a Amazon EC2 server running Linux, the first thing I usually do is configure password-less login more properly known as public key authentication over SSH.

The steps described here are clear and to the point to help you get started.

The problem I had this time round was due to the folder/file permissions defined for the Linux user (apps) under which I was trying to login with. After some googling, I discovered that you could track SSH authentication attempts by 'tailing' this file: [tail -f] /var/log/secure which on some systems is: [tail -f] /var/log/security and then I noticed the error message --
Apr 3 17:12:36 domU-XX-XX-XX-XX-XX-XX sshd[2626]: Authentication refused: bad ownership or modes for directory /home/apps/.ssh

Rather than 'waste' time solving the permissions problem (after a few attempts I didn't make much progress) I settled with passwordless login as root! I know it's not exactly a good practise but hey the instance is not exactly running mission-critical apps anyway nor does it contain sensitive financial information ....

Sunday, February 28, 2010

Neat Data Visualization Libraries for Flex

Here are some really nice data viz libraries for Adobe Flex that sport line, bar, waterfall, cluster, bubble charts and a lot more without requiring that you have a Flex Builder 3 Professional license:

(1) Axiis

(2) BirdEye

There are open source projects so you should be able to get the code for Axiis here and for BirdEye here (SVN checkout).

Monday, February 8, 2010

Multiple undo keystrokes and bam all your day's coding is gone!!!

Working on a fresh project all day that hasn't been setup in a Subversion repository and while testing out stuff in Flex Builder (which is essentially Eclipse under the hood) I made some Ctrl+Z key strokes to undo some commented lines and I noticed the build started to fail whenever I saved the reverted changes. (Flex Builder 3 is set to build on each save by default).

I ignored the initial build errors thinking heck, Eclipse had gone gaga from prolonged use and it started to freeze after brief shots of inactivity so the error would definitely go away once I perform a Clean then a Build. How wrong I was indeed.

By the time, I got over my drunkenness three source files in newly created sub-folders had vanished from my file system. My God. No. This can't be happening to me... all of todays's work gone foreever????

I figured OK maybe Eclipse was playing pranks by somehow hiding the files so I hit Terminal to do an:
ls -lpA
to view all the hidden files in the parent directory containing the missing files/sub-folders. No dice.

Next thing I'm doing
apropos undelete
and surprisingly enough I get an entry for the undelete C library function on BSD systems. How convenient. I have to dust off my C skills to write an undelete utility to avoid loosing my mind from lost work? No way.

Enter: Google
I fire up my EVDO connection and hit the search box "eclipse deletes source files" trying to point fingers squarely at Eclipse for my misery. The first result, a mailing list post from way back, precisely in 2001, where the author wrote that it was dirt easy to lose changes while working in Eclipse with someone chiming in that it is a known issue that is planned to be addressed in version 2.0.

How refreshing. This post is from 2001?? and this is like 2010 and Google somehow thinks this will solve my issue? Rather than jump off to the next result or crafting another search query, I decided to continue reading the thread a bit more as to why this ancient post should be ranked higher than the rest, I might actually learn something. Interestingly, I hit this little nugget of information regarding Eclipse:

A couple of workarounds until the issues are resolved...

As a side note, the same thing happened to me today. I was working on a
class and deleted it by mistake. What I did was load an old version from the
repository and then choose the class in the Navigator and selected "Replace
with edition from Local History". That seemed to work fine.


Then I quickly recollected how I used to ignore that menu item "Restore From Local History..." when you right-click items in the project navigator.

I highlight the parent folder, right-click to 'Restore From Local History...' and bam my files re-appear. They all contained all my most recent edit. Hurray!!!

Google's search technology is still unarguably their most valuable piece of IP on top of which everything else powered by Google resonates which is why they won't risk it being stolen if their continued stay in China still poses such risks.

I can't say for sure if I accidentally hit some keystrokes other than Ctrl+Z while working on this project causing Eclipse to think I wanted those newly created source files deleted or that multiple undo key strokes in quick succession can cause source files that were creating within a coding session (i.e. Eclipse hasn't been restarted) to vanish. Either way, I'm too scared to try to find out until I've backed up all my changes safely.

Enough pontificating, it's time to get back to work.

Friday, February 5, 2010

Installing Oracle 10g (10.2.0.1.0)

While installing Oracle 10g on a Windows 2003 (32-bit) server instance on Amazon EC2 I got a warning from the installer after it ran some diagnostics:

Checking Network Configuration requirements ...

Check complete. The overall result of this check is: Failed <<<< Problem: The install has detected that the primary IP address of the system is DHCP-assigned. Recommendation: Oracle supports installations on systems with DHCP-assigned IP addresses; However, before you can do this, you must configure the Microsoft LoopBack Adapter to be the primary network adapter on the system. See the Installation Guide for more details on installing the software on systems configured with DHCP.


If I had chosen to ignore the warning the installation would have still succeeded anyways but here's how to fix the warning message.

Oracle Database Preinstallation Requirements: 2.6.5.3 Installing a Loopback Adapter on Windows 2003, Windows Server 2003 R2, or Windows XP offers 21 steps to help resolve the warning on Windows 2003, Windows Server 2003 R2, or Windows XP. It also contains directions for other Windows variants (Vista etc).

I decided to shave off a few steps by going the command line route since I might have to perform a number of installations.

Step 1
Download the DevCon package, a self-extracting zip archive containing an utility provided by Microsoft to allow you perform tasks that you would otherwise do from the Device Manager (and a little extra). You can read more about the tool DevCon command-line utility.

Step 2
After extracting DevCon to a location on your machine, open a command prompt window and change to the directory containing the actual devcon.exe file.

Step 3
Steps 1 to 12 from 2.6.5.3 Installing a Loopback Adapter on Windows 2003, Windows Server 2003 R2, or Windows XP can thus be condensed to these two simple steps using DevCon:

devcon -r install %WINDIR%\Inf\Netloop.inf *MSLOOP

devcon restart =net @'ROOT\NET\0000

In case you loopback adapter device address isn't "ROOT\NET\0000" you can check what value it is via:

devcon find *MSLOOP

Step 4
You can now go ahead to complete the rest of steps 13 to 21.

Saturday, January 30, 2010

Getting Started with a Solaris 10 Appliance Image for VirtualBox

You can download a Solaris 10 (October 2009) Appliance Image for VirtualBox (works on VirtualBox versions 3.0 and above) here: http://www.sun.com/software/solaris/get.jsp#virtualbox which is a ~1.4GB download. I'm using VirtualBox 3.0.6 on Mac OSX 10.5.8.

Now you need to extract the downloaded zip to reveal two files:
Solaris_10_u8.ovf
and
Solaris_10_u8.vmdk

Launch VirtualBox and from the File Menu -> Import Appliance...
Specify the path to Solaris_10_u8.ovf and accept the defaults or you could customize them to suit your preferences.

After the import process is complete, the Solaris installer will ask for additional system information: hostname, networking, root password, etc. You should provide a root password when asked.

Once the installation is complete, you'll be presented with a login screen but you need to create a new user account that you'll use on a regular basis.

Create a New User Account
(1) Login as "root" with the password you specified during setup
(2) Open a Terminal (Launch -> Applications -> Utilities -> Terminal)
(3) Type:
useradd -c "Full Name" -m -d "/export/home/username" -s /bin/bash username
Command explanation:
"-c" simply creates a new user with the name: 'Full Name';
"-m" copies the default profile information from /etc/skel;
"-d" creates the home directory in '/export/home/username' and;
"-s" specifies the shell '/bin/bash'
The final part 'username' is the login name.
(4) Type: passwd username to set the account password otherwise the account will remain locked
(5) Logout as root
(6) Login using the new user account and password
(7) You can choose either of Sun Java Desktop or CDE as you window environment.

Installing VirtualBox Additions
From the VirtualBox File menu, choose Install Guess Additions... to mount the VirtualBox additions .iso as a disk drive on Solaris and will appear with an icon on your desktop.
From a Terminal, change to the disk drive can copy two files:
cp autorun.sh ~/autorun.sh
cp VBoxSolarisAdditions.pkg ~/VBoxSolarisAdditions.pkg

This step of copying the two files above is necessary because for some reason, I couldn't get the autorun.sh shell script to work out of the box as it gave an error "id: illegal option -- u"
To fix the error:
(1) Make autorun.sh writeable:
chmod +w ~/autorun.sh
(2) Edit the file using a 'sane' text editor (I had issues using Sun's version of the vi editor):
gedit ~/autorun.sh
(3) Look for the line `$pfexecbin id -u` and change to `$pfexecbin /usr/xpg4/bin/id -u` since the version of id the script attempts to use is /usr/bin/id which doesn't support the -u option.

(4) Save and close the file.

(5) Run the script:
~/autorun.sh

Alternatively, you could ignore the error and simply just type from the directory containing VBoxSolarisAdditions.pkg:
pkgadd -d ./VBoxSolarisAdditions.pkg
[This tip is from the blog post Solaris Guest Additions in VirtualBox on Mac OS X by Susan Morgan].

After installation, you need to log out and back in for the changes applied to be re-read by your desktop environment.

I hope this helps someone.

Update:
Even after I specified a valid hostname in the initial setup screen when running the Appliance Image for the first time, I still continued to have my Solaris hostname as "unknown". After some googling the fix is quite simple: create a file called /etc/nodename and in it put your desired host name there then reboot.
So on the Terminal you could simply type these four commands (as root) to set "solaris-vm" as your hostname:
(1) # cat > /etc/nodename
(2) solaris-vm
(3) <Ctrl> + D (end-of-file character)
(4) # reboot (to confirm your changes)

Wednesday, January 27, 2010

Today in History...

Today in History: January 27, 2002, Bombs went off in their storage area at the Ikeja Army Barracks causing pandemonium across Lagos with the resulting stampede killing hundreds of people at an Oke Ofa, Isolo water canal.

Tuesday, January 19, 2010

Today in History...

Today in History: January 19, 2005, Wednesday (a day before Iléya), a group of mischievous akokites (students) rendered the then D.S.A., Prof. 'Dele Olowokudejo homeless and almost succeeded in burning down the Vice Chancellor's residence due to the controversial death of Olaolu Akosile, Speaker of the UNILAG Students Union Government.

Iléya or Eid-ul adha is the bigger of the two well known muslim festivals.

Sunday, January 17, 2010

It's not Google that's leaving China, it's China that's leaving the world

There's something really dear to Google at stake that it just isn't worth risking, given the unfavorable status quo, with their continued presence in China. Even after reading the lengthy blog post by Drummond in Google vs China I kept on wondering: why give up on such an important market like China? Many of the news outlets I frequent didn't quite give me the "aha" moment I sought.

Since we are in the participation age as Jonathan Schwartz likes to call it, I turned to comments for answers and managed to pick up some interesting bits as to why Google is making such a "bold" move.

I feel like everyone is talking around, but not addressing the likelihood that google.cn employees were involved with the govt/hacking. Google had to send their employees home to audit and secure their internal network and systems because that is by far the most vulnerable. --Mr.Recycle

2) google.cn is a like trojan horse into google’s secuity and IP. Technology is probably being smuggled over to baidu. If google shuts off that tap, they could potentially reenter the market later with a more evolved search engine and dominate. --Rdl

At least one thing is clear, a sudden realization of doing evil and then standing up to defend free speech is certainly not the real reason to quit censorship of search results after doing it for about four years in China.

Friday, January 1, 2010

Error #2007: Parameter blendMode must be non-null

So you got this error while developing a Flex 3 app.

And you have already consulted this post: http://www.newviewnetworks.com/nvnhome/blog/client/?p=168 who in turn had consulted this post for guidance.

Hmm, even the post by The Agile Tdog refers to another post by Agile UI and this still points to a use case where there is a mismatch between the Flex 3 SDK version you are developing (your project) on and an/some external Flex lib which may have been compiled with a newer or older Flex 3 SDK version.

But that is not my case -- I get this error purely due to my (mis-)use of components in the Flex framework.

Short answer: simply set the blendMode attribute to a valid value on the component that caused the error a la:
blendMode="{BlendMode.NORMAL}"

Synopsis
I was trying to implement reordering of the elements of a control via drag and drop within the same control.

Basically, this is what I did:
<mx:List
 dragEnabled="true"
 dropEnabled="true"
 dragMoveEnabled="true" 
 width="100%"
/>

and then I got the blendMode must not be non-null error.

So my fix was to set the blendMode attribute, which by the way, is inherited from flash.display.DisplayObject.

<mx:List
 dragEnabled="true"
 dropEnabled="true"
 dragMoveEnabled="true" 
        blendMode="{BlendMode.NORMAL}"
 width="100%"
/>

Possible values are listed in the docs here: http://livedocs.adobe.com/flex/3/langref/flash/display/DisplayObject.html#blendMode

[I'm developing using Flex Builder 3 for the Mac which shipped with the Flex 3.2 SDK.]