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...
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:
If you now want to make a directory with a create mode of 700 (octal) you will call
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:
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:
AFTER
# 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
*/
2008-09-12
Why you can't trust Wikipedia...
It's amazing how wrong data can be on the WWW, yet most people belief everything they read :-) Wikipedia is often criticized for it's inaccurate information, yet it is used in many academic references.
Take this entry on the DNA Computer on Wikipedia as an example: the author claims that the "field was initially developed by Leonard Adleman of the University of Southern California, in 1994."
But, if you wonder of to the National Geographic web site, you will discover an article dated 23 Feb 2003: "Israeli scientists have devised a computer that can perform 330 trillion operations per second, more than 100,000 times the speed of the fastest PC. The secret: It runs on DNA."
I think that proofs the theory that you should NOT trust anything on Wikipedia. Do much more research on your subject then just Wikipedia!
Take this entry on the DNA Computer on Wikipedia as an example: the author claims that the "field was initially developed by Leonard Adleman of the University of Southern California, in 1994."
But, if you wonder of to the National Geographic web site, you will discover an article dated 23 Feb 2003: "Israeli scientists have devised a computer that can perform 330 trillion operations per second, more than 100,000 times the speed of the fastest PC. The secret: It runs on DNA."
I think that proofs the theory that you should NOT trust anything on Wikipedia. Do much more research on your subject then just Wikipedia!
2008-09-10
Oracle install HOWTO
I finally completed the detailed Oracle install HOWTO as described in an earlier post.
2008-09-07
Oracle 11g Enterprise on Ubuntu
Took me the whole of 1 day and lot's of reading :-)
I first tried to play with Oracle in VMWare, but it was DOG SLOW !!! To give you an idea, my Laptop is a dual core 2.4GHz with 4GB RAM, and it becomes virtually unusable after running in a CentOS VMWare session, where the session was allocated 1.5GB RAM and some RAW disk.
The thing is I don't want to mess anything up, so if I can't use a Virtual Machine, I guessed I could do it using something like debootstrap.
I ended up combining these two resources for the final solution:
In terms of system usage, it's still heavy but at least my Laptop is still very responsive. I found that one CPU Core is always at 100% usage, with 45% of time in IO WAIT state - so not ideal really, but ok for a experiment/learning environment. BTW: I use the Dell XPS m1530...
I first tried to play with Oracle in VMWare, but it was DOG SLOW !!! To give you an idea, my Laptop is a dual core 2.4GHz with 4GB RAM, and it becomes virtually unusable after running in a CentOS VMWare session, where the session was allocated 1.5GB RAM and some RAW disk.
The thing is I don't want to mess anything up, so if I can't use a Virtual Machine, I guessed I could do it using something like debootstrap.
I ended up combining these two resources for the final solution:
- https://wiki.ubuntu.com/DebootstrapChroot - To get my chroot environment up and running
- http://www.pythian.com/blogs/968/installing-oracle-11g-on-ubuntu-804-lts-hardy-heron - To install Oracle 11g on my new Ubuntu Hardy chroot environment
In terms of system usage, it's still heavy but at least my Laptop is still very responsive. I found that one CPU Core is always at 100% usage, with 45% of time in IO WAIT state - so not ideal really, but ok for a experiment/learning environment. BTW: I use the Dell XPS m1530...