Skip to content

Instantly share code, notes, and snippets.

View paveljurca's full-sized avatar
🎯
Focusing

Pavel paveljurca

🎯
Focusing
View GitHub Profile
@paveljurca
paveljurca / Berlin.pl
Last active August 29, 2015 14:08
A hypothetical conclusion?
#-------------------------------------------------
# http://www.google.com/#q=pavel+curda+gesche+haas
#-------------------------------------------------
TO_GESCHE_HAAS:
until ($I_have_sex_with_you) {
say "I will not leave Berlin. Deal?";
die unless <STDIN> =~ m{yes|ok|fine}ig;
#she's gotta be kidding me
@paveljurca
paveljurca / HEAD.pl
Last active August 29, 2015 14:08
HTTP requests; quick and dirty
#!/usr/bin/perl
use LWP::UserAgent;
$req = HTTP::Request->new(
'HEAD' => 'http://fis.vse.cz'
);
$res = LWP::UserAgent->new(
agent => 'Googlebot/2.1'
)->request($req);
@paveljurca
paveljurca / is_prime.pl
Created October 27, 2014 14:53
$> for a in `seq 1 100`; do if $( perl is_prime.pl $a ); then echo $a; fi; done
#!/usr/bin/env perl
use strict;
use POSIX;
exit 2 unless &is_prime(pop @ARGV);
sub is_prime {
my $num = shift || 0;
return if $num<2
|| ($num%2==0 && $num>2)
$> echo "Zanzibar, zambeZi" | perl -le "@_= <STDIN> =~ m/z/g; print scalar(@_);"
$> echo "Zanzibar, zambeZi" | perl -le "print (scalar(split /z/, <STDIN>) - 1);"
--
#!/usr/bin/env perl
use strict;
use warnings;
use feature q{say};
package VS module
"Packages and modules are two completely separate and distinct features"
=> http://qntm.org/files/perl/perl.html
conventions
http://perlmaven.com/how-to-create-a-perl-module-for-code-reuse
--
use VS require
http://linux-forum-karthik.blogspot.cz/2011/06/use-vs-require-in-perl.html
%INC
@paveljurca
paveljurca / diary.pl
Last active August 29, 2015 14:14
have a Perl diary!
#!/usr/bin/env perl
use strict;
use autodie;
my $note = \&diary;
sub diary {
my %tasks;
chomp(my($date,$task) = @_);
$tasks{$date} = $task;
### add FILEHANDLE, have a file!
@paveljurca
paveljurca / books.pl
Last active August 29, 2015 14:14
Právě půjčeno | Městská knihovna v Praze /* SKRIPT PRO UCHOVÁNÍ SI PŘEHLEDU O KNIŽNÍCH VÝPŮJČKÁCH */
#!/usr/bin/env perl
use strict;
use warnings;
use open qw(:std :utf8);
use utf8;
#################################
# EXAMPLE #
# http://jurcapavel.cz/books.pl #
#################################
@paveljurca
paveljurca / file_test.pl
Created February 5, 2015 09:48
stat $mode
use 5.010.1;
use strict;
use warnings;
for (@ARGV) {
say "[ $_ ]";
say " - $_" for file_test($_);
}
sub file_test {
@paveljurca
paveljurca / words.pl
Last active August 29, 2015 14:17
word frequency counter (pretty stupid one)
#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use open qw(:std :utf8);
my %word;
#single-space-literal split pattern cuts out leading spaces
#see http://perldoc.perl.org/functions/split.html
@paveljurca
paveljurca / header.cgi
Last active August 29, 2015 14:17
HTTP headers (relace)
#!/usr/bin/perl -T
#PERL5OPT=-T
use strict;
use warnings;
use LWP::UserAgent;
my $dotaz = sestav_dotaz(
zpracuj(&nacti) #ref eq 'HASH'
);
my $odpoved = posli_dotaz($dotaz);