2008-11-29

 

State of OpenSource Hardware in 2008

There's a nice summary over at MakeZine

 

Linux on the iPhone

The Linux 2.6 kernel now runs on the iPhone :-)


iPhone Linux Demonstration Video from planetbeing on Vimeo.

2008-11-26

 

Why do people still use Internet Explorer ???

Many people probably just don't know there are other browsers... Perhaps they don't know how to get/install other web browsers... Whatever the reason, they are missing out!

Since Chrome is currently only Windows based, I will gladly settle for my Firefox 3 browser, as it didn't do that bad at all.

Well done Google!

Follow up: Also be sure to check out Lunascape - a triple engine browser!

2008-11-25

 

The snake bites it's tail

I have finally hit some sore points in my Python programming experience I don't like at all:

Point nr 1: How Python handle NULL values. I am of course not the first to hit this little problem... This is particularly confusing when dealing with databases. A DB query could return one field in one row of which the value is NULL, or, no rows could be returned at all. In both cases you will have a "None" condition, but you need some logic in your app to figure out the where and why you get the "None". Very irritating indeed...

Point nr 2: Then there is the MySQLdb problems, like the BLOB problem noted here... Only, I got the same issue on BIG INT values as well. From the status of the noted problem you will note that the maintainers of the MySQLdb module does not intend fixing this, so again you need a lot of application side logic to deal with these problems.

Point nr 3: I still long for the way Perl deals with variable types - just have scalars, arrays and hashes - nothing else. I am ending up converting almost all output of variables to strings using the str() function, as you just don't always know when a variable is not a string. The annoying part is that it doesn't always work - refer to point 2. Of course this adds more CPU calls and still more logic you need in your application to deal with all these strange things.

So what is one to do?

Well - I will probably have to write my own wrapper module around MySQLdb in order to get the values I want in the way I want it, and hide all the complexities in the wrapper module.

Watch this space...

2008-11-07

 

Started a new dedicated Python site

Check it out on http://sites.google.com/site/pythonbits/

Will be adding more and more stuff there over time.

2008-11-03

 

RFC 1123/822 dates in Python

Quick solution:
import datetime
.
.
.
datetime.datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S GMT")


References:

2008-09-20

 

Low latency sound recording - Linux RT Kernel

Here is a nice intro on how to set-up near real time components in the Linux kernel. In this specific demonstration the author demonstrates how to get less then 3ms latency on audio recording - something Operating Systems for home users can not generally do.





Also make sure to read the comments from Dave Phillips at the bottom of the page...

 

Python tip: base conversions

Sometimes you may require to convert between base systems, for example from Octal to BASE10, as may be required when you use the os.mkdir or os.makedirs functions.

Here is a simple script demonstrating a possible implementation:

#!/usr/bin/python

BASE2 = "01"
BASE8 = "01234567"
BASE10 = "0123456789"
BASE16 = "0123456789ABCDEF"
BASE62 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"

def baseconvert(number,fromdigits,todigits):

""" converts a "number" between two bases of arbitrary digits

The input number is assumed to be a string of digits from the
fromdigits string (which is in order of smallest to largest
digit). The return value is a string of elements from todigits
(ordered in the same way). The input and output bases are
determined from the lengths of the digit strings. Negative
signs are passed through.

decimal to binary
baseconvert(555,BASE10,BASE2)
'1000101011'

binary to decimal
baseconvert('1000101011',BASE2,BASE10)
'555'

integer interpreted as binary and converted to decimal (!)
baseconvert(1000101011,BASE2,BASE10)
'555'

base10 to base4
baseconvert(99,BASE10,"
0123")
'1203'

base4 to base5 (with alphabetic digits)
baseconvert(1203,"
0123","abcde")
'dee'

base5, alpha digits back to base 10
baseconvert('dee',"
abcde",BASE10)
'99'

decimal to a base that uses A-Z0-9a-z for its digits
baseconvert(257938572394L,BASE10,BASE62)
'E78Lxik'

..convert back
baseconvert('E78Lxik',BASE62,BASE10)
'257938572394'

binary to a base with words for digits (the function cannot convert this back)
baseconvert('1101',BASE2,('Zero','One'))
'OneOneZeroOne'

"
""

if str(number)[0]=='-':
number = str(number)[1:]

neg=1
else:
neg=0

# make an integer out of the number

x=long(0)
for digit in str(number):

x = x*len(fromdigits) + fromdigits.index(digit)


# create the result in base 'len(todigits)'
res=""
while x > 0:
digit = x % len(todigits)

res = todigits[digit] + res
x /= len(todigits)

if neg:
res = "-"+res

return res

print "'700' octal (base8) is '" + str( baseconvert( 700, BASE8 ,BASE10 ) ) + "' in base10"



If you now want to make a directory with a create mode of 700 (octal) you will call
os.makedirs( "/tmp/test/path", baseconvert( 700, BASE8 ,BASE10 ) )
Until next time then... Need to get back to some coding :-)

2008-09-19

 

Fix for mod_bw when getting an error "undefined symbol: apr_atomic_cas"

I downloaded the Apache module mod_bw to see if I could simulate some "slow" connections. To compile the package you need to run the following command as root:
# apxs -i -a -c mod_bw.c

That will install the module correctly, but when you add the configuration option to your vhost configs you might get an error "undefined symbol: apr_atomic_cas". When that happens, open the file mod_bw.c and change the following:

Before:
/* Compatibility for ARP < 1 */
#if (APR_MAJOR_VERSION < 1)
#define apr_atomic_inc32 apr_atomic_inc
#define apr_atomic_dec32 apr_atomic_dec
#define apr_atomic_add32 apr_atomic_add
#define apr_atomic_cas32 apr_atomic_cas
#define apr_atomic_set32 apr_atomic_set
#endif


AFTER

/* Compatibility for ARP < 1 */
/*
#if (APR_MAJOR_VERSION < 1)
#define apr_atomic_inc32 apr_atomic_inc
#define apr_atomic_dec32 apr_atomic_dec
#define apr_atomic_add32 apr_atomic_add
#define apr_atomic_cas32 apr_atomic_cas
#define apr_atomic_set32 apr_atomic_set
#endif
*/






This page is powered by Blogger. Isn't yours?