titbits from the world less travelled

Archive for April, 2010

Database SQL Server, time for defragmentation

Keywords you will need to know: fragmentation/defragmentation
The DB server which I use is Microsoft SQL Server Enterprise Edition
SQL commands:

select * from sys.dm_db_index_physical_stats(DB_ID(ecommerce_vh10),NULL,NULL,NULL,NULL)

The above command will get you all the index values and descriptions in the database. But it shall give you only the object needed for verification of your indexes, but not the names. Now what you got to do is:

select top 100 i.object_id,i.name,avg_fragmentation_in_percent,avg_page_space_used_in_percent from sys.indexes i join sys.dm_db_index_physical_stats(DB_ID(ecommerce_vh10),NULL,NULL,NULL,NULL) ips on (i.object_id=ips.object_id)

id=BLOGGER_PHOTO_ID_5265715542992212098

What this does is to join the indexes table and index description table. This will give you the index and index name. You will need to keep an on avg_fragmentation_in_percent which should be on the lower side. If its reaching 100% you got a problem there. This can happen when you have lot of insert,update,delete commands on the table and the space is not utilized properly.

posted by admin in Uncategorized and have No Comments

Nokia N8 stolen and then reviewed

I recently came across this site where they have reviewed the much awaited nokia n8.

What I am amazed is that these fools reviewed an unfinished and untested product and declared the phone worthless.

Any sensible person would not review an untested and unreleased product. God save their readers.

As for the stolen phone, it didnt get much attention as the Iphone 4g, but Nokia did release a statement. regarding that.

Some of the other reviews can be found at: http://blogs.zdnet.com/cell-phones/?p=3669

posted by admin in iphone, webos and have No Comments

Nokia N8 – Supposedly looks good

posted by admin in Uncategorized and have No Comments

How to strip mulitple and variable spaces in python

LJS93K 1300 10500
J38ZZ9 700 4750

What do you do when you have multiple spaces but not constant spaces in between words. You could you split in python but what that does is either strips all spaces or gives you a single space for each space found. this wouldnt be want you wanted. So you could do the following;

Read all the lines above into a String and then remove all new line chars or tabs and so on:

newString = re.sub([s], ,myListString)

Then join them to get a uniformly spaced string:

newString = .join(newString.split())

posted by admin in python and have No Comments

Correct usage of Mbstowcs

I got this snippet of code from a security website. I thought I would post it, since its a common mistake most do. Not allocating enough memory when using buffers:

Examples of Incorrect Code:

wchar_t destString[20];
const char sourceString[] = “Pretend this string is multi-byte.”;

// The following has multiple problems:
// 1. The number of characters destString can hold is actually sizeof(destString)/sizeof(destString[0])
// 2. The buffer is not large enough to hold the converted string.
// 3. No check is done to ensure that the entire string was converted.

mbstowcs(destString, sourceString, sizeof(destString));
Examples of Corrected Code

const char sourceString[] = “Pretend this string is multi-byte.”;

// Size the output buffer as needed to fit the complete result
int charsToProduce = mbstowcs(NULL, sourceString, 0) + 1; // note error return of -1 is possible
if (charsToProduce == 0) { /* handle error */ }
if (charsToProduce > ULONG_MAX/sizeof(wchar_t)) return error;
wchar_t *destString = (wchar_t *)malloc( charsToProduce * sizeof(wchar_t) );

mbstowcs(destString, sourceString, charsToProduce);

posted by admin in c++ and have No Comments

raw extraction of data from google blogger to wordpress

This is a small script I wrote to extract all posts from my blogger which was in the form a xml or aton feed and insert into a wordpress database.

import feedparser
import re
d = feedparser.parse(“C:\\Python25\\programs\\blog.xml”)
count = len(d['entries'])
loopVar = 0
p = re.compile(r’[\'\"]‘)
mainInsertString = “INSERT INTO `wp_posts` (`ID`, `post_author`,”
s2 = “`post_date`, `post_date_gmt`, `post_content`, `post_title`,”
s3 = “`post_category`, `post_excerpt`, `post_status`, `comment_status`,”
s4 = “`ping_status`, `post_password`, `post_name`, `to_ping`, `pinged`,”
s5 = “`post_modified`, `post_modified_gmt`, `post_content_filtered`,”
s6 = “`post_parent`, `guid`, `menu_order`, `post_type`, `post_mime_type`,”
s7 = “`comment_count`) VALUES”

finalInsertString1 = mainInsertString + s2 + s3 + s4 + s5 + s6 + s7
print finalInsertString1
blogID = 3300
finalDBString = “”
finalDBString = finalInsertString1
dbString2 = “, 1, ‘2009-06-17 06:11:54′, ‘2009-06-17 06:11:54′,”
dbString3 = “‘, 0, ”, ‘publish’, ‘open’, ‘open’, ”, ‘palm-pre-and-web-os’, ”,”
dbString4 = ” ”, ‘2009-06-17 21:13:18′, ‘2009-06-17 21:13:18′, ”, 0, ”
dbString5 = “‘http://kmdarshan.com/wordpress/?p=”
dbString6 = “‘, 0, ‘post’, ”, 0),”
f = open(‘C:/Python25/programs/sqlfile.txt’, ‘w+’)
f.write(finalInsertString1)
encoding = “ascii”
loopString = “”
for loopVar in range(48, count):

blogTitle = d.entries[loopVar].title
e = d.entries[loopVar]
data = e.content[0].value
blogContent = p.sub(”, data)
loopString = “(“+ str(blogID) + dbString2 +”‘”+ blogContent + “‘,” + “‘” + blogTitle + dbString3 + dbString4 + dbString5 + str(blogID) + dbString6

f.write(loopString.encode(encoding,”ignore”))
blogID = blogID + 1
loopString = “”

I did this at first by rreading through the XML, taking out all the apostrophe’s so that we dont get any errors while inserting into a the sql table. Also stored them into a file for future use. Not sure why I did this, ahh..mostly the imported on my wordpress was giving me some silly errors and not importing any of my posts.

posted by admin in python and have No Comments

Python replace carriage return and tab in a string

I wrote this script to replace all carriage return and tab in my wordpress database and put it in a PHP page.

import MySQLdb
conn = MySQLdb.connect (host = “localhost”,
user = “root”,
passwd = “”,
db = “test”)
cursor = conn.cursor ()
cursor.execute (“SELECT post_title,post_content FROM wp_posts”)
rows = cursor.fetchall ()
cnt =0
for row in rows:
f = open(str(cnt)+”.php”, ‘w’)
f.write(““);<br /> title = row[0];<br /> f.write(title);<br /> f.write(“

“);
f.write(“

“);
f.write(“
“);
f.write(“

“);
f.write(title);
f.write(“

“);
post = str(row[1])
post = post.replace(“\n”, “”).replace(“\r”, “
“)
f.write(post)
f.write(“

“);

#print “%s %s” %(row[0],row[1])
cnt = cnt+1
#if cnt > 2:
# break
print “Number of rows returned: %d” % cursor.rowcount

cursor.close ()
conn.close ()

posted by admin in Uncategorized and have No Comments

Facebook app development

My 0.02C that a novice facebook developers need to do, when developing a new application is look at this console given by facebook itself.

the links are below:

http://developers.facebook.com/tools.php

Basically the above has both php and XML links for developers to easily develop.

Attaching a screenshot below:

posted by admin in Uncategorized, python and have No Comments

Disabling searchindexer.exe on windows

I know how annoying it is. It sucks big time this tool developed by Microsoft which eats up all the memory on my computer. Even though its good to look for mails instantly on outlook, but it keeps increasing its memory usage.

You can disable it at startup only by the following registry keys:

HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesWSearch

Goto the above key and search for Start. In start Key type zero to disable searchindexer at startup only. But there is a catch to this, if you explicitly try to start the search indexer then this will enable the exe to start a service again. So you will have to use taskman to stop the service.

Tell me how it goes.

posted by admin in Uncategorized and have No Comments