Archive for the 'how-to' Category

29th Apr 2008

Ouch

I went to check my site a few minutes ago and found that any page I tried to access returned a “403 Forbidden” error. scary. So I spent a panicked 5 minutes checking error logs, .htaccess files, file permissions, folder permissions…of course the last thing I checked was the permissions on my public_html folder. It seems my host hiccupped and changed the public_html folder’s permissions to 0750…so it was a quick fix (once I found it), but; note to self — check the public_html permissions first.

Posted in how-to, web | No Comments »

16th Feb 2008

Install Python module without root privileges

By default, python tries to install modules to the /usr/lib/pythonXX directory, which is write protected for any user other that root. Here’s how to get around that limitation:

In my case, I will be installing sqlite onto a web server, and so will be doing this all through cgi scripts. It shouldn’t be much different for other situations, though.

The short answer is:

run “python install.py –prefix=/home/username”

whenever you want to use the module, put this at the top of your file:

import sys
sys.path.append('/home/jabapyth/lib64/pythonX.X/site-packages')

For the long answer (how I did it),

Run this file:

#!/usr/bin/python
print "Content-type: text/html\n"

from urllib import urlopen as upen
import tarfile
import os

## the source archive URL
archive = "http://initd.org/pub/software/pysqlite/releases/2.4/2.4.0/pysqlite-2.4.0.tar.gz"

## download the archive
open("pysqlite.tar.gz","w").write(upen(archive).read())

## extract it
tr = tarfile.open("pypy.tar.gz","r:gz")
for m in tr.getmembers():
    tr.extract(m)

## run the installer
import os
os.chdir("pysqlite-2.4.0")
## this is the relevant line for most people: pass --prefix=/home/username to the install file
res = os.popen("python setup.py install --prefix=/home/jabapyth").read()
print res

Run that file, and the module will be installed

again, you will need to put this at the top of any file into which you want to import this module:

import sys
sys.path.append('/home/username/lib64/python2.4/site-packages')

Posted in how-to, python, web | No Comments »

14th Feb 2008

VensterCE: Hello World, again

In this tutorial, we are actually going to make a window, although we will still just be saying “Hello, World”

The Code

from venster.ce import *

class MyWindow(CeMainWindow):
    _window_title = u"Hello World, again"

    @msg_handler(WM_CREATE)
    def OnCreate(self,event):
        self.sizer = BoxSizer(VERTICAL)
        text = StaticCenter(u"Hello World", parent=self)
        self.sizer.append(text)
        CeMainWindow.OnCreate(self,event)

def main():
    mainForm = MyWindow()
    mainForm.ShowWindow()
    application = Application()
    appliation.Run()

if __name__ == "__main__": main()

Step by Step

class MyWindow(CeMainWindow):
    _window_title = u"Hello World, again"

This is the class definition of the main window. It inherits from CeMainWindow, which was imported from venster.ce at the top. “_window_title” is a class variable, and representing the title of your window. Once again, be sure to use unicode (prepend the string literal with a “u” or convert with the unicode(str) function), or it will come out looking like garbage.

    @msg_handler(WM_CREATE)
    def OnCreate(self,event):
        self.sizer = BoxSizer(VERTICAL)
        text = StaticCenter(u"Hello World", parent=self)
        self.sizer.append(text)
        CeMainWindow.OnCreate(self,event)

the @msg_handler(WM_CREATE) is a decorator function, setting this function up as the message handler for the WM_CREATE function; the effect being that this function is called as soon as the window is created.
self.sizer (the name is important) is our main widget sizer — all widgets we create should be appended to it, or one of its children.
There are 4 classes of static text: Static, StaticLeft, StaticCenter, and StaticRight. They all take the same arguments.
Finally we call the parent class’ OnCreate to finish setting up the window.

def main():
    mainForm = MyWindow()
    mainForm.ShowWindow()
    application = Application()
    appliation.Run()

if __name__ == "__main__": main()

These lines of code will probably be at the end of all your programs; they “create” the window and start th eapplication running.

Posted in axim, how-to, pocketpc, python, windows mobile | No Comments »

06th Feb 2008

Sync Windows Mobile with Ubuntu

time-saving tip: if you don’t want this all explained to you, you can just download and execute this bash script.

First you need to install SynCE:
Add these lines to your apt sources (type “sudo kate /etc/apt/source.list” and paste these at the bottom)

deb http://ppa.launchpad.net/synce/ubuntu gutsy main
deb-src http://ppa.launchpad.net/synce/ubuntu gutsy main

Install the USB Driver

sudo apt-get install usb-rndis-source cdbs
sudo module-assistant auto-install usb-rndis

Install ODCCM (the connection manager)

sudo apt-get install odccm librra0-tools librapi2-tools

Now we need to install MultiSync (a gui that manages the syncing process)

sudo apt-get install multisync libmultisync-plugin-backup libmultisync-plugin-irmc libmultisync-plugin-evolution synce-multisync-plugin

Now that you’re done installing everything, type “sudo odccm -f” into the konsole to start the connection manager, and plug in device (your device should now recognize that it is connected). To manage the syncing, open up MultiSync (Start Menu->Utilities->MultiSync) and create a new sync pair with the plugins “SynCE Plugin” and “Ximan Evolution 2″. Press sync, and you’re done!

If you dont use evolution, you can get other plugins for MultiSync at their website.

Posted in axim, how-to, pocketpc, ubuntu, windows mobile | No Comments »

05th Feb 2008

CeGCC Hello World

First, copy this into a file “hello.c”

#include <windows.h>
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
{
          MessageBox(0, L"Hello!", L"CeGCC says...", MB_OK);
}

Here we have the generic MessageBox function, but with one twist: because we are in unicode, we need to prepend all string literals with ‘L’ (we could use the _T(”mystring”) macro, but I think it looks more ugly). If you try do compile

MessageBox(0, "Hello!", "CeGCC says...", MB_OK);

You will get an error complaining something about converting to LPCWSTR (meaning it wants unicode and didn’t get it).
To compile this source (you need to have first installed CeGCC), enter this at command line:

arm-wince-mingw32ce-gcc hello.c -o hello.exe

You can then copy the .exe file over to your Windows Mobile device and double click on it in the file manager to run your first program!

Posted in axim, c, how-to, ubuntu, windows mobile | No Comments »

30th Jan 2008

VensterCE: Hello World

In keeping with tradition, lets start off with a simple “hello world”

from venster.ce import *
msg = MessageBox(None,u"Hello World",u"Venster Says",MB_OK);

First line:

from venster.ce import *

This merely includes the basic functions and classes from the venster library. We will use this in every program.

msg = MessageBox(None,u"Hello World",u"Venster Says",MB_OK);

Here create a simple messagebox and store the return value in the variable “msg”. The function definition for MessageBox is MessageBox(window,message,title,buttons). Here the parent window is None, as we haven’t created one (It’s ok, windows can handle that). Next are the Message and Title strings, but make sure you keep them unicode (bad things can happen if you dont). The “buttons” variable is combination of flags. A few popular ones are MB_OK, MB_OKCANCEL, and MB_HELP for buttons, and MB_ICONWARNING and MB_ICONINFORMATION for the icon. For a full reference of the different flags, go Here.

Posted in axim, c, how-to, pocketpc, ubuntu, windows mobile | No Comments »

24th Jan 2008

VensterCE: installation

To use the vensterce library you first need python, so (If you haven’t already) go ahead to the PythonCE Download Page and get either the installer or the CAB file (you choose :). Then you can fetch VensterCE zip archive from here. Inside that zip file you will find several things:

  • “venster”: this folder is the actual library. Copy it into your python library (Usually \Program Files\Python25\Lib\
  • “tutorial”: here is contained 5 “tutorial” files along with an html page describing them, although I’ve found this “tutorial” to be more of a quick-start for those already proficient with C++ win32 programming
  • the contents of the “shared” folder need to be copied into the \Windows directory on your device.
  • “pyceide”: this is an advanced python IDE, built in VensterCE. All you need to do is double-click on the “pyceide.pyw” file and it will run.

That should be all that’s necessary. From now on you can “import venster”.

Posted in how-to, pocketpc, python, windows mobile | No Comments »

21st Jan 2008

Ubuntu Locked Folders

The quick and simple way to “unlock” a locked folder in (k)ubuntu and probably most *nix.

$ sudo chown yourusername: /path/to/locked/folder

If the folder isn’t locked by root, i believe this will work:

$ su owneruname chown yourusername: /path/to/locked/folder

(source: http://ubuntu-utah.ubuntuforums.org/showthread.php?t=642406)

Posted in how-to, ubuntu | No Comments »

21st Jan 2008

Kubuntu Gutsy mount error

I finally got around to installing Gutsy on my PC, and was aghast that it gave me errors while trying to mount an external drive! I thought, how could an os exist that couldnt mount drives? The error I got was “hal-storage-fixed-mount refused uid 999″. After poking about online a bit, however, I found how to fix it:
go to System Settings>advanced tab>Disks and Filesystems
There you can find the offending drives, and click modify (you need to to be in ‘administrator mode’). There, give it a mount point (just make up a name, eg /dev/myhdd), make sure “writeable” and “enable at startup” are checked, and select “anyone may enable/disable at anytime”. Then you’re done!
http://languor.us/hal-storage-fixed-mount-refused-uid-1000

Posted in how-to, ubuntu | No Comments »

28th Dec 2007

Cross-Compiling for Windows Mobile on Ubuntu

There are a few compilers I’ve found that will do this:

  • the (only for windows) Pelles C compiler through WINE
  • the PocketPC-GCC ubuntu package
  • the CeGCC cross-compiler for pocketpc

Pelles C

Pelles C is a great IDE, not only for windows mobile, but also for windows smart phone and regular old windows. My only objection to it is that it takes really, really long to compile even the simplest programs. Now, this might seem a small failing to some, but having to wait up to a minute for hello world to compile drives me nuts, especially since the others compile soo much faster.
Links:

PocketPC-GCC

This package is great for general C, and (though I haven’t tried this) might be excellent for porting linux apps to the PocketPC. Unfortunately, It doesn’t come with the windows headers/libs (these can probably be added, but I’m lazy, and CeGCC comes with them pre-loaded). In a few days I will probably experiment with getting Win32 programming to work with this compiler, so check back to see if I’m successful ;).
To install this, just do “sudo apt-get install pocketpc-gcc”. You might want to install pocketpc-g++ and pocketpc-sdk as well. I haven’t found any docs/tutorials/etc. for this package, witch is part of the reason I’m hesitant to use it.

Update: On closer inspection, I’ve found that this compiler results in massively bigger files: For the standard “helloworld.c”, the resulting exe was 338kb! in contrast to the 10kb exe compiled by CeGCC ;). Thats it, I’m definitely sticking w/ cegcc.

CeGCC

This is my champion for the moment, and the one I’m leaning win32 c on. It comes with the windows and pocketpc specific headers (though no directx or opengl). This will be the one that I will be using in my upcoming tutorials.
Links:

My CeGCC Tutorials:

Posted in axim, c, how-to, pocketpc, ubuntu, windows mobile | No Comments »