Skip to content

Instantly share code, notes, and snippets.

View olegwtf's full-sized avatar

Oleg olegwtf

  • reg.ru
  • Russia, Novosibirsk
View GitHub Profile
#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";
@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
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 / 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;
package JUNOS::Config::Parser;
sub new {
my ($class, %cb) = @_;
bless \%cb, $class;
}
sub parse {
@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;
@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:7464791
Last active December 28, 2015 07:29
Mojolicious & IO::Async
use strict;
use v5.10;
BEGIN {
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
$ENV{MOJO_IOLOOP_DEBUG} = 1;
}
use Mojo::IOLoop;
use Mojo::UserAgent;
use Net::Async::HTTP;
use URI;
use strict;
use QtCore4;
use QtGui4;
package Ui_MainWindow;
use strict;
use warnings;
use QtCore4;
use QtGui4;
@olegwtf
olegwtf / gist:4259527
Created December 11, 2012 15:51 — forked from sharifulin/gist:335531
Nested layouts for the Mojolicious
#!/usr/bin/env perl
use Mojolicious::Lite;
get '/' => 'index';
get '/ok' => 'index_ok';
use Test::More;
plan tests => 6;