Monday, February 28, 2011

TopCoder, Inc. 2001-2011

TopCoder, Inc is 10 years this year!

I'm willing to bet this year's TCO come September 25 - 28, 2011 will be really awesome! They are ditching Las Vegas, Nevada as the traditional venue for TCO finals this year in favor of Fort Lauderdale, Florida.

Another significant milestone is the number of SRMs: TopCoder's 500th SRM will come up on Saturday March 19, 2011.

Thursday, January 27, 2011

Informix Tips

Informix command-line tips:

export CLIENT_LOCALE=EN_US.UTF8
export DB_LOCALE=EN_US.UTF8
: ensures any client can correctly connect to the server (see: UNIX setup guide)

oninit
: starts the server

onmode -ky
: kills the server

onstat -
: display server online status

oncheck -pr
: displays detailed status including dataspace info

onstat -g env all
: displays database server start-up environment settings

Executing:
cd /opt/IBM/informix
mkdir dbspaces
cd dbspaces
touch chunk1
chmod 660 chunk1
onspaces -c -d datadbs -p /opt/IBM/informix/dbspaces/chunk1 -o 0 -s 204800

will create a data space named chunk1 with size 204800 but will give a warning message like below which you can ignore.

Verifying physical disk space, please wait ...
Space successfully added.

** WARNING ** A level 0 archive of Root DBSpace will need to be done.


UPDATE: Here's a useful IBM article on Informix usage: http://www.ibm.com/developerworks/data/zones/informix/library/techarticle/0305parker/0305parker.html

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";}'