Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env perl
use common::sense;
use Net::DNS::DynDNS;
use LWP::Simple qw/get/;
my $file_ip = "result.dat";
my $user = "user";
my $passw = "paswword";
my $domain = "domain.dyndns.org";
@sugar84
sugar84 / gist:952361
Created May 2, 2011 21:03
twiggy vs node.js vs HTTP::Server::Simple::PSGI
----------------------------------------------------------
== Twiggy ==
app.psgi:
my $app = sub {
return [ 200, ['Content-Type' => 'text/plain'], [ "Hello world\n"] ];
};
[sugar@host dir]$ twiggy --listen 127.0.0.1:8080 app.psgi
@sugar84
sugar84 / gist:954958
Created May 4, 2011 09:02
search perl modules
for I in `perl -le 'print for @INC'`; do RES=`ls -l $I | grep AnyEvent`; if [[ $RES ]]; then echo $I; echo $RES; fi; done
@sugar84
sugar84 / gist:966719
Created May 11, 2011 15:48
strange behavior
#!/usr/bin env perl
use strict;
local $, = " ";
my $registry = {1 => 1, 2 => 1, 3 => 1};
my $num = [2,5];
say "first" if @$registry{@$num};
my $num = [5,2];
@sugar84
sugar84 / gist:1044446
Created June 24, 2011 08:40
Oneliner to search perl-module
perl -le '$r = "Mojolicious"; for (@INC) {opendir $dh, $_; if (@a = grep {/$r/} readdir $dh) {print $_.":"; print for @a}}'
@sugar84
sugar84 / format_time.pl
Created June 24, 2011 11:31
format elapsed time
sub format_time {
my $time = shift;
use integer;
my $formatted;
for my $unit (["д", 60*60*24], ["ч", 60*60], ["м", 60], ["с", 1]) {
my $res = $time / $unit->[1];
@sugar84
sugar84 / gist:1053955
Created June 29, 2011 14:37
Create aliase for access remote servers by pass
#!/usr/bin/env perl
use common::sense;
use YAML::Tiny;
use Data::Dumper;
my $conf = YAML::Tiny->read("config.yml")->[0];
my $template = 'alias ssh_<name>=\'expect -c "spawn ssh <user>@<host>;' .
'expect password: {send <passw>\r}; interact"\'';
@sugar84
sugar84 / gist:1057039
Created June 30, 2011 19:44
python test measurement
#!/usr/bin/env python
def get_primes7(n):
if n < 2: return []
if n == 2: return [2]
# do only odd numbers starting at 3
s = []
for t in range(1, n/2):
s.append(t*2 + 1)
@sugar84
sugar84 / gist:1057050
Created June 30, 2011 19:49
Perl test measurement
#!/usr/bin/env perl
use strict;
use warnings;
# use integer;
sub get_primes7 {
my $n = shift;
if ($n < 2) { return (); }
@sugar84
sugar84 / gist:1069381
Created July 7, 2011 12:11
smart code "sorter" in js
/**
* jQuery.fn.sortElements
* --------------
* @author James Padolsey (http://james.padolsey.com)
* @version 0.11
* @updated 18-MAR-2010
* --------------
* @param Function comparator:
* Exactly the same behaviour as [1,2,3].sort(comparator)
*