Skip to content

Instantly share code, notes, and snippets.

View olegwtf's full-sized avatar

Oleg olegwtf

  • reg.ru
  • Russia, Novosibirsk
View GitHub Profile
@olegwtf
olegwtf / test.pl
Created March 29, 2014 09:17
gortrans geo
use strict;
use feature 'say';
use Geo::Distance;
use Geo::Point;
use JSON;
use LWP::UserAgent::Cached;
use Term::ANSIColor;
use List::Util 'reduce';
use Math::Trig;
use strict;
use Text::CSV;
use Text::Trim;
use HTML::Entities;
binmode STDOUT, ":utf8";
my $dir = shift
or die "usage: $0 dir > output";
@olegwtf
olegwtf / cache-if-modified.pl
Last active August 29, 2015 14:06
LWP::UserAgent::Cached and If-Modified-Since header
use strict;
use LWP::UserAgent::Cached 0.06;
use HTTP::Date;
mkdir '/tmp/cache';
my $ua = LWP::UserAgent::Cached->new(cache_dir => '/tmp/cache');
$ua->nocache_if(sub {
my $resp = shift;
$resp->code == 304; # do not cache not modified
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
char *sockname(int type) {
if (type == SOCK_STREAM) return "SOCK_STREAM";
use strict;
use blib;
use Net::DNS_A;
for (1..10_000) {
Net::DNS_A::lookup("localhost");
}
sleep;
@olegwtf
olegwtf / gist:ebfc9dcadb98eafe2216
Created December 16, 2014 10:45
IO::Socket::IP bug
use strict;
use IO::Socket::IP;
use Socket 'IPPROTO_TCP';
use IO::Select;
my ($err, @res) = Socket::getaddrinfo("www.google.com", 80, {protocol => IPPROTO_TCP});
die $err if $err;
my $ip = IO::Socket::IP->new(Blocking => 0, PeerAddrInfo => \@res) or die $@;
my $sel = IO::Select->new($ip);
@olegwtf
olegwtf / gist:f1aa01e5e33f2c49bbc5
Created January 20, 2015 12:16
sharepoint: get folder items
CamlQuery camlQuery = new CamlQuery();
camlQuery.FolderServerRelativeUrl = cFolder.ServerRelativeUrl;
List list = ctx.Web.Lists.GetById(listGuid);
ctx.Load(list);
ctx.ExecuteQuery();
var items = list.GetItems(camlQuery);
ctx.Load(items);
ctx.ExecuteQuery();
foreach (ListItem i in items)
diff --git a/lib/Mojo/Server/Prefork.pm b/lib/Mojo/Server/Prefork.pm
index 1052111..96c33f5 100644
--- a/lib/Mojo/Server/Prefork.pm
+++ b/lib/Mojo/Server/Prefork.pm
@@ -78,8 +78,12 @@ sub run {
local $SIG{INT} = local $SIG{TERM} = sub { $self->_term };
local $SIG{CHLD} = sub {
while ((my $pid = waitpid -1, WNOHANG) > 0) {
- $self->app->log->debug("Worker $pid stopped.")
- if delete $self->emit(reap => $pid)->{pool}{$pid};
find . -type f -regextype posix-egrep -regex '.*\.pm|.*\.c|.*\.h|.*\.xs' ! -regex '\./\.git/|.*ppport\.h' | while read fname; do perl -ne 'print unless /^=h/ .. /^=cut/' < $fname; done | sed '/^$/d;/^#/d' | wc -l
@olegwtf
olegwtf / gist:1180610
Created August 30, 2011 10:25
measure speed with lwp
use LWP::UserAgent;
use Time::HiRes;
use strict;
my $ua = LWP::UserAgent->new();
my $start = Time::HiRes::time();
my $maxbytes = 1024*1024;
my $curspeed = 0;
my $received_bytes = 0;