Here we go loop de loop

Well looks like old fiend smartypants was up to her old tricks again.

You know the type, spends the day at work in some IRC, never forgets the minutia of page 67 of the help file of a sys-admin command, has memorized and and has a better version every regex ever written, knows she is always right and in the bosses eyes can never make a poor choice when designing code.

Anyway let's get on with the code example. Sometimes the ugly way to do
things is the best. In this case processing a large array where lets say the following has to be extracted,

  1. The maximum value
  2. The minimum value
  3. Clean out any duplicates
  4. Group the data into 3 sets

Simple enough really. But then I saw the code (changed to protect the guilty and save space)

Purpose of this blog

At this point, I don't have a Perl blog. I do Perl things, but nothing that ever seems worth blogging about. However, I've decided to improve my knowledge of Perl 5i and Perl 6, and generally practice my proramming, so I'm going to work through a bunch of easy through to difficult problems in each language. Hopefully I'll pick up the idiomatic solution ideas as I go along.

Feedback and alternate solutions are also welcome.

At some point I may repeat the problems with Python, but not yet.

Problem sets I'm planning on starting with include:

The latter two are language-targetted, but I believe that I should be able to gain some benefit from some of them anyway. Suggestions for other problem sets are welcome, but this is certainly enough to get me started.

Netting apples against possums

I officially join Fruit Protectors R Us:

The pix of the tricks.

Release a new distribution every month in 2014

This challenge is a stencil quest on questhub: in each calendar month of 2014 you have to release a distribution that you haven't released before, and write a blog post about it. This might be an entirely new distribution, one that you've adopted, or one that you're helping with. The rules so far are:

  • You have to release at least one such dist within each calendar month. You can't catch up, by releasing 12 in December.
  • You must blog about the dist and link to the blog post in a comment on your quest. It doesn't matter if the blog post is in a following month.
  • Renaming one of your existing dists doesn't count :-)

Come and join us!

Another Little Head Scratcher

So I though it would be just a regular day until with me just doing a little coding, drinking my coffee* and generally enjoying life, But I was wrong.

A Little Vulnerable

So I have been babysitting and ever so slowly migrating a 15+ year old application over to a more manageable and of course we have to keep doing improvements to the code so on a very old part I found something like this. (SQL changed to protect the innocent)

my $usr_ids = join(",",@user_sel);

my $sth = $h->prepare("Select * from a_table where id in ($usr_ids)");

$sth->execute();

Params? We an't got no params. We don't need no stinking params!!

Well the old bug-bear of little Bobby Tables or SQL injection shows it ugly little head again.

But what to do? There is no bind_array, well lets just give 'execute_array' a try

my $sth = $h->prepare("Select * from a_table where id in (?)");
my $tuples = $sth->execute_array(
{ ArrayTupleStatus => \my @tuple_status },
@user_sel,
);

ora_st_execute_array(): SELECT statement not supported for array operation.

Ouch so no luck there!

Perl Exercism

I blame Jeff Thalhammer. He is the one who directed me to The ChangeLog, and that's where I've heard the interview with Katrina Owen, the creator of Exercism.io.

What is Exercism.io?

Perl and Me, Part 1: The Road So Far

Lately, I’ve been pondering my relationship with Perl.  Every programmer has a different relationship with their language-of-choice, and it impacts how they approach many different aspects of coding, what features they like and which ones they hate, what they clamor for and what they disparage.  And these choices are always going to be challenged by our friends, our coworkers, and our open-source collaborators.  Which is a good thing, for the most part: being challenged is what keeps us honest, keeps us fresh.  Without constant challenge, we can lapse into dogma and cargo cult coding.  But we can’t properly defend our positions—can’t explain why we feel the way we do about certain things—unless we take the time to understand our relationship with our language.

So this is part 1 of an X-part series (we’ll just have to see how long it takes me to work through it all).  Primarily I want to explore this for my own self-awareness, but I hope it will be interesting to others as well.  And perhaps it will make some of my other blog posts make sense.

I begin at the beginning: how I came to Perl.

Visualizing a CPAN install plan

At the patch -p1 Perl hackathon, I'm working on bits related to my idea for a new sort of CPAN client. One of the features I want is a graphical display of the work to do and the work being done.

Creating the data structure in Perl is easy. Start with a module, figure out it's distribution, then grab that META.{json|yml} to get dependencies (for now, with more discovery later). Put that stuff into a data structure.

Does This Mean Me??


In an odd turn of fate as I was just about to write today's post. I got this email announcing the release of DBI 1.6.31, normally this causes me little concern as DBI has been stable for a very very long time, but given yesterdays Part 18 and this line in the change file

Changed the handle passed to Callbacks from being an 'inner' handle to being an 'outer' handle.

I though maybe I should look at this change?

Are You an Innie or Outie

I'll start by giving the 25 cent tour of inner and outer handles. DBI has been using Tied Hashes since time immemorial, and all handles in DBI are references to tied hashes so you never really get a $dbh or $sth object just a reference to it.

Prehistory

Hello, folks. This blog was started to talk about a project of Jess and mine, but before we got around to starting it, I posted a couple of times in my own blog about it, so please read these if you’re interested:

Future entries will hopefully be collected on this blog, at least until we pick a name for the project. (So far, I’ve come up with learnthing and {mechano,electro,cyber}didact, all of which kind of suck.)

Thanks,
-=- James "theorbtwo" Mastros

A book on Debian admin

Recently, Packt published a book called Debian 7: System Administration Best Practices.

Some time before they had emailed me asking if I would be a reviewer. I know some readers have in the past been disappointed with Packt's books, and thought that since I had time I might be able to contribute enough suggestions to help make the book better. I explained that I am a Perl programmer, not a Debian administrator, and on that understanding we agreed.

I was not told the name of the author, and from his point of view I would have been one of the anonymous reviewers.

During reviews, I made many suggestions. I have received a paper copy of the book, but have not counted how many were adopted. I did check a couple of chapters, and see a few were, and some (a clear majority :-) weren't. The number doesn't matter - what matters of course is the resultant book.

Learning project 2: What's different

In this post, I’d like to talk about what’s different between this project and other similar things I’ve seen. I haven’t seen everything (by a long shot), and I certainly would love to see more prior art posts — I’ve now at least glanced at all the ones mentioned in the comments to the last post, though it’s been a while since I looked at the Kahn Academy, and that’s probably the closest to what I’ve got in mind.

Mo’ money, mo problems

Looking at DBI Part 18, Call me Ishmael,

In part 17 we had a look at DBD:Pg's ability to do Asynchronous Queries, now I think it is time I got a little back in line with the spec so we are going to look at DBI's ability to do callbacks.

How it happened that Mastro Cherry,

Callbacks are common attribute to all three of the the DBI handles and with them you can be come if you want the great and all powerful puppet master of DBI contorting everything from A to Z. Myself I have really only used them for one of two reasons, either as a quick and dirty logging system as a secondary way to control access.

Using them is quite straightforward one just set the 'Callbacks' attribute of the desired handle, to a hash ref where the keys are the methods you want to set a callback for and the values are the code you want to run.

passwordless ssh not working on rhel5

Was doing automation test, trying to set up passwordless ssh between the dirver and couple of test nodes. it just didn't work with one rhel5 box. Finally find the solution:

[root@perlrh5-179 .ssh]# tail -n 10 /var/log/secure
Dec 4 12:39:56 perlrh5-179 sshd[9397]: Authentication refused: bad ownership or modes for directory /root
Dec 4 12:39:59 perlrh5-179 sshd[9398]: Connection closed by 10.200.58.179
...

log shows the issue was the permission of the root dir

drwxrwxr-x 20 root root 4096 Nov 25 10:08 root

change it to 700 and the issue was resolved.

Blobs in Postgresql with Perl

Are you using, or do you want to use Postgresql Blobs with Perl?

Providing you are in the Moose ecosystem, here is Pg::Blobs. Pg::Blobs is a role that adds blobs handling methods to any Moose based package.

Continued here.

Automate As Much As Possible

When you are starting up a business, automate as much as you can. You’ll have enough headaches along the way even if you automate everything, so save yourself some trouble up front and automate as much as you can figure out how to automate. Here are some examples:

Set up your payroll to be automatically sent out every two weeks. There are some online services for this, or you can simply outsource it to your accountant.

Use a software based calendaring system to remind you about everything you have going on. Not just the usual stuff such as meetings and dentist appointments, but also about writing blog posts, changing the oil in your car, and to check in on new employees once in a while.

Is that an Int?

I had to do a little playing around today as I have to validate if a number is an integer? Well there are as many ways to do this as there are perl programmers.

At first I though that is easy just look for the '.' in the string so I gave this a try

if (index($a,'.') == -1 )

but wait what if $a was not a valid number say '0.1.1.1'. All I am really checking for is the '.' so I would have to check if it is a number first. We do have a nifty little util called 'looks_like_number' so we could do this

use Scalar::Util qw(looks_like_number);
if (index($a,'.') == -1 and (!Scalar::Util::looks_like_number($a))

not the most readable code out there.

How about this old gem I remember using with GW-Basic. Simply test subtracting the number from itself as an integer like this and since this is perl we can play with the 'unless'

unless((($x-int($x)))

or if you like

if (!(($x-int($x))))

Learning project: introduction

Past & Prologue

So, one of the great projects that have been rattling around in my head for some time has recently come back into the front burner of my brain again: computer-assisted learning. Jess has more or less been constantly thinking of this for the last decade+, from a rather different viewpoint — the writing of documentation and tutorials, especially around DBIx::Class and Catalyst. I think my current ideas are worthy of implementation, and I think that without building an active community around them, the project will falter, and that’d be a shame. So, enough of the past / prologue for the moment…

Synopsis

The basic idea goes like this: first, ask questions to determine what the student does and does not know.
Then, point them at something to read or watch, which requires only things that they do know, and will teach them things that they do not know. Now, since that basic idea is a bit … vague, a more detailed, and less formal English sketch of the system will follow.

Sketch

Graphviz V 2.34, GraphViz2 V 2.23 and output formats

A discrepancy has arisen between the list of output formats supported by Graphviz, and the list supported by my module GraphViz2.

Planet Moose - November 2013

Welcome to Planet Moose, a brief write up on what's been happening in the world of Moose in the past month, for the benefit of those of you who don't have their eyes permanently glued to the #moose IRC channel, or the MetaCPAN recent uploads page.

If you'd like to contribute some news for next month's issue, you can do so on the wiki.

Mouse 2.0.0

Mouse has rolled over to 2.0.0, and now 2.1.0. 2.0.0 introduced a potentially backwards-incompatible change with regards to role composition, and 2.1.0 drops support for Perl 5.6.x.

About blogs.perl.org

blogs.perl.org is a common blogging platform for the Perl community. Written in Perl with a graphic design donated by Six Apart, Ltd.