Updated: September 16th, 2012

Introduction

StackOverflow is an amazing site for coding questions. It was created by Joel Spolsky of joelonsoftware.com, Jeff Atwood of codinghorror.com, and some other incredibly smart guys who truly care about user experience. I have been a total fan of SO since it went mainstream and it's now a borderline addiction (you can see my StackOverflow badge on the right sidebar).

The Story

Update 6/21/09: This server is currently under very heavy load (10-200), even with caching plugins enabled. Please bear with me as I try to resolve the situation.

Feel free to bookmark this page and return to it later when the fires have been put out.

Update 06/21/09: I think I've got the situation …

Read the rest of this article »

2

[Perl] Finding Files, The Fun And Elegant Way


Posted by Artem Russakovskii on April 8th, 2009 in Awesomeness, Linux, Perl, Programming, Tutorials

Updated: October 6th, 2009

No matter what programming language you use, there comes a time when you need to search for a file somewhere on the file system. Here, I want to talk about accomplishing this task in Perl. There are many ways of doing so, most of them boring, but I want to discuss the fun and elegant way – using File::Find::Rule.

Let me briefly discuss some of the other methods first.

Limited

Using glob() (or <>, TODO verify) you can find files in a single directory, using only the limited shell wildcard support. For example,

1
my @files = glob(&quot;tmp*&quot;);
I prefer glob() to <> because glob()'s parameters can be more than just

Read the rest of this article »

Updated: June 9th, 2009

Problem

While writing a 1093985th Perl script the other day I was facing the following dilemma:

  • Let’s say there is a local library, called TheUberLib.pm. It is so uber that most of my scripts, located all over the machine, include it.
  • Now, let’s also say that there’s an even more uberly important binary called run_me_now_or_you_will_die but the only way to find it is by using a relative path to the aforementioned TheUberLib.pm, for example ../bin (RELATIVE TO TheUberLib.pm).
  • I don’t want to hardcode the path to run_me_now_or_you_will_die because it can be different on multiple machines and the code wouldn’t be robust enough – all I know is that the path is relative to an included library.

So …

Read the rest of this article »

4

Programming Comics: xkcd – 11th-Grade Activities


Posted by Artem Russakovskii on December 19th, 2008 in Humor, Programming

Hey, I can relate to today’s xkcd! It hits close to home:

image

 

And some more traveling down the Perl related memory lane (yeah, these are old, I know):

image 

image

Read the rest of this article »

5

My Notes On Learning Python Coming From Perl


Posted by Artem Russakovskii on October 9th, 2008 in Programming

Updated: January 2nd, 2017

image

I’m learning Python. Since I’m currently primarily a Perl coder, I decided it’d be a good idea to post and keep track of my experiences coming from heavy Perl. I have a few reasons for learning Python, which are:

  • to see what else is out there and broaden my horizons.
  • to keep my brain active by feeding it new tasty information every day.
  • to become a more valuable employee and potential future candidate.
  • to learn a new language, especially one used by giants like Google.
  • to learn a new OO language, as I’m tired of Perl’s hacky OO.
  • to build GUI applications. GUI in Perl is a big pain. I’ll see about Python.

So, without further ado, here are the …

Read the rest of this article »

0

How To Install The Latest SOAP::Lite Using Perl CPAN


Posted by Artem Russakovskii on April 30th, 2008 in Programming

Apparently it's not straightforward to install SOAP::Lite, even using CPAN.

Check this out.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
cpan[1]> install SOAP::Lite
CPAN: Storable loaded ok (v2.18)
Going to read /root/.cpan/Metadata
  Database was generated on Tue, 29 Apr 2008 18:29:45 GMT
CPAN: YAML loaded ok (v0.66)
Going to read /root/.cpan/build/
............................................................................DONE
Found 149 old builds, restored the state of 109
Warning: Cannot install SOAP::Lite, don't know what it is.
Try the command
 
    i /SOAP::Lite/
 
to find objects with matching identifiers.
CPAN: Time::HiRes loaded ok (v1.9713)

Read the rest of this article »

Updated: October 6th, 2009

I'm sure most Perl coders have to face this annoying problem at one point or another: how do you consistently get the return value out of a system call, be at executed via backticks or system()? Backticks return the output of the program with no error code in sight, while system() returns the error code but prints the output instead of putting it into a variable.

The best solution I could find to this problem to date was posted at http://www.perlmonks.org/?node_id=19119 and involved opening a piped filehandle. It worked quite well but always felt like a hack (which it was). Having used the new Perl 5.10 for a few months, I was shocked today to find this new variable that …

Read the rest of this article »

4

Do NOT Use This Perl Module: Passwd::Unix


Posted by Artem Russakovskii on April 22nd, 2008 in Linux, Programming

Updated: April 29th, 2008

Update: The author of the module contacted me the same day and promised to fix it in the next version. Version 0.40 was indeed on cpan as promised, but I haven't tested it yet.

Passwd::Unix will corrupt your /etc/shadow file and rearrange login names and their corresponding password hashes.

The current version of Passwd::Unix corrupted my /etc/shadow upon only
calling the passwd() function. Immediately users started to report not
being able to login.

After examining the situation, I found that Passwd::Unix rearranges all
users in /etc/shadow in some way, but it only does it to the
usernames, and not the password hashes. Thus, you will get corrupted accounts. Moreover,
users are now able to login to one OTHER account, not …

Read the rest of this article »

Updated: May 23rd, 2009

In this tutorial, I'll show you how to parse JSON using Perl. As a fun example, I'll use the new SouthParkStudios.com site released earlier this week, which contains full legal episodes of South Park. I guess the TV companies are finally getting a clue about what users want.

I will parse the first season's JSON and pull out information about individual episodes (like title, description, air date, etc) from http://www.southparkstudios.com/includes/utils/proxy_feed.php?html=season_json.jhtml%3fseason=1. Feel free to replace '1' with any valid season number.

Here's a short snippet of the JSON:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

Read the rest of this article »

2

Quick Perl Snippet: Finding If A File Has A Media Extension Using Regex


Posted by Artem Russakovskii on March 21st, 2008 in Programming

Updated: May 1st, 2008

Sometimes in my line of work, I need to figure out if a url or filename point to a media file by checking for the file extension. If it's a url, however, it may be followed by various parameters. Not to overcomplicate things, I came up with the following Perl code:

1
2
3
4
5
6
7
8
9
10
#!/usr/bin/perl -w
use strict;
my $name = "some_file.flv"; # or http://example.com/file.mp4?foo=bar
my $is_media_type = ($name =~ /\.(wmv|avi|flv|mov|mkv|mp..?|swf|ra.?|rm|as.|m4[av]|smi.?)\b/i);
if($is_media_type){
  print "media extension found\n";
}
else{
  print "not a media file\n";
}

Read the rest of this article »

0

Programming Comic: Lisp, Perl, And God


Posted by Artem Russakovskii on March 17th, 2008 in Humor, Programming

Computer Science majors out there that went through tedious hours of studying Lisp – this is for you from xkcd. If you know Perl, it will make even more sense.

image

Source: http://xkcd.com/224/

See Also: Best Programming Comic Ever: Code Quality In WTFs/Minute

Read the rest of this article »

2

cpan – The Perl Module Manager


Posted by Artem Russakovskii on October 12th, 2007 in Linux, Programming

Updated: March 19th, 2008

cpan is a perl module manager. To get into cpan, login as root and type in

cpan

Install a module:

cpan install MODULE

Upgrade a module:

cpan upgrade MODULE

Reinstall a module or force install in case of failed tests:

force install MODULE

See a list of upgradable modules:

r

See cpan configuration (that's the letter 'o'):

o conf

Update an option in cpan configuration:

o conf OPTION_NAME OPTION_VALUE

It is always nice to:

upgrade CPAN
install Bundle::CPAN

If there's an error making a Perl module, it can be caused by a missing make path in cpan configuration. In …

Read the rest of this article »