Creating Gray-Code sequences using gimp

June 15th, 2009 admin No comments

I needed to implement gray-code sequences for a fringe projection system i'm trying to build. To avoid hard to understand and not really intuitive C-code, i used gimp to produce the projection images. In this article i'm going to document the code used.

First is the script-fu function to generate a picture with a given number of fringes or - alternatively - a given width of the period:

CODE:
  1. (define (script-fu-oan-create-fringes fwidth t fcount)
  2. (let*
  3.     (
  4.     (myimg (aref (cadr (gimp-image-list)) 0))
  5.     (mylayer (gimp-image-active-drawable myimg))
  6.     (layers (gimp-image-get-layers  myimg))
  7.     (channels (gimp-image-get-channels myimg))
  8.     (height (car (gimp-drawable-height (car mylayer))))
  9.     )
  10.     (if (= t TRUE) (set! fwidth (/ (car (gimp-drawable-width (car mylayer))) (* anzahl 2)))
  11.                     (set! fcount (/ (car (gimp-drawable-width (car mylayer))) (* breite 2)))
  12.     )
  13.     (define i 0)
  14.     (gimp-selection-all myimg)
  15.     (gimp-edit-clear (car mylayer))
  16.     (gimp-selection-none myimg)
  17.     (while
  18.         (<i fcount)
  19.         (gimp-rect-select myimg (* (* fwidth i) 2) 0 fwidth height CHANNEL-OP-ADD FALSE 0)
  20.         (set! i (+ i 1))
  21.     )
  22.     (gimp-edit-bucket-fill (car mylayer) FG-BUCKET-FILL NORMAL-MODE 100 0 FALSE 0 0)
  23. )
  24. )

Then there is the register-function call to enable the menu item for the function:

CODE:
  1. (script-fu-register
  2. "script-fu-oan-create-fringes"                              ;func name
  3. "Create Fringes"                                            ;menu label
  4. "Create an image of fringes\
  5.  "                                                          ;description
  6. "Omar Abo-Namous"                                           ;author
  7. "copyright 2009, Omar Abo-Namous"                           ;copyright notice
  8. "March 02, 2009"                                            ;date created
  9. ""                                                          ;image type that the script works on
  10. SF-VALUE "Fringe width:" "16"                               ;
  11. SF-TOGGLE "Use Fringe count" FALSE                  ;
  12. SF-VALUE "Fringe count:" "8"                            ;
  13. )
  14. (script-fu-menu-register "script-fu-oan-create-fringes" "<Image>/Xtns")

An older in-depth script-fu article by me.

3DMagix: Just Blender renamed

June 11th, 2009 admin 3 comments

Apparently some silly guy is trying to make fast money by selling the open source and free 3D-software package Blender. He's using the name 3DMagix, which is a pretty dumb name. The site doesn't look to reassuring to me, but there are lots of people (some i am ashamed to call 'close relatives') who would gladly fall for this kind of 'best deal' offers. So, be warned: If you want to check out some nice and really(!) free 3d modelling, animation, texturing and video editing software (and yet some), head over to Blender.org and download it for free without having to register or give out your credit card number.. Thanks to Blendernation for the heads-up.

Here are some screen captures of the site (perhaps the creator wants to sue me?

Categories: software Tags: ,

Working bridge on startup for Virtualbox

May 24th, 2009 admin No comments

I'm experimenting with a server running under virtualbox on my home computer. Here is the script running as /etc/rc.local that sets my bridge up and starts the virtualbox with the name 'seville':

BASH:
  1. ifconfig eth0 down
  2. ifconfig eth1 down
  3.  
  4. tunctl -u namous -t tap0
  5.  
  6. brctl addbr br0
  7. brctl addif br0 eth1
  8. brctl addif br0 tap0
  9.  
  10. ifconfig tap0 0.0.0.0 promisc
  11. ifconfig eth1 0.0.0.0 promisc
  12.  
  13. dhclient br0
  14.  
  15. vboxheadless -s seville &
  16.  
  17. exit 0

Categories: software Tags:

Wordpress 2.8 announced and installed

May 18th, 2009 admin 1 comment

The Wordpress version running on this blog is now "2.8-beta1-11380". After the first beta has been announced, i switched the svn installation to trunk again (after having it to branches/2.7) and updated the blog.

There is a problem with gengo though: Right after upgrading i got this warning:

CODE:
  1. Warning: Invalid argument supplied for foreach() in /.../wp-includes/classes.php on line 255

The line in question looks like this:

PHP:
  1. foreach ( $GLOBALS['wp_taxonomies'] as $taxonomy => $t)

I really didn't have the time to get into this, so in order to get the blog going, i used the workaround suggested here and changed the line to:

PHP:
  1. foreach ((array) $GLOBALS['wp_taxonomies'] as $taxonomy => $t)

Categories: Programming, php, wordpress Tags:

Wolfram Alpha goes public

May 18th, 2009 admin No comments

Wolfram Alpha is finally the computer we were waiting for. Not only does it compute mathematical problems really fast, but it tries to give us everything about the answer, that we would like to find out. It's like a wikipedia - just with more accurate information. Also, WolframAlpha is able to interpret user input and find out what the user is trying to find out by searching for the terms of a query in a semantic database: Weather in Guatemala, President in Germany or C6H6O.

Below the answer set that WolframAlpha delivers, there is the option for an output as pdf-file and a rather general information of where the information came from.

Great Mathematical Ressource

March 11th, 2009 admin No comments

I just found this nice educational ressource for numeric methods (i was specifically looking into LU decomposition).

Convert Gray-Code to decimal/binary and back

February 16th, 2009 admin No comments

Gray-Code is a binary code developed by Frank Gray in 1947. It is used by most absolute incremental encoders and some favor it's use for fringe projection systems that have to encode the pixel data in a series of image patterns (mostly fringes with differing widths). To convert Gray-Code from and to Decimal numbers using c++ i had to look up different approaches with varying difficulty levels. I then compiled the following algorithms, that i will be using for my own fringe projection system (keep tuned).

It's rather easy if you know how to do it. I had to find out the hard way, so here's for the rest of the world:

First the easy part: transforming a integer number dec into a Gray-code _code:

C++:
  1. void _calculateGrayCode () {
  2.     bitset<numeric_limits<int>::digits + 1> bs(dec);
  3.     bitset<numeric_limits<int>::digits + 1> gs(dec);
  4.     bitset<numeric_limits<int>::digits + 1> _code(0);
  5.     bs>>= 1;
  6.     gs ^= bs;
  7.     for (unsigned i=0; i<_code.size(); i++){
  8.         _code[i] = gs[i];
  9.         gs[i]=0;
  10.     }
  11. }

Now to the part of converting Gray-Code to binary and then decimal number: Suppose our Gray-code is inside the bitset _code.

C++:
  1. void _calculateNumber () {
  2.     bitset<numeric_limits<int>::digits + 1> gs(0);
  3.     bitset<numeric_limits<int>::digits + 1> bs(0);
  4.     for (unsigned i=0; i<_code.size(); i++){
  5.         gs[i] = _code[i];
  6.     }
  7.     bs[gs.size()-1] = gs[gs.size()-1];
  8.     for (int i=gs.size()-2; i>=0;i--){
  9.         bs[i]=bs[i+1];
  10.         bs[i]=bs[i]^gs[i];
  11.     }
  12.     _number = static_cast<int>(bs.to_ulong());
  13. }

bs holds the binary representation of the Gray-Code and _number is the decimal respresentation.

References:

Major crisis: some databases not readable

December 24th, 2008 admin No comments

Two days ago i was just about to reinstall the whole server (web, db, mail and fileserver). The reason was, that mysql was apparently not able to open most databases. The files were still there (under /var/lib/mysql), but only two databases which belonged to two gregarius-installations were accessible. I had just installed the aggregator at solidworks.toomuchcookies.net and had instructed the installer to create the database needed. I gave him root-access and also told him to access that database after that as root.

And that was the problem: The installation procedure involved creating the database and granting the user (in this case root himself) on localhost only rights to that database - not on all databases. After that the mysql.users table had a line which granted root/password/localhost only access to two databases and another line which granted root/password/bigcook root access to all privileges. The second line came first and was therefor ignored. I even wasn't able to access the mysql-database, which hods information about the user privileges..

To solve the problem (after an hour and a half of desperate searching and trying to 'recover' the data) i had to start mysql with the "--skip-grant-tables" parameter.

CODE:
  1. /etc/init.d/mysql stop
  2. mysqld --skip-grant-tables &

This is a rather dangerous mode and should be handled with care, since it instructs mysql to ignore the privilege table and allow all users access. I used this mode to verify that the databases were still there and then moved on to see the mess created in the mysql.users table. By removing the second grant line, the server was finally able to read all the databases. Phew!

Don't forget to stop the server and restart as daemon:

CODE:
  1. killall mysqld
  2. /etc/init.d/mysql start

Categories: software Tags: ,

Postfix: sender_bcc_maps

December 19th, 2008 admin No comments

For an email account for a group project, we needed the ability to see what was being sent via a specific email account. The reason was, that we're going to handle the account data very liberally and therefor to avoid misuse of the account, we needed an automatic forward of all emails that were sent from this account to some screening account.

I thought i would need to script some piping instructions but actually it was much easier: Using the command sender_bcc_maps i could simply define that any email sent by x@x.com would be bcced to the same account. Now, that account has an automatic forward to some aliases. So anytime someone sends an email from x@x.com all the aliases (outside emails) would get a notice.

To setup sender_bcc_maps, i needed to setup a hashtable that looked like this:

CODE:
  1. bcc_maps
  2. x@x.com   x@x.com

After "postmap bcc_maps" i had to include the command in main.cf, that looks like

CODE:
  1. sender_bcc_maps = hash:\etc\postfix\bcc_maps

That did the trick. Thanks to miniGeek, Linox.BE and of course the Postfix team.

Categories: software Tags: , ,

Pingbacks and Trackbacks work again in Wordpress

December 18th, 2008 admin No comments

For quite some time, i had a problem getting pingbacks and trackbacks working. Receiving them wasn't a problem, but i couldn't send any. It seems, i'm not alone and no where were any answers to be found..

I think i found the problem: the function spawn_cron (/wp-includes/cron.php, 153) opens a socket to then wp-cron.php file after adding a new scheduled item. For that reason it runs the function wp_remote_post which also accepts a timeout parameter. That parameter is set to 0.01 by default. I guess these are seconds (which means these are 10 milliseconds!) and for some webservers this value is simply too small. Change that to something bigger (i'm using 0.1 or 1) and pingbacks and trackbacks should work again..

Now what about the old trackbacks and pingbacks that didn't get sent? Actually you'll simply need to write a new post and all the old unsent pings should be scheduled for sending. If you don't want to do that, you could install the plugin Wp-Crontrol where you can specify a hook to be scheduled to a specific time. Schedule the hook "do_pings" to be triggered any time soon (parameter should be empty = "[]") and it should take care of the old pingsbacks.