Strangely addictive Tk::Zinc based game
on May 04, 2006 at 22:35
|
3 replies
|
by thundergnat
|
|
I've been puttering around with the Tk::Zinc package, trying to get a handle on it and decided to do a little simulation of a ball in a gravity field. I set up the mouse pointer to be a "point source anti-gravity field". It is strangely addictive to try to keep the ball aloft by repelling it with the mouse cursor.
To make it interesting, the "anti-gravity" field strength decreases over time, so it becomes more and more difficult to keep the ball up. 10 seconds is simple, 20 easy, 30 hard, 40 difficult and 50 plus nearly impossible. The tested limit, (when the "antigravity is too weak to support the ball,) is at 75 seconds, but it would take someone with the reflexes of a fast twitch FPS god to get much over 60 seconds. My personal best is 42 seconds.
Requires Tk::Zinc.
Update: Rewrote it a bit to do less calulations inside the loop. Added automatic update speed detection to set the update speed to a value appropriate for your system. Override automatic speed detection by passing in a delay value in milliseconds at the command line. (20 to 80 ms range recommended.)
|
script-starter
on May 02, 2006 at 15:33
|
1 reply
|
by polettix
|
|
A template for creating new scripts, much in the Module::Starter spirit, together with a script that filters the template to actually create the new script. Ok, it's simpler than what I've described!
The script has documentation, but it's not based on the template - just because the template evolved with time (e.g. english translation).
Update: followed clever suggestions from chanio.
Update: followed clever suggestion from http://perlbuzz.com/2009/11/the-horrible-bug-your-command-line-perl-program-probably-has.html.
|
Serve image from file
on Apr 28, 2006 at 17:33
|
1 reply
|
by ruzam
|
Here's snip of script I use to dump images from private (non-document path) file folders.
The source of the file path varies from application to application. Sometimes it comes from the cgi parms, othertimes it comes from a database, so I've simply included a path variable for reference.
Is there a leaner (performance wise, not elegant code wise) way to do this?
|
Calculate Age, days to next and days from last for a given birthday
on Apr 28, 2006 at 16:03
|
3 replies
|
by ruzam
|
This is a little function to calculate a person's age, the number of days to their next birthday and the number of days from their last birthday.
If the birthdate is today, then the number of days to and from the last birthday = 0.
I can't say for certain that it's accurate for all situations (leap years and what not), but it's quite simple and doesn't rely on any additonal modules other than Time::Local which should be standard.
Updates:
- changed the name to 'birth_date_age_today' so there's no confusion as to it's purpose.
- Removed current day and month as these are not used.
- Used timelocal_nocheck to account for birthdates on Feb 29
- Added condition to leap year check so script continues to operate in the year 2100
- Added more comments (so people don't get the wrong idea about leap years).
- fixed missing brackets on leap year test
- added test code to check results
|
IP address - long to dottedquad to long
on Apr 28, 2006 at 15:47
|
3 replies
|
by ruzam
|
Convert long integers to dotted quad notation string.
Convert dotted quad notation strings to long integer.
A couple of quick functions I've been using to convert IP addresses. I seem to be using these quite often.
Any and all comments/suggestions appreciated!
Thanks to jdporter and ikegami who have shown me a better way. The code here is credited to ikegami.
|
pythagorean triples
on Apr 23, 2006 at 16:01
|
2 replies
|
by Pete_I
|
calculates pythagorean triples
explanation:
a pythagorean triple is a set of non-zero integers that make the pythagorean theorem return true when they're plugged in.
3,4,5 is the first triple.
sqrt((3)**2 + (4)**2) = 25
sqrt(9 + 16) = 25
sqrt(25) == 5
I've got no idea what uses this could have, but I thought it was interesting.
it looked cleaner at the beginning, but map{} and for(a..b) had big memory problems. If you find a use for it, i'd like to know. Enjoy :)
|
XML Output from MySQL
on Apr 17, 2006 at 09:49
|
1 reply
|
by PerlDutch
|
|
With this piece of code you can extract data from a table within MySQL and put in a XML document.
The perl packages I use in this listing are standard packages, which can be found at ActiveState.com and be installed with ppm.
Have fun.
|
MIME AND SMTP
on Apr 15, 2006 at 18:47
|
0 replies
|
by PerlDutch
|
|
With this piece of code a email with attachment like a pdf file or a zip file can be sent.
You only have to punt into this your own email adres, the adres of the receiver and finally the address of the mail server that you want to use from your provider.
In this piece of code you will find scalars that I use to specify file. These can of course be replaced by your own.
I have tested this and it works very well. I have put in a delay with "sleep" of 2 seconds.
Have fun.
|
XML Data Output from ODBC
on Apr 15, 2006 at 18:37
|
0 replies
|
by PerlDutch
|
|
With this piece of code you can generate XML in conjunction with a ODBC connection to a database.
|
Edit a List of Files
on Apr 10, 2006 at 16:15
|
2 replies
|
by lev36
|
|
With much help from answers provided by fellow monks to my previous questions, I have come up with a script (my first real script, actually!) that will read a list of filenames and then apply a series of edits to the files. In the process, it will back the originals up in a tarball.
If any of you are willing to look over my code, I'd appreciate feedback. Any lines stand out as the wrong way to do things? Are there things that could be written more elegantly? Can error handling be improved? I'm quite new at Perl, so I wouldn't be surprised if there are things I could have done better.
So here's the script, which I've called fled for 'file list edit'.
The reason I'm not simply using perl -pi.bak -e 's|foo|bar|g' files is that these files are not necessarily all in the same directory, and besides, the in-place edit feature of Perl changes the owner of the edited file to whoever runs it. This script will maintain the same owners on the original files.
Since it runs from a list of files, that list can be generated by grep, or tcgrep, or however.
Anyway, here it is:
|