Archive

Archive for the ‘Programming’ Category

Contact Form for wordpress

February 23rd, 2010 admin No comments

For a client of mine, i’ve been using the PEAR-package HTML_QuickForm which is ’superseded’ by now and isn’t compatible to php 5.2, whereas the followup package HTML_Quickform2 is still in alpha state. Since the client switched his server and that is running php 5.2, i had to come up with a new solution. I tried out many wordpress contact-form-plugins but they all did not satisfy me fully.

The only form-plugin that i truly would recommend is cForms II. It is flexible, can handle more than one form template. Forms can be inserted via template files or via tags inside posts or pages. I think this is the only plugin that supports individual Fieldsets (this can be very handy for designing complex layouts). The verification of the user input is done with very individual regular expressions. The admin can set Form field name, tooltip and default value and even let the default value be auto-cleared once the form field is activated. cForms II supports multi-page forms (which i didn’t use, though) and it can autoconfirm emails to the user (which i didn’t use either). Spam detection is done not only with the individual regular expressions, but also with a captcha-plugin or alternativey with a simple Q&A-field (like, ‘what color is snow?’). The possible questions for the Q&A field can be set manually. You can even backup and restore the form settings! Furthermore the admin can chose from a dozen css-layouts and manually change them.

Here are the other plugins, that i tried out:

  • Contact Form 7: It didn’t seem to have a template tag, that i could use in the theme files.
  • Form Builder: Very bad design. It features div-tags that are floated. If your design uses floating objects, it will break it or be broken itself!
  • Scaleable Contact Form plugin: Nearly no option to verify the user input. Supports Captcha, but it uses the plugin “simple captcha” for that, which doesn’t seem to support wordpress 2.9.
  • Spam-Free Contact Form: simply crap. don’t use that.
  • Visitor Contact: only interesting, if you like using external web applications on your own blog.
Categories: Programming, php, wordpress Tags: , ,

Scavenged pen-plotter Roland DG DXY-990

November 20th, 2009 admin No comments

Yes! I've managed to scavenge an old pen-plotter that was obviously gathering dust down in the basement of our institute. Last time i've seen such a plotter was in the 1980s at the institute where my father used to work. Back then, it was a paper-feed pen plotter that was used to plot various measured data online.

The DXY-990 plotter shown below can hold eight pen at the higher left part and moves on an xy-plane using two stepper motors which control a ribbon each. Each initialization process involves finding the lower-left corner which seems to be offset from the x-position of the pen. The plotter can be loaded with a paper size slightly bigger than DIN A3. The paper is held by a controllable static charge (wow! when did this technology disappear?) so that it doesn't move when the pen is hovering or scratching on it.

Roland DG DXY-990

The plotter has a manual dial to control it. The pen can be moved in 8 directions and two velocities. A number dial is used to change the pen. Then there are the buttons for "paper hold", "pen up/down" which simply controls a electric magnet and "pause" which can pause a loaded program. To test the plotter, one can hold the "Enter" button while turning it on (back side). It will then plot a test page.

As i expected, the control of the plotter with a pc wasn't so complicated, but finding a documentation about how to do it using standard windows/linux commands took some time. First one has to know about the HPGL-language which seems to have been a standard for plotting machines by hp which was adopted in large parts by other manufacturers. Roland DG adopted the language as RD-GL1 which is compatible to HPGL. A HPGL-command to initialize and print a line from (10,10) to (1000,1000) would look somewhat like this:

CODE:
  1. IN;SP1;PU10,10;PD1000,1000;

IN stands for "initialize". It sets back all the parameters (scaling, rotation, pen status etc..). SP stands for "select pen" and the first parameter "1" means, that the first pen should be selected. Interestingly, the dxy-990 remembers at every state, which pen it's holding and which actualy coordinates it should be at. So SP2 while holding the first pen means actually "bring back pen1, pick up pen2, go back to coordinates". To move the pen without drawing we can use the PU or "pen up" command. It takes two parameters as in x and y coordinate. I'm not quite sure about the delimetation codex. i think it's o.k. to write PU 10,10; or even P U 10,10;. To set the pen down, the command PD is used - equally with way points. PD can take as many waypoints as need be. Printing a polygon is much better using the compact notation PD1000,1000,50,50,10,40....

The easiest way to send the commands to the plotter is to write them down into a text file and then (using windows) type the following command into a shell

CODE:
  1. copy "file.hpgl" lpt1:

This is assuming the plotter is connected to the (still existing) parallel port. I didn't do serial port connection yet. The equivalent linux command should be

CODE:
  1. cat file.hpgl> /dev/lp0

With linux you can also write online commands:

CODE:
  1. cat> /dev/lp0
  2. <commands>

After each "return", the commands are sent to the plotter and it immediately performs that command.

By the way, HPGL-files can also be generated by Inkscape. The problem is that right now, the export-plugin doesn't consider changing the pen for differently colored figures and rectangles arent't exported at all. I hope this changes in the near future (maybe i will find time to work on it). I will end with a small video of the Roland DG DXY-990 plotter in action (plotting the test page). The ogg-video can be viewed with current browsers with the html5-standard and the ogg-vorbis codec implemented . Otherwise download the video and watch it offline (vlc).

Categories: CAD, Hardware, Programming Tags:

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.

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:

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:

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.

Finally wordpress 2.7 final

December 11th, 2008 admin No comments

The final version of wordpress 2.7 "Coltrane" has been released. I've kept this blog up to date and switched from trunk to 2.7-branch now for fear that the stability held up until now won't be kept up. I've also updated my main blog. The only thing that is bugging me is the notice at the top of the blog telling me to upgrade to please WordPress 2.7, even though the blog is long updated.. A last-minute bug?

It's really funny at the dashboard, where it literally says "You have version 2.7. Would you like to upgrade to version 2.7?"

upgrade27

upgrade27

Anyway, the team of Automattic has again done a great job with this version. I'm totally happy with it. Thanks guys.

Lighty Development is not (!) dead

November 19th, 2008 admin No comments

I thought it was. The forum was long abandoned. Just now i was looking for a problem i'm having with high-load combined with enabled xcache and found out they've changed from trac to redmine (have to try!). Here is the new development site.

On this happy note, i now think i could be changing soon to lighttpd 1.5.0svn. Let's see. Maybe even try an svn-version of xcache?? Any thoughts about such a transition? I know there are quite some sites already running 1.5.0, but as long as i didn't see progress on the site of lighttpd i was too afraid, that i wouldn't get any support if i changed to the unstable version.

Gengo und Wordpress 2.7

November 17th, 2008 admin 1 comment

Ich hatte Probleme damit, Gengo und Wordpress 2.7 gemeinsam zum Laufen zu bringen und die Option zum Anhängen von Sprachkürzeln in Gengo zu aktivieren (Gengo should append language codes to permalinks automatically.), da Gengo in eine Endlos-Weiterleitungsschleife ging. Ich dachte schon, das wäre eine grundsätzliche unverträglichkeit zwischen den beiden und schaltete deswegen diese Option aus, was dazu führte, dass sämtliche Links nicht mehr funktionierten. Joshreisner schlägt dagegen im Forum auf wordpress.org vor, die Permalink-Strukturen neu zu speichern.

Und tatsächlich geht man auf Einstellungen>Permalinks und speichert einfach die bereits gespeicherte Permalink-Struktur neu, dann geht das Problem der Endlosschleifen weg! Es hat wahrscheinlich damit zu tun, dass Gengo beim Speichern der Permalinks selbst eine Aktion durchführt.

Categories: Programming, wordpress Tags: , ,

Gengo and Wordpress 2.7

November 17th, 2008 admin 3 comments

I had an issue with gengo getting into an endless redirect loop once i activate the option "Gengo should append language codes to permalinks automatically.". I thought this was an issue of gengo-compatibility and deactivated the option making many links unusable. Now i just found this thread over at wordpress.org where joshreisner suggests simply saving the permalink structure again:

i just upgraded to 2.6.1 using the automatic updater and it caused a redirect loop on my site. whenever i would visit it it would be like "the address /en/en/en/en/en/en/en etc was in a repeat loop that would never be resolved"

i pulled my hair out for a minute but then figured it out. just go to the permalinks settings page (in wp, not gengo) and hit save. no change, just save. that fixed the problem!

Thanks. This works. It seems gengo uses some action that is being pulled once the permalink structure is saved..

Categories: Programming, php, wordpress Tags: , ,