wilmens™

by William W. Mensah

XML vs. HTML tags;

  • Tuesday Jul 14,2009 10:01 AM
  • By wmensah
  • In Thoughts

Supposing you have a string in your xml file that contains html tags for whatever reason (perhaps you want the content of the string to be displayed in html format at some point), be sure to replace all ‘<’ with ‘&lt;’ and all ‘>’ with ‘&gt;’ .

So basically, a string such as “<b>Hello World!</b><br>Now what?” would have to be changed to “&lt;b&gt;Hello World!&lt;/b&gt;&lt;br&gt;Now what?”

Ugly? You bet!! but it’s your best bet! To avoid getting dizzy, you might want to select the string and perform a find & replace on this kind of stuff. Otherwise you might spent hours trying to figure out why your xml script is not working.

GRE/GMAT vocabulary list

Provided is a bunch of words (1000+) that you might encounter on the GRE/GMAT. You’ll need (or can use) Flash Card Manager to use the attached file.

Vocabulary List

Big ups to the creators of Flash Card Manager – that is one handy software!!!

Locate32

  • Tuesday Jun 9,2009 09:56 AM
  • By wmensah
  • In Stuff

Best search tool you can ever award your computer with!

http://www.locate32.net/

Enterprise Content Management (ECM) meets Web 2.0

Clueless about what ECM or Web 2.0 is? Check out these great videos I came across on YouTube – the first explaining what ECM is, the second explaining what Web 2.0 is and how it came about and the last video explaining how the 2 are (or might be) integrated.

Enterprise Content Management

Web 2.0

ECM + Web 2.0

myDiary 4.5 Beta 2 running on Windows 7 RC

Below is a screenshot of myDiary running on Windows 7 installed on Virtual Box as a guest on Windows Vista. Don’t worry, my laptop can take it. Besides, Windows 7 looks and feels very light. I think it looks great and compared to Vista, it’s very fast. The graphics look neat and polished and the animations and transitions makes your PC smile with pride like it’s running on a fresh set of hardware :)

Anyways, before I get carried away, myDiary 4.5 Beta 2 does work on Windows 7 just like it does on Vista. If you ‘hate’ Windows Vista or are still in the process of divorcing Windows XP, then partition your hard drive or get a copy of Virtual Box and install Windows 7. So far, from what I’ve seen, it’s worth trying it out.

I had to get Firefox though. Internet Explorer was getting on my nerves. It crashed a couple of times because I tried to read a PDF file with Adobe (which isn’t fully compatible yet). Come on, PDF files? Well, I installed Firefox and it worked like a charm. All the same, Windows 7 is great!

myDiary 4.5 on Windows 7

You can obtain a copy of Windows 7 RC for free from www.microsoft.com

Palm Pre

Can’t wait till that bad boy is released. I currently have a Palm Treo running windows mobile 5, and I mean it’s a great phone and all but I could sure use something new – something webOS :) . I’m not an iPhone person, probably because I’m not with AT&T, and also because I’m not into the whole virtual keyboard thing. My iPod touch gets me frustrated enough – especially when I’m trying to backspace and keep hitting the L key – uuuggh!!!! This post is not an iPhone vs. Palm Pre opinionated argument. You can find a lot of them online. I’m just interested in the Pre and everything about it – webOS, Mojo SDK etc. so I suppose you can say I’m prethinking…

www.prethinking.com

Ever used Pygtk’s filechooser widget and wanted to have Back, Forward and Up navigation buttons to go with it? The filechooser widgets acts weird sometimes, for instance when you open a new folder, the folder_changed signal is received twice, sometimes once which is very inconsistent and difficult to work with. Spent hours Googling (to Google means to search for something on the internet – Oxford dictionary – soon) a solution in vain so I finally decided to put my brain to work. If you’re reading this post then chances are that you’re either looking for a solution or just a big fan of my blog :)

The script below assumes you’re designing a GTK GUI with Python as your scripting language, have a filechooser widget placed somewhere on it, and want to add some navigation buttons (basically back, forward and up, and maybe reload – just like a file browser) and need some script to get them to work. Here are a few things you’ll need before we proceed.

A stack class:

#!/usr/bin/env python

class Stack:
   def __init__(self):
       self.data = []
       self.size = 0

   def push(self,item):
      self.data.append(item)
      self.size = self.size + 1    

   def pop(self):
       if self.size > 0:
           self.size = self.size - 1
       return self.data[self.size]    

   def is_empty(self):
      return self.size == 0

   def is_full(self):
      return self.size == len(self.data)

   def top(self):
       return self.data[self.size-1]

   def item_at(self, pos):
       return self.data[pos-1]

   def count(self):
       return self.size

   def clear(self):
      self.data = []
      self.size = 0

   def elements(self):
       #displays all elements in the stack
       for x in range(0, self.size):
           print self.data[x]

- with the stack class in hand and ready to go, you’ll need to create 2 stacks (each an instance of the stack class) one for back history, and the other for the forward history (in my example I called them back_stack and fwd_stack respectively).

- note that in the code below, the filechooser widget is called, well, “filechooser”.

guru = gtk.glade.XML("your_glade_file.glade")

class WidgetsWrapper:    

    current_folder = guru.get_widget("filechooser").get_current_folder()
    back_stack = stack.Stack()
    fwd_stack = stack.Stack()
    back_size = 0 #used to determine when folder_changed occurs.
                       #if not == back_stack.count() that means back button was clicked.

    def __init__(self):
        signalDic = {"on_filechooser_current_folder_changed" : self.folder_changed,
                     "on_btnReload_clicked" : self.reload_dir,
                     "on_btnBack_clicked" : self.goBack,
                     "on_btnForward_clicked" : self.goFwd,
                     "on_btnUp_clicked" : self.goUp}

        guru.signal_autoconnect(signalDic)
	#code to show the main window goes here;
        #ie. guru.get_widget("main_window").show(), something so.

    def folder_changed(self, widget):
        filechooser = guru.get_widget("filechooser")
        if WidgetsWrapper.back_size == 0 or
            WidgetsWrapper.back_stack.count() == WidgetsWrapper.back_size:
            #the line below makes sure the current folder doesn't get added to
            #back_stack after folder is changed.
            if WidgetsWrapper.current_folder <> filechooser.get_current_folder():
                WidgetsWrapper.back_stack.push(WidgetsWrapper.current_folder)
                guru.get_widget("btnBack").set_sensitive(True)

            #should fwd_stack be cleared?
            if WidgetsWrapper.fwd_stack.count() > 0 and
                (WidgetsWrapper.back_stack.count() > WidgetsWrapper.back_size):
                WidgetsWrapper.fwd_stack.clear()
        WidgetsWrapper.back_size = WidgetsWrapper.back_stack.count()
        WidgetsWrapper.current_folder = filechooser.get_current_folder()

        #set button sensitivity
        #back button
        if WidgetsWrapper.back_stack.count() == 0:
            guru.get_widget("btnBack").set_sensitive(False)
        #forward button
        if WidgetsWrapper.fwd_stack.count() == 0:
            guru.get_widget("btnForward").set_sensitive(False)
        #up button
        if os.path.dirname(WidgetsWrapper.current_folder) == WidgetsWrapper.current_folder:
            guru.get_widget("btnUp").set_sensitive(False)
        else:
            guru.get_widget("btnUp").set_sensitive(True)

    def goBack(self, widget):
        cnt = WidgetsWrapper.back_stack.count()
        if cnt > 0:
            WidgetsWrapper.current_folder = guru.get_widget("filechooser").get_current_folder()
            setdir = WidgetsWrapper.back_stack.pop()
            WidgetsWrapper.fwd_stack.push(WidgetsWrapper.current_folder)
            try:
                guru.get_widget("filechooser").set_current_folder(setdir)
                guru.get_widget("btnForward").set_sensitive(True)
            except:
                pass
        else:
            guru.get_widget("btnBack").set_sensitive(False)

    def goFwd(self, widget):
        cnt = WidgetsWrapper.fwd_stack.count()
        if cnt > 0:
            setdir = WidgetsWrapper.fwd_stack.pop()
            WidgetsWrapper.back_stack.push(str(guru.get_widget("filechooser").get_current_folder()))
            try:
                guru.get_widget("filechooser").set_current_folder(setdir)
                guru.get_widget("btnBack").set_sensitive(True)
                WidgetsWrapper.back_size = -1 #avoid folder_changed evaluation
            except:
                pass
        else:
            guru.get_widget("btnForward").set_sensitive(False)

    def goUp(self, widget):
        WidgetsWrapper.current_folder = guru.get_widget("filechooser").get_current_folder()
        WidgetsWrapper.back_stack.push(WidgetsWrapper.current_folder)
        try:
            x = guru.get_widget("filechooser")
            x.set_current_folder(os.path.dirname(WidgetsWrapper.current_folder))
            guru.get_widget("btnBack").set_sensitive(True)
            WidgetsWrapper.back_size = -1 #avoid folder_changed evaluation
            WidgetsWrapper.fwd_stack.clear()
        except:
            pass

    def reload_dir(*args):
       x = guru.get_widget("filechooser")
       x.set_current_folder(guru.get_widget("filechooser").get_current_folder())

    def print_stacks(*args):
        print ""
        print "back_stack elements:"
        print "...................."
        WidgetsWrapper.back_stack.elements()
        print ""
        print "count: ", WidgetsWrapper.back_stack.count()
        print "fwd_stack elements:"
        print "..................."
        WidgetsWrapper.fwd_stack.elements()
        print ""

The code could use some improvement but bottom line is that it works. Just be sure to change the string in line 1 to the name of your glade file. The print_stacks function simply displays the current contents of the 2 stacks. Use it for debugging.

Hope this helps someone.

miniRCS

I’ve commenced on the development of a revision control system that supports ftp servers. Being open source, the script can be obtained from here.

To use it, you’ll have to copy and paste the file into your favorite text editor and then save it as a python file (.py). From there you can run it using Python (if you don’t already have it on your computer, download and install it).

Mess around with the code as much as you can. In addition to the source code, I’ve provided a public repository you can use for testing. You’ll have to get a user name and password from me (to do so contact me at support@wilmens.net). If you have your own ftp server, replace mine with yours in the script.

Feel free to contact me if you have any questions.

have fun :)

Get a SQLite Vacuum and vacuum my table!

What happens when you delete a record from a SQLite database table that has a primary key attribute which autoincrements? Do the rest of the records after the deleted record get shifted back one step? Or do you end up with a break in your table. Well as far as I’ve discovered, in SQLite3, you end up with breaks in your table. For instance, if you had data in your table like so:

record1, record2, record3, record4

(note: select count(*) from [table_name] gives 4)

and you delete record2, you end up with

record1, , record3, record4

(note: select count(*) from [table_name] still gives 4)

but that’s not reasonable because you didn’t want the record anymore and deleted it. I mean, that is why you deleted it, right? If you wanted a blank row you could have replaced the record with blank spaces. Inserting new data doesn’t even take advantage of the empty space, so if you keep deleting records and inserting new data, you can image what your table will look like.

That’s when you need to vacuum! Yup, vacuum. Oh and the nice thing is, you don’t have to do it yourself; you just have to issue the command :)

In SQLite, just execute the command “vacuum” after deleting a record and the table gets cleaned up nice. If you don’t want to keep doing this, before you create any tables in the database, set pragma auto_vacuum to 1 (on) and that will take care of it for you.?This also takes care of reordering your rowids. As a result,?doing a select * from [table_name] will now give us:

record1, record3, record4

(note: select count(*) from [table_name] gives 3, aah, much better).

This doesn’t seem to work when you have?an integer?primary key so you might have to do without it or use a different attribute (non-integer) as a primary key. It can save you a lot of frustration trying to figure out why your tables are acting weird.

more information here:

http://marc.info/?l=sqlite-users&m=118061508921524&w=2

myDiary 4.3 Linux

  • Tuesday Nov 4,2008 10:52 AM
  • By wmensah
  • In myDiary

Above is a screenshot of myDiary 4.3 for Linux running on Ubuntu 8.10 (Intrepid) with?Santay theme pack?0.3.1??(GTK 2.x Theme/Style) created by?Jose Javier Espinoza.

WordPress Loves AJAX