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.
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.)
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.
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.
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'
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
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.
In part 16 we has a quick look at the NAME and other attributes that can help you create portable code. Well this time lets break with good portable code like I did in part 15 and bend the spec a bit. We will have a look at Asynchronous Queries
Wrapped Around Your Fingers
So we are not talking about the Album but then again I think the album should of been called Asynchronicity, as it really was overplayed not very well executed and over-hyped, anyway lets get on track.
Asynchronous in DBI means we are sending a query off to the DB and instead of waiting for a response, we go off and do our own thing and DBI and hopefully later we can come back and ask if our results are ready.
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.
I released GitPrep 1.4 at 2013/10/09. You can install portable GitHub system into Unix / Linux easily. It is second major release.
Because you can install GitPrep into your own server, you can create users and repositories without limit. You can use GitPrep freely because GitPrep is free software. You can also install GitPrep into shared rental server.
- Fix markdown small bugs (*em*, _em_ etc)
- Defalt readme file is changed from README to README.md
- Add private repository and collaboration features
Big adding point is that Gitprep support private repository and collaboration features. If you repository set to private, the repository can be shown, pulled, pushed from only myself and collaborator. By this, you can publish private repository on public internet.
In part 15 we had a look at a look at some extra XML goodies that DBD::Oracle give you. Now we are going to see how the statement handle can save you arse.
LOGID, LogID, LOgid
Egad those really are three table names I once encountered in a Oracle DB and I am not even going to show you all the fields in some of these three that where upper, lower and even mixed case.
Well how can DBI statement handle help?? Well you can at least get everything out of a table in the same case. So lets take this SQL for example
Select "First_Name", "last_NAME" from USER_NAMES
Don't laugh I actually had that above table. You could of course just deal with it as you go along but the DBI $sth has the handy 'NAME_lc_hash' attribute which can does the dirty work for you.
So on the select from this table you could do something like this
A long time ago I started to build a Perl distribution for Linux, but then I did not have more time and I did not have the immediate need. But it has changed and thus I created a new version of the DWIM Perl for Linux.
It includes perl 5.18.1, DBI, DBD::SQlite, Moo, and for the first time it include XML::LibXML. This is the big change for me and for the package. It now includes a directory called c/ where external (non-perl) dependencies are installed.
My servers are backed up using a little script that works just like Apple's TimeMachine. Every day a backup job moves the latest backup to a folder named by the date of its creation and creates a new backup in the folder latest. Rsync has a nifty feature that creates hardlinks to files in a different folder if the file matches with the current folder. Meaning that you don't create a full backup every time but only sync the differences, i.e. an incremental backup.
All in all that works quite well and I can go back to any date in time to see the state of the machine. This script is now in production for quite a while and I ended up running out of space because I haven't figured out a good way to get rid of old backups. A listing for one of my servers looks currently like this:
In part 14 we had a look at a look at blob, lob and clobs and even memo data sometimes DBD developers add in a few goodies that are outside the spec despite the ever watchful eyes of the DBI gods. Here is one exmple.
XML, That will never catch on we have SML
On neat little trick, besides a bunch of others, that DBD::Oracle can do is suck up large XML documents into its native XMLType.
It is actually quite easy as all that is really necessary is to import the correct data type and then bind it to the appropriate column.
So to start
use DBD::DBD qw(:ora_types);
and then simply bind it with the ORA_XMLTYPE like this
my $sql = "insert into big_data values(:p_xml)";
my $sth =$dbh-> prepare($SQL);
$sth-> bind_param(":p_xml", $big_hunk_of_xml, { ora_type => ORA_XMLTYPE });
$sth-> execute();
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.
As some of you know, one of my most popular talks is "Agile Companies Go P.O.P.". What you probably don't know is that this talk is actually an introduction to a full day training course I give on this topic. So far it's been a lot of fun and I cover everything from the space shuttle (which you've seen from the slides), to the Feudal era (which you haven't). However, there is one topic I don't cover enough and I think it's time to point it out: agile sucks, but it
sucks less than the alternatives.