Getting IP address with Perl

A common situation which you will usually come across, is to retrieve the IP.

Using WWW::curlmyip, this task is very easy.

use WWW::curlmyip;
my $ip = get_ip();

Lets inspect the module on https://metacpan.org/pod/WWW::curlmyip closely to understand how it works.

use strict;
package WWW::curlmyip;
$WWW::curlmyip::VERSION = '0.02';
use 5.008;
 
# ABSTRACT: Returns your ip address using L<http://curlmyip.com>
 
 
BEGIN {
    require Exporter;
    use base 'Exporter';
    our @EXPORT = 'get_ip';
    our @EXPORT_OK = ();
}
 
 
sub get_ip {
    my $response = HTTP::Tiny->new->get('http://curlmyip.com');
    die join(' ', 'Error fetching ip: ',
                  ($response->{status} or ''),
                  ($response->{reason} or '')) unless $response->{success};
    my $ip = $response->{content};
    chomp $ip;
    $ip;
}
 
1;
 
__END__
 


It's a one file module, which simply contacts http://curlmyip.com, retrieves the content with HTTP GET request, and finally chomps the result; because there exists an extra new line character which is useless.

So simple, isn't it ?
But It's also very useful !


A Grand, 2014

A couple of days ago I got a tip that I was very close to being the first CPAN author to upload 1000 releases in a year (989). Today I topped it off:

Thus ends my CPAN numbers ambitions. From now on I will concentrate on -Oquality -Ofun and -Oacmeism. Actually the numbers stuff ended in early September.

The -Oquantity and -Ofrequency flags were fun for a while, and it resulted in my getting a large portion of my modules into an up to date state; but numbers for numbers sake has a limited appeal.

Note: It was ironic that one of my final releases was from a pull request by SHARYANTO++ who leads almost all the CPAN statistics. :-)

Elasticsearch Custom Scoring

Elasticsearch has a builtin scoring algorithm which works quite well in practice, but sometimes you want to roll your own scoring algorithm. Let's examine how to create a custom scoring algorithm using the function score query.

Let's assume we want to search and score Perl job offers based on a set of weighted keywords. To get the score of each offer, we'll multiply the weights of matching keywords where positive keywords have weights greater than one, and negative keywords are weighted less than one. Thus, the positive and negative keyword matches add and take away from the final product (score) respectively.

Define the Qualitative Importance and Their Weights

Qualitative Tags

Instead of assigning weights directly to keywords, let's use qualitative tags of desirability (importance) for each keyword (trait). Borrowing from okcupid's five degree scale of importance:

  • mandatory
  • very
  • somewhat
  • little
  • irrelevant

This takes care of the non-negative traits, now let's add qualifiers for negative traits using a similar pattern:

  • mandatory_neg
  • very_neg
  • somewhat_neg
  • little_neg

Actual Weights

Final TPF Devel::Cover grant report

(Russian) Article about Test::Spec

Article in Russian about Test::Spec benefits and gotchas/internals

Travis-CI Helpers for Perl

I deal with a lot of modules that promise backwards compatibility with older versions of perl, usually back to perl 5.8.1. Since I don't regularly use perl versions that old when developing, accidentally introducing incompatibilities is always a risk. Having a continuous integration system check this for me makes it much easier to catch mistakes like this before they get released into the wild.

Travis CI is a very useful continuous integration service that is free for any public repositories on GitHub. There are issues with using Travis CI for the kind of testing I need though. First, it only provides the last revision of each perl series. Especially in the perl 5.8 and 5.10 series, there are substantial enough differences between them that testing only the latest isn't adequate. Additionally, some of the testing needs to be done on perls built with threading, which isn't included on most of the versions available on Travis. It also is sometimes useful to test without any additional modules pre-installed like Travis does.

Strawberry Perl 5.18.4.1 released

Strawberry Perl 5.18.4.1 is available at http://strawberryperl.com

More details in Release Notes:
http://strawberryperl.com/release-notes/5.18.4.1-32bit.html
http://strawberryperl.com/release-notes/5.18.4.1-64bit.html

I would like to thank our sponsor Enlightened Perl Organisation for resources provided to our project.

Spam on CPAN

Some idiot has just uploaded a purely spam distribution: THEMA-MEDIA. He clearly knows it's idiotic, because his README.md begins with "CPAN-foolishness".

IO::Iron::Applications - Command line tools for Iron.io services

Partitions of an Integer

The subject of integer partitions comes up regularly, with multiple threads over the years at PerlMonks, a big chunk of Chapter 5 of Higher-Order Perl, and some pages from Knuth TAOCP volume 4A. Last year I added a partitions function to my ntheory Perl module, for counting integer partitions (OEIS A000041). A few months ago I added a partition iterator (forpart) since I liked the one Pari/GP added last year.

Integer partitions
Solution Impl
Order
anti-lex
Order
lexico
Restrict
count
Restrict
size
Max in 10s Count in 10s
ntheory 0.45 XS yes no yes yes 87 223,000
ntheory 0.45 Perl yes no yes yes 72 7,300
Integer::Partition 0.05 Perl yes yes no no 67 -
(unreleased, from Limbic 2004)
Perl no yes no no 62 6,000
MJD 2013 Perl no no no no 71 -
blokhead 2007 Perl yes no no no 63 -
kvale 2004 Perl yes no no no 62 -
sfink 2004 Perl yes no no no 58 -
tye 2001 Perl no no no no 58 -
(golfed, 73 chrs)
Perl
no (73)
yes(90)
no no no 21 -
Pari/GP 2.8.0
(not a Perl module!)
C/Pari no no yes yes 100 34,000,000

Exporter::Tiny nearing 1.000000

Yes, in my warped mathematics, 0.042 is nearly 1.000000.

Exporter::Tiny is a module I split out of the Type::Tiny distribution. It's an exporter, offering roughly the same capabilities as Sub::Exporter, but with a lighter footprint. I've not massively promoted it, but have been using it in a bunch of my other modules, and other people seem to have picked up on it and started using it too.

The documentation requires a bit of work, but from my perspective the implementation is effectively complete. If you're using it, then I'd appreciate any feedback you have before it's "stable" and thus too late to change.

Ideas for perl.org.in | an Indian connecting platform

Friends,
I have found certain outward challenges in perl and have always found someways to overcome them. Some of the common challenges i found specific in India are:
India being such a large country have a number of software development centers across it like: Noida, Gurgaon, Bangalore, Hyderabad, Pune etc. Though there are excellent developers in perl but they are less in number and find them sparsely located across these development centers , ie. few in each centers which makes connecting with each others rather difficult. Though there are some perl monger and other groups here but still as the developers are geographically sparsed in India, they dont connect well, eg. a developer in Delhi will not want to subscribe to Bangalore group because he may not find any merit at it. Same is with the recruiters .

My idea is to create a all india perl group, and also list profiles of most of the people here. There will be a weekly or monthly mailer from the group with a list of opportunities , I am willing to use the domain perl.org.in for this and use catalyst for the same.

Also we will plan remote sessions / google hangouts.

Any person here want to comment on this, and / or will want to contribute towards the design / anything just comment here or at https://twitter.com/perl_org_in ?

I am looking for Derek Price

I tried to get co-maintainer bit for Text::MediawikiFormat, but his e-mail does not get delivered. do you know Derek? Could you help me get in touch with him to become a co-maintainer?

Launched http://perl.careers/

I know what you're thinking. You're thinking: "What this world has too few of, is recruiters. The world definitely needs more recruiters". And given that shocking lack of people trying to get you a job, I've launched Perl Careers.

My eventual goal is to try and do something like O'Reilly did back in the day - divert a significant portion of profits back in to the community via paying for high-quality Perl content/articles, sponsorship of conferences, and sponsorship in to TPF and similar organisations. This is going to take me a while to achieve; I'm planning to sponsor November's London Perl Workshop, and I'm flying to London for it, and I hope to start paying for high-quality Perl-related content at the beginning of next year. ORA used to pay $200-$400 for articles on Perl.com, and I think that's where I'll be aiming.

However, in the interim, I'm hiring for some great roles. I'm only willing to take on roles for companies I'd want to work at, so please get in contact: pete@perl.careers.

Devops in the cloud with perl

I gave a talk at NY Perlmongers this past Tuesday. We streamed it -- though didn't really publicize that ahead of time due to me working on my slides up until the last second -- and Devops in the cloud with perl is up on YouTube. The slides are here. I used the excellent reveal.js.

This is my second time giving a talk at perlmongers, and SocialFlow's fifth time hosting. Every time I've attended perlmongers it's been fun, interesting, and worthwhile, so if you're on the fence about going to your local meetup you should give it a shot. And it you're on the fence about streaming your local meetup you should give that a shot as well; it's really not very hard.

The Audio compression came out really bad this time, probably because our upstream speeds were severely limited by being on a cable modem, but I still stand by my HOWTO live stream a talk in pretty much the laziest way possible.

Planet Moose - September 2014

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.

Moose

Moose 2.1212 fixes some warnings under the Perl 5.21 development branch. (See also perl RT#121638.) Moose 2.1213 fixes a memory leak throwing exceptions. If you're already using Moose 2.11xx or 2.12xx, then it's probably worth upgrading to Moose 2.1213. If you're on an older version of Moose, then also consider upgrading but first test that your stuff works with a newer Moose.

Legal Issues in Game Software Creation

Note: I am not a lawyer and the following should not be considered legal advice. Double-check everything and hire a lawyer.

As I continue to work on Veure, I have the added fun of less time spent working on it while I try to understand the legal problems. If you're going to create and publish your own game, you'll invariably hit legal issues. What's worse, you might discuss them publicly and some bright spark will vaguely remember an online article, dumbed down for mass consumption, regarding a complicated libel lawsuit for the print industry and swear up and down that it applies to you. They won't supply a link.

In fact, software games seem to have some peculiar legal issues all their own, compounded by the fact that they're often indie games created by hyper-intelligent, well-read individuals who either don't think of legal issues or assume they already understand them. On the off chance that they're right about a given issue, there's also one tiny detail they often overlook.

Elasticsearch Token Filters

We recently saw an example of an elasticsearch token filter called the catalan_stemmer. The Catalan language has other token filters available:

  • catalan_stop
  • catalan_elision
  • catalan_keywords

Let's see what they do.

Stop

The catalan_stop filter removes a list (common) of words. Given the example search:

  porros amb balsàmic

applying the catalan_stop filter will remove the word amb (with) from the indexing.

This stop filter is defined as:
  "catalan_stop": {
    "type":       "stop",
    "stopwords":  "_catalan_" 
  }

and it is customizable.

Elision

The catalan_elision filter removes elisions. Given the example search:

Travis and Dist::Zilla projects

Getting started with Travis

I felt like I should give Travis a try and picked a recent github project of mine that I knew had a decent testsuite.

The instructions on how to get started with travis were quite simple and soon the project had its own travis page.

Unknown build failure

I wondered why the build failed after adding a very simple .travis.yml file to the project.

$ cpanm --quiet --installdeps --notest .

! Configuring . failed. See /home/travis/.cpanm/work/1411809721.1412/build.log for details.

The command "eval cpanm --quiet --installdeps --notest ." failed. Retrying, 2 of 3.

DWIM Perl for Linux - version 5.20.1.9 released

After almost a week of adding more and more modules I've got to the 9th revision of DWIM Perl for Linux .

It explicitly includes more than 400 CPAN modules, but with their dependencies it is probably a lot more. The idea behind this distribution is to make it very fast and easy to get started with Perl. Without learning how to brew perl and how to install CPAN modules. Without fighting external dependencies or some failure in the latest release of a CPAN module.

I need your help to test-drive the distribution and to fill the holes. The modules that might be really needed but have not yet been included.

It would be of great help if you downloaded the latest distribution. Configured it as described on the website and let me know which additional modules your application might need or if something is broken.

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.