APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed


Sometimes you should reinvent the wheel

It's an old adage: don't reinvent the wheel. Search Google for "reusable code" and you'll find hundreds of thousands of web posts and books extolling the virtues of both writing and using reusable code. Well, yeah, there are advantages .. Even if you feel you can write what you need, if there is nagging doubt that you really have dotted all the i's, maybe you should go get the code that has been time proven, right?



Title Last Comment
How do I find out what IP address a user logged in from?   2013/11/13 TonyLawrence
- Obtaining a client IP address on Linux/Unix is not always direct or easy. You may have to dig it out of shell command output. -

Another Perl link checker  
- I'm still trying to write the perfect link checker for my site. -

Slightly Scrambled - unsorting a file   2011/04/05 TonyLawrence
- Here is a typical way to approach the problem. It uses Perl's associative arrays and (somewhat ironically) uses -

Snarling Panda site cleanup  
- The problem is "low value content". That's tough to define absolutely, but some pages here definitely fall into that category -

Smarter HTML Link Extractor   2011/07/20 TonyLawrence
- Checking links is not really hard; you can actually do it with just a few lines of Perl. -

Locking files for shared access  
- Multiple users require some sort of mechanism to give exclusive access to data. It's trivial to demonstrate advisory locking with Perl. -

A simple but useful Chrome Extension  
- Chrome extensions are much easier than you may think. Follow along to build a simple extension you might actually use. -

Quick and simple web log grepper in Perl  
- Get quick pageviews/uniques from web logs with this short Perl script -

Simple XML POST and reply   2010/03/24 TonyLawrence
- A customer has an app that needs to post and get XML data from a website. This task was being handled by .asp scripts on a Windows box, but now they want it moved to Linux and Perl. -

'makekey' for Linux  
- Porting 'makekey' to Linux. Apparently there was once a Linux makekey, but it was deprecated in favor of crypt(3). -

Using Multiple Submits with Perl CGI   2010/11/20 TonyLawrence
- You don't have to limit yourself to one submit, but you do have to be careful -

Sometimes you should reinvent the wheel  
- They say don't reinvent the wheel, but you sometimes you should -

Perl script to get Numly  
- Using Perl LWP to get Numly tags (I stopped using this sometime back but am leaving this code for others). -

Random errors in Perl  
- Don't make this programming mistake in Perl or any other language. -

Surveys with Google Graphs  
- Using Google Graphs to display Survey Results including a simplified version of the code here with comments. -

Equal height CSS columns with filler text   2010/04/15 w3cvalidation
- Making column length match with text. The problem is knowing when to stop writing text in the left column. -

Who locked that file?  
- Determine what process has a file locked - I can't even imagine how many times I've heard someone complain about a locked file. -

How many RSS readers do you really have?  
- Do those RSS readers come to the site? I sometimes subscribe to a site and only after months of ignoring it do I get around to actually getting rid of it. -

USB I/O on Wiring.org board  
- Example of using usb port on Wiring.org board: I'm continuing to play around with the Wiring.org I/O Board and wanted to see how to use its built-in USB port for input and output. It turns out that's not hard to do, but I did run into a number of data conversion problems along the way, so the project became a little challenging. -

 
 











 
 
Random subroutines in Perl  
- How to call subroutines randomly with Perl - and why you might want to do something that seems so silly. -

Handling missing data  
- I have an old Perl project that goes out to a Government web site, ftp's some files, massages them in various ways, and spits out some output. Over time, the project grew, and now does more than it used to. To keep it generic and simple, let's pretend that originally it went out and got "temperature" files every hour. That was simple enough: about the only error condition would be the inability to get one or more of the files it wanted. My program simply kept track of what it actually got and only ran the rest of the process on new files. -

Simple Schedule  
- I often get asked for web-based scheduling programs. I've done quite a few of them over the years, sometimes using scripts available from the web, but more often writing my own simply because I don't like modifying other people's code. -

POST,GET: Tech Words the Day  
- Web forms have two possible methods of passing information back to the script that will process the form. -

Buffer Overflow Attacks  
- This is a deeply disturbing book. I thought things were getting better, that buffer overflows were going away as programmers learn to avoid them. but the authors explain that is an illusion: it's just that the reporting slacked off. -

Virus Research and Defense  
- This book by Symantec's chief researcher should scare you, because the bad guys are winning the virus wars. This book can be heavy geek territory. If you aren't fascinated by the details of executable programs and the like, some of this will be hard sledding. But if you are the type who likes to take things apart to see how they work, this is for you. -

An example of poorly commented code...  
- This one is a little amusing, and deserves some kind of award for perl "one-liners", and belongs on a tee-shirt! -

Linux|Unix Application Development  
- If I had to pick one word for this book, I'd choose "thorough". Give me the luxury of a few more and I'd add "sumptuous", "enthralling" and maybe even "riveting". -

Goal seeking code  
- Playing with evolution in code isn't very scientific, but it still can be fun. Here's a Perl plaything. -

Transferring mail to a new mail server  
- Your current mail server may just not be meeting your needs, so you've put up something new. But what about old mail? -

Simplified SCO_OSR5 Printing  
- Although this article strongly references SCO Unix printing, the background and trouble-shooting tips are valuable on any Unix/Linux platform. -

Replacing a Spreadsheet  
- Spreadsheets can be powerful tools. The customer needed several breakdowns of this data. I offered to provide an HTML page that could generate desired output. -

Perl 6 Now: The Core Ideas Illustrated with Perl 5  
- Perl 6 scares me. It probably wouldn't have shaken me up so much if I hadn't read Larry Wall's State of the Onion 2003. I'm sure Larry didn't intend to frighten anyone, but he is so intense and often so obscure. He can be fun to read, too, but his expositions on Perl 6 really made me a bit nervous. I'm not alone, at least with regard to fearing Perl 6 -

Randal Schwartz's Perls of Wisdom  
- Randal Schwartz was co-author of the first and second editions of the Perl Camel Book> and of another of my favorites, Learning Perl -

Determining clients IP address by service and PID  
- I wrote this thing several years ago for use with a program where I needed to know a client's IP address, given the TCP service on which they were connected and the program's PID -

IOMEGA REV Drive with Fedora Core 2  
- Unfortunately, that was a system I wanted to use the REV on. -

Handling missing data in inputs  
- Missing data can be very annoying to a programmer. In fact, it is so annoying that very often we'll write separate programs to clean up data and eliminate unpleasant conditions so that the main code doesn't have to deal with it. -

Smart text reformatting with Perl  
- How to reformat included text when the level of quoting causes line wrap problems. Perl Text::Autoformat fixed it nicey. -

How and where to start writing first Shell Script in UNIX Part 2  
- How and where to start writing first ShellScript in UNIX -

Fixing 404 errors  
- Maybe you mistyped something, or the link you followed was mistyped by someone else, or maybe the webmaster moved it or renamed it or just deleted it. -

No programming  
- Whenever I see 'No programming', I have to smile. Of course it's 'programming' - and it still requires skill! -

Running out of space for web logs  
- Damn! I hate running out of space.. though I hate paying for more space too.. Well, web access logs are easily compressed. A 30 MB access_log easily gzips down to a tenth of that. -

WinPopup   2010/02/11 anonymous
- This is a perl script that sends out a SMB Message to all users via "WinPopUp", using SAMBA. -

Perl Input   2011/04/08 TonyLawrence
- Perl has wonderful I/O capabilities. I'm only going to cover input here: reading from files or standard input. There are two ways to do that (actually a lot more than two, but this is supposed to be introductory material): you can open a specific file, or you can pass files on the command line and either open them individually or just ignore the whole thing and pretend everything is coming from STDIN. -

Fork and exec with Perl  
- Understandin Unix fork and exec. Recently I had a project that required a number of different programs that will mostly run all the time, but need to be restarted now and then with different parameters. -

Text vs. Binary Data formats  
- When I'm doing some project that requires storing and retrieving data, I usually have a mental argument about how to structure the files. Should I use flat text, or some binary format (typically Perl dbm files)? The answer almost always should be "flat text", but old habits die hard. -

Getopt and getopts   2013/06/29 TonyLawrence
- Both "getopt" and getopts are tools to use for processing and validating shell script arguments. They are similar, but not identical. -

Perl Getopt and GetOptions   2013/02/26 TonyLawrence
- Two Perl modules (Getopt and Getoptions::Long) work to extract program flags and arguments much like Getopt and Getopts do for shell programming. The Perl modules, especially GetOptions::Long, are much more powerful and flexible. -

Understanding Floating Point Formats   2011/10/28 TonyLawrence
- Understanding basic floating point. Under ordinary circumstances, you don't have to know or care how numbers are represented within your programs. However, when you are transferring data files that contain numbers, you will have to convert if the storage formats are not identical. If the numbers are just integers, that's fairly easy because the only differences will be the length and the byte order: how many bytes the number takes up, and whether it is stored lsb or msb (least significant byte or most significant byte first). Once you know that, conversion is trivial. -

Some Assemblance of Order  
- I don't do any machine or assembly language coding any more, but I still have tender feelings in that direction. Assembler is fun: you have total control of the machine, and it runs so darn fast you can't blink or you'll miss it. You can write programs that are smaller and faster than is ever possible with any other language. Although it looks horribly daunting at first, there are really only a dozen or so basic instructions that you use over and over again. I think there is something quite pretty about listings of assembler code, and I truly miss seeing them in magazines. -

Simple RSS Feed Generator  
- So, you have a web site, and you want to generate an RSS feed. In my case, I have the entire process of adding anything to my site scripted (see The AutoMagic Web Site), and of course generating new RSS documents is just part of that. But you may not have reached that state yet, so here's a little Perl script that will help you along. -

 
 
Samepage - Redefining how people create and share information
 
 
Printing to a remote printer with a dynamic address  
- You have a PC at home and you make some sort of connection over the internet to your server, but your application needs to print to your PC. -

Operating System Concepts  
- Basic OS concepts. The CPU (Central Processing Unit) is the heart of any computer, but the operating system is the brain. Unfortunately, understanding exactly how these things really work can be difficult, because it's fairly hard to "play" with the operating system that you are actually using. You can do quite a bit with sophisticated debuggers, but eventually you run into confusion and difficulty. And, as you try more complex tasks, you run the risk of interfering with the real machine's operating system. Finally, modern CPU's are very complex, and that complexity can make it more difficult to understand basic concepts. -

Squidlog II  
- This new version generates pages as requested. This version also uses a Perl .db file to store its data. -

I've given up on Blogger  
- Perl code for a simple blogging platform. Simple base to expand from, requires Perl ability. -

Notify Cell Phone of Incoming Mail  
- Notify Cell Phone of Incoming Mail using "dash" addresses and a bit of Perl scripting. -

Sample Test Question Creation  
- This article covers how I create the sample tests. It involves a little bit of html, some Perl, some Applescript, and even making a Mac disk image. -

Simple FAQ Creator  
- This is a pair of programs to create and maintain a simple FAQ web page. The administrative inteface lets you add questions and answers. -

Converting Print Files to HTML Invoices  
- Example of HTML Invoice generated from Perl script. The basic transformation is done by a Perl script running on a Windows server. -

Converting Print Files to HTML Invoices (Sample)  
- -



More Code articles
















Have you tried our Tests?