Skip to content

Instantly share code, notes, and snippets.

@viliampucik
viliampucik / oldrpm.pl
Created March 15, 2011 22:47
Perl script for printing all old (SRC) RPM packages from a specified directory
#!/usr/bin/env perl
# [2011-03-15] viliam.pucik@gmail.com
# Prints all old (SRC) RPM packages from specified directory.
# Assumed package format: name-version-release.distribution_optionalpatch.suffix.rpm
#
# Use case:
#
# $ ls test/
# glibc-2.12-1.7.el6_0.3.src.rpm glibc-2.12-1.7.el6_0.4.src.rpm glibc-2.12-1.7.el6.src.rpm
# $ ./oldrpm.pl test/
@viliampucik
viliampucik / dns-2.pl
Created June 5, 2011 19:55
Example of using POE::Component::Client::DNS
#!/usr/bin/env perl
use strict;
use warnings;
use POE;
use POE::Component::Client::DNS;
my @ips = qw( 127.0.0.1 10.0.0.1 192.168.0.1 192.168.1.1 1.2.3.4
8.8.4.4 8.8.8.8 208.67.220.220 208.67.222.222 );
@viliampucik
viliampucik / PKGBUILD
Created November 9, 2011 19:48
perl-mojolicious
# Contributor: Viliam Pucik <viliam.pucik@gmail.com>
# Generator : CPANPLUS::Dist::Arch 1.19
pkgname='perl-mojolicious'
pkgver='2.25'
pkgrel='1'
pkgdesc="Real-time web framework"
arch=('any')
license=('PerlArtistic' 'GPL')
options=('!emptydirs')
@viliampucik
viliampucik / PKGBUILD
Created November 12, 2011 14:17
perl-html-wikiconverter
# Contributor: Viliam Pucik <viliam.pucik@gmail.com>
# Generator : CPANPLUS::Dist::Arch 1.19
pkgname='perl-html-wikiconverter'
pkgver='0.68'
pkgrel='2'
pkgdesc="Convert HTML to wiki markup"
arch=('any')
license=('PerlArtistic' 'GPL')
options=('!emptydirs')
@viliampucik
viliampucik / benchmark-empty-strings.pl
Created December 28, 2011 20:32
Benchmark of Empty String Comparisons
#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark ( 'cmpthese' );
my $foo = '';
cmpthese( 10000000, {
'direct' => sub { return $foo eq '' },
@viliampucik
viliampucik / uuid-v3.pl
Created January 28, 2012 19:03
Perl Name-based UUID Generator
#!/usr/bin/env perl
use strict;
use warnings;
use Digest::MD5 qw( md5 );
# based on UUID::Tiny
sub uuid_v3 {
my ( $namespace, $name ) = @_;
@viliampucik
viliampucik / app.conf
Created February 28, 2012 21:08
Pure Perl Configuration File
{
database => 'donut',
user => 'homer',
password => 'simpson',
quote => {
give => 'me',
the => 'number',
for => 911,
},
@viliampucik
viliampucik / samples.sql
Created April 9, 2012 16:43
Random 5-minute Samples
select i * '5 minute'::interval + timestamp '2012-01-01 00:00:00',
trunc(100 * random()::numeric, 2)
from generate_series(0, 24 * 60 / 5 - 1) as t(i)
#!/usr/bin/env perl
# Taken from "There are too many ways to do it" presentation
# http://www.shlomifish.org/lecture/Perl/Lightning/Too-Many-Ways/slides/
#
# The problem
#
# <sniperd> looking to write a regex that strips out all periods, except for
# the last one. ie, i have a string named perl.is.the.best.txt and I just
# want perlisthebest.txt
#
@viliampucik
viliampucik / pgrep.pl
Created March 21, 2013 12:39
Perl's zgrep
#!/usr/bin/env perl
use strict;
use warnings;
use PerlIO::gzip;
my $pattern = $ARGV[0];
my $file = $ARGV[1];
open my $z, '<:gzip', $file or die "gunzip failed: $!\n";
while ( <$z> ) {
print if /$pattern/i;