Skip to content

Instantly share code, notes, and snippets.

View yowcow's full-sized avatar
💮
Job well done

Yoko OYAMA yowcow

💮
Job well done
View GitHub Profile
@yowcow
yowcow / gist:2307997
Created April 5, 2012 04:44
Funny Mac OS X UTF-8
perl -MEncode -e 'print Encode::encode("utf8", "\x{264b}");'
@yowcow
yowcow / gist:5192987
Created March 19, 2013 01:45
Minimal exception handling
use strict;
use warnings;
use Carp ();
sub try (&@) {
my $try = shift;
my ($catch, @finally);
while (my ($kind, $coderef) = splice @_, 0, 2) {
if ($kind eq 'catch') {
$catch = $coderef;
@yowcow
yowcow / request.pl
Created October 15, 2014 08:26
"Request" class method "param" comparison
use common::sense;
use HTTP::Message::PSGI;
use HTTP::Request::Common;
use Test::More;
use Test::Pretty;
use Test::Stub;
my $env = (GET "http://hoge/?name=foo&name=bar")->to_psgi;
subtest 'Plack::Request' => sub {
@yowcow
yowcow / anyevent-server.pl
Created November 20, 2014 13:26
Simple non-blocking server
use common::sense;
use AnyEvent;
use AnyEvent::Socket;
use AnyEvent::Handle;
use Data::Dumper;
my $cv = AnyEvent->condvar;
my %clients;
my %names;
@yowcow
yowcow / mojolicious-6.pl
Created December 24, 2015 10:38
Mojolicious 6 hints
use common::sense;
use Data::Dumper;
use Encode ();
use JSON::XS qw(decode_json);
use Mojo::Util qw(monkey_patch);
use Mojolicious::Lite;
use Test::Deep;
use Test::Mojo;
use Test::More;
use Test::Pretty;
@yowcow
yowcow / perl5-ipc-pipe.pl
Created January 16, 2016 14:55
Simple IPC with pipe
use common::sense;
pipe my $read, my $write;
my @pids;
for (1 .. 5) {
my $pid = fork // die "Failed: $!";
if ($pid) { # Parent
@yowcow
yowcow / p5-parallel-http.pl
Created January 19, 2016 12:38
Parallel HTTP request in Perl 5
use common::sense;
use LWP::UserAgent;
use HTTP::Request::Common;
use POSIX qw(:sys_wait_h);
use Test::More;
my @urls = qw(
http://hoge.fuga/
http://fuga.hoge/
http://fooo.baar/
@yowcow
yowcow / p6-parallel-http.p6
Created January 19, 2016 12:46
Parallel HTTP request in Perl 6
use v6;
use HTTP::UserAgent;
use HTTP::Request;
use Test;
use URI;
my Str @urls = "http://hoge.fuga/",
"http://fuga.hoge/",
"http://fooo.baar/";
@yowcow
yowcow / php-pdo.php
Created January 26, 2016 03:11
Connect to MySQL with PDO in PHP
<?php
# Specify `charset=utf8` or you get multi-byte chars as "?"
$dbh = new PDO('mysql:host=some-host-name;dbname=databse-name;charset=utf8', 'user', 'password');
@yowcow
yowcow / p5-multipart-request.pl
Created February 25, 2016 05:08
Multipart form data with HTTP::Request::Common
use common::sense;
use HTTP::Request::Common;
use LWP::UserAgent;
{
my $req = POST 'http://localhost:8888/test.php',
Content_type => 'form-data',
Content => {
myname => 'hogefuga',
myfile1 => [ 'file.txt', 'file.txt' ],