Skip to content

Instantly share code, notes, and snippets.

@hamakn
hamakn / hoge.php
Last active November 19, 2015 07:35
Crypt by Blowfish CBC / work with PHP using ZeroBytePadding
<?php
require_once 'Crypt/Blowfish.php';
$data = "test text";
$key = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
$iv = "bbbbbbbb";
$blowfish = Crypt_Blowfish::factory('cbc', $key, $iv); # Crypt_Blowfish-1.1.0RC2 only
$encrypted_data = $blowfish->encrypt($data);
echo base64_encode($encrypted_data) . "\n";
@hamakn
hamakn / quicksort.rb
Created December 25, 2012 18:46
quicksort
def quicksort(arr)
return arr if arr.size <= 1
pivot = arr.last
f, l = 0, arr.size - 1
loop do
loop { break if arr[f].nil? || arr[f] > pivot; f += 1 }
loop { break if arr[l].nil? || arr[l] < pivot; l -= 1 }
break if l < f
arr[f], arr[l] = arr[l], arr[f]
end
@hamakn
hamakn / 11st_cfcrjp.md
Created January 29, 2013 08:49
11st Cloud Foundry 輪読会 ホワイトボードのまとめ

11st Cloud Foundry 輪読会 ホワイトボードのまとめ

2013-01-28 atnd

Cloud Foundryについて興味のあること

  • 何かアプリを乗せる話
  • Java
@hamakn
hamakn / gist:5079781
Created March 4, 2013 03:50
perlbrew install perl-5.16.2 failed
% perlbrew install perl-5.16.2
Fetching perl 5.16.2 as /Users/katsunori.kawaguchi/perl5/perlbrew/dists/perl-5.16.2.tar.bz2
Installing /Users/katsunori.kawaguchi/perl5/perlbrew/build/perl-5.16.2 into ~/perl5/perlbrew/perls/perl-5.16.2
This could take a while. You can run the following command on another shell to track the status:
tail -f ~/perl5/perlbrew/build.perl-5.16.2.log
Installation process failed. To spot any issues, check
@hamakn
hamakn / gist:5131299
Last active December 14, 2015 18:39 — forked from yssk22/gist:5128840
use 5.016;
use DateTime;
# beginning_of_day
say DateTime->now( time_zone=>'local' )->truncate( to => "day" )->strftime('%Y/%m/%d %H:%M:%S')
# => 2013/03/15 00:00:00
# サマータイムで存在しない時刻を指定すると例外
# (America/Chicago時刻では、2003-04-06 01:59:59 の次は 2003-04-06 03:00:00)
DateTime->new( time_zone => 'America/Chicago', year => 2003, month => 4, day => 6, hour => 2, minute => 0, second => 0 );
@hamakn
hamakn / Guardfile
Last active December 15, 2015 11:29
perl用Guadfile (主にUNIVERSAL::requireでsyntax errorが出てこなくなる対策)
require "open3"
require "colorize"
guard 'shell' do
watch(/(.*).pm/) do |m|
arr = Open3.capture3("perl -c #{m[0]}")
line = arr.first.split("\n").first
unless line =~ /syntax OK/
puts line.red
else
@hamakn
hamakn / gist:5262528
Created March 28, 2013 11:37
1ヶ月を足す、とは
[1] pry(main)> require "active_support/time"
=> true
[2] pry(main)> Time.parse("2013-03-31").next_month
=> 2013-04-30 00:00:00 +0900
re.pl$ use DateTime
re.pl$ DateTime->new(year => 2013, month => 3, day =>31)->add( months => 1)->ymd;
"2013-05-01"
@hamakn
hamakn / encode.pl
Last active December 15, 2015 16:29
prelの内部文字列がわかってなくて死んだ
use 5.016;
use utf8;
use Encode;
use Encode::Guess qw/utf8 euc-jp shiftjis/;
my $str = 'あああ';
say guess_encoding($str)->name;
# => utf8
@hamakn
hamakn / hoge.pl
Created December 16, 2015 07:59
open pull request
#!perl
use strict;
use warnings;
# ref: http://techlife.cookpad.com/entry/2015/11/17/151426
my $commit_hash = $ARGV[0];
unless ($commit_hash) {
print "usage: open_pull_request <commit_hash>\n";