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 / gist:7478457
Created November 15, 2013 03:05
Mojolicious and AnyEvent
use strict;
use Mojo::Reactor::EV;
use v5.10;
BEGIN {
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::EV';
$ENV{MOJO_IOLOOP_DEBUG} = 1;
}
use Mojo::IOLoop;
use Mojo::UserAgent;
use AnyEvent::HTTP;
@olegwtf
olegwtf / gist:7734836
Last active December 29, 2015 22:09
Coro based socks server through another socks server
use strict;
use Coro::PatchSet 0.04;
BEGIN {
package IO::Select;
use Coro::Select;
use IO::Select;
}
use IO::Socket::Socks qw(:constants :DEFAULT);
use Coro;
use Coro::Socket;
use strict;
package JUNOS::Config::Parser;
sub new {
my ($class, %cb) = @_;
bless \%cb, $class;
}
sub parse {
@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)