Skip to content

Instantly share code, notes, and snippets.

View tokuhirom's full-sized avatar
💖
Focusing

Tokuhiro Matsuno tokuhirom

💖
Focusing
View GitHub Profile
@tokuhirom
tokuhirom / .zshrc
Last active August 29, 2015 14:03
repos
e() { cd $(repos-list --null | peco --null) }
@tokuhirom
tokuhirom / epoch
Created May 16, 2014 09:52
The epoch command
#!/usr/bin/env perl
use strict;
use warnings;
use Time::Piece;
use Pod::Usage;
&main; exit;
sub show($) {
my $time = shift;
sub Member::get_ad($self, $id) {
my $ad = $self->db->find->ad($id) or throw NotFoundException->throw;
if ($ad->member_id eq $self->id) {
return $ad;
} else {
return SecurityException->throw(); # ここはもう
}
}
sub Controller::dispatch_update_ad($c) {
@tokuhirom
tokuhirom / gist:9928481
Created April 2, 2014 05:34
MemProfile.pm
package Devel::MemProfile;
use strict;
use warnings;
use utf8;
use 5.010_001;
use Devel::Symdump;
use B::Size2::Terse;
sub new {
my $class = shift;
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use 5.010000;
use autodie;
package URI::Lite {
use Class::Accessor::Lite 0.05 (
rw => [qw(scheme user password host port path query)],

SQLインジェクション対策について

教育的な観点ではなく実務的な観点から、僕の考えをまとめてみる。UTF-8 を利用し、SET NAMES を利用していなくて mysql で、クライアントプリペアドステートメントなケースを想定している。

SQL インジェクションとは

$foo=$_POST[‘id’];
query(“SELECT * FROM foo WHERE id=$foo”);

のように外部からの文字列をそのまま使用してクエリを組みたてたときに、意図せぬ SQL を発行されてしまう脆弱性のことである。

{
package HTTP::Body::JSON;
use JSON::XS;
use parent qw(HTTP::Body);
use HTTP::Body;
use Encode qw(encode_utf8);
$HTTP::Body::TYPES->{'application/json'} = __PACKAGE__;
sub spin {
@tokuhirom
tokuhirom / gist:7224787
Last active December 26, 2015 22:39
DOM 操作を jQuery をつかわずにおこなう方法のメモ

なぜ?

jQuery は便利だけど、ナマで DOM を操作することも最近やっと楽になりつつある。IE9 以後だけをサポートすれば DOM 操作もわりと楽だ。

というわけで、原点回帰して、DOM 操作を DOM API からおこなうことを復習しようとおもう。

対応ブラウザ

IE9 以後と、各ブラウザの最新版。

@tokuhirom
tokuhirom / gist:6851517
Created October 6, 2013 09:09
hackish でもなんでもなくて、バグってるだけじゃない?
http://hachiojipm.github.io/entry/2013-10-04-warn-die-hack.html
STDERR をキャプチャする hack は hack っぽいし、よいとして。。
my $version = try { ## ここのコードがhackishでよくわからん!!!
open my $fh, '>', \my $stderr;
local *STDERR = $fh;
$self->database_version;
close $fh;
};
@tokuhirom
tokuhirom / mop.md
Created October 2, 2013 20:19
MOP on Perl5

Get list of methods from meta class:

my @methods = Foo->^methods();