This section is now closed for posting code. Please use Cool Uses For Perl instead.

Code Categories
Audio Related ProgramsFTP stuffNT Admin
CGI ProgrammingFun StuffWin32 Stuff
Chatterbox ClientsGUI ProgrammingMiscellaneous
CryptographyHTML UtilityText Processing
Database ProgrammingUtility ScriptsNetworking Code
E-Mail ProgramsWeb StuffPerlMonks Related Scripts


New Code
Jumping Desktop Windows with Gtk2
on Jul 14, 2008 at 14:42
0 replies by zentara
Warning...contains some X windows trickery, and should not be run while important things are going on on your desktop. It will not destroy anything, just be annoying.

This is some Gtk2 code that will find all non-maximized windows (on all virtual desktops), and start them jumping like crazy. A control window is placed in the center (immune to the jumping), which has a global keyboard grab, so you can kill the program.

Use cautiously. :-)

Developed for a school audio visual tech, who needed to pretend to be fixing malfunctioning monitors, all the while partying in the back room. :-)

It does show an important concept, of doing a global keyboard grab with Gtk2.

Perl modules search engine, part II
on Jul 12, 2008 at 00:20
0 replies by jacques
Perl module search. Copy & paste the code to a CGI script and you are good to go. (You need to have HTML::Perlinfo installed.)

This is an updated version of the previous post, based on the latest version of HTML::Perlinfo, which fixes a security vulnerability pointed out by moritz.

I added optional fields in the search form. The program searches @INC by default, so you don't need to specify search directories, but you can if you want to now. If you look at the documentation for HTML::Perlinfo::Modules, you will see that more options are available. For example, you can add different columns or change the POD links (by default, every module is linked with search.cpan.org).

Suggestions/Code Updates Welcomed!

Thanks to Your Mother, moritz, and everyone else who responded last time.

Gnome2::Canvas Scribble with Image
on Jul 09, 2008 at 16:27
0 replies by zentara
Loads an optional image on a canvas, lets you draw with selected brush size and color, and save a screenshot. Fast and handy for marking up maps.
Goo Canvas and transparent images
on Jul 03, 2008 at 16:02
0 replies by zentara
A discussion arose recently about overlaying radar weather plots on a map. Well this kind of demonstrates all you need. It shows how to load images onto the canvas, and make a color transparent. The first time it runs, it gets a little map from google, and the overlay is base64encoded into the script. It is a little green plane that flies in circles over the map. This will work with a Gnome2::Canvas also (with some minor syntax changes), but I use Goo because it implements saving to postscript (amoung other formats).

Updated 7/25/2008... added more transparency to the airplane....it was solid green, on a black background, in which the canvas made black transparent. I added semi-transparency to it, so it looks similar to see the thru clouds of a weather map. This was done by adding an alpha layer to the plane itself, and setting the alpha to black. This made the green semi-transparent by removing it's black constituent.

RFC: XML::Pastor v0.52 is released - A REVOLUTIONARY way to deal with XML
on Jun 29, 2008 at 15:23
0 replies by aulusoy

Hello all,

Having just released the first available version (v0.52) of XML::Pastor, I have found this discussion list that might best suit speaking about it.

Let me run the commercial....

Now you don't need to write code in an ugly language like Java in order to be able to get native XML support. Because now, there is XML::Pastor.

XML::Pastor is a revolutionary new way to handle XML documents in Perl.

Give it a try. You won't regret it. Guaranteed (or almost).

In fact, if you are familiar with Java's XML CASTOR, this module (XML::Pastor) will be very familiar to you. XML::Pastor is very similar to Java's Castor, however, as usual with Perl, it's more flexible. On the other hand, full XSD support is not achieved yet (a lot is already supported, see below).

XML::Pastor will actually generate Perl code starting with one or more W3C Schema(s) (XSD). The generated code is as easy, if not easier, to use as XML::Simple. YET (and this is the tricky part), you can also easily read and write to and from an XML document ('instance' of the schema) abiding by the rules of the schema. You can even validate against the original schema before writing the XML document.

However, you don't need the original schema at run-time (unless you are doing run-time code generation). Everything is translated into Perl at code generation time. Your generated classes 'know' about how to read, write, and validate XML data against the rules of the original schema without the actual schema at hand.

Attributes and child elements can be accessed through auto-generated accessors or hash items. You don't need to know or worry about whether or not a child element appears once or multiple times in the XML document. This is automagically taken care of for you. If you access the child element as an array (with a subscript), it is OK. But you don't need to. You might as well access the first such element directly, without needing to know that there are others.

Code can be generated at 'make' time onto disk (the so-called 'offline' mode) or it can be generated and 'eval'ed for you as a big chunk at run-time. Or you can get it as a string ready to be evaled. In 'offline' mode, you can choose to use a 'single' module style (where all code is in one big chunk), or in 'multiple' style, where each class is written to dik in a separate module.

There is also a command line utility, called 'pastorize' that helps you do this from within 'make' files.

Gone with the multiplicity problem of XML::Simple. Gone with the complexity of dealing with XML as XML. Now you can deal with XML data as real Perl objects (with accessors for child elements and attributes). But you can still get XML back out of it at the end of the day.

W3C SCHEMA SUPPORT

Most of the W3C XSD Schema structures are supported. Notable exception is substitution sets. Namespace support is currently a bit shaky (at most one namespace per generation). That's why schema 'import' is not - yet- supported. However, schema 'include' and 'replace' are supported.

All W3C schema builtin types have Perl counterparts with validation. This includes datetime and date types as well (You can get/set these with CPAN's DateTime objects as well).

Internally, XML::Pastor uses XML::LibXML to deal with actuial xml reading/writing XML (but not for validation). But, you don't need to know anything about XML::LibXML for being able to use XML::Pastor.

Give it a try please. And enjoy...

Note: It's already on CPAN. Just search for XML::Pastor on search.cpan.org.

Cheers,

Ayhan Ulusoy

eval() from gdb
on Jun 25, 2008 at 23:10
0 replies by diotalevi
Tk RGBColorDialog
on Jun 22, 2008 at 14:23
1 reply by zentara
I got tired of trying to use the cumbersome Tk ColorDialog ( which I could never get to work simply). I wanted a popup dialog, with RGB sliders, that simply returns the RGB color, on the Ok button press. Nothing fancy, but just works in a simple straightforward manner. Presented as a package, but can easily be put into module form.

UPDATE Jun23, 2008 Removed uneeded hex2dec sub, which was intended to be used if you fed the package an initial setting. See comment below if you need an initial color option.

SmallRSA
on Jun 20, 2008 at 08:51
0 replies by LordScinawa
It's an easy implementation of RSA using small prime numbers.
Tk Canvas Image Sampler/ Montage builder
on Jun 19, 2008 at 14:57
0 replies by zentara
UPDATED Jun20,2008 Simplified multiple canvas bindings, and made it all left-mouse-button operation. I like the simplicity of left-mouse single clicks and drags.

This recursively browses a directory of png and jpg images (you can add more). It makes thumbnails for selection with a left click on subdirs. Upon left-click selection on a thumbnail, the full image is displayed in the source canvas, and a left-mouse-drag will draw a rectangular region on the image. Upon left-button release, the region will be copied to a second target canvas, where it can be positioned and saved.

Useful for easy-mouse selections in creating montages. The entire target canvas can be saved as a jpg.

So for instance, you can open a 100 photos, copy off only the faces, arrange them to please yourself, then save the whole montage as a jpg.

For the more advanced Tk users, there is an interesting use of ImageMagick blobs to convert postscript directly to jpg, without temp files.

Perl module search engine
on Jun 13, 2008 at 18:21
2 replies by jacques
This is a quick -n- dirty script for searching your local Perl modules and printing the results to a webpage. You can easily change it around for your needs. NOTE that the search is case insensitive and you can do partial searches, such as 'file::' to see all the modules in that particular namespace. See HTML::Perlinfo::Modules for more details and options.

NOTE: Do not use the code presented on this thread, as there is a security risk described below. In particular, Your Mother 's code example should not be implemented. HTML::Perlinfo::Modules will be updated with a security patch soon.

UPDATE: 7/11/08 -- See the latest version at Perl modules search engine, part II.