Skip to content

Instantly share code, notes, and snippets.

#!/bin/sh
if [ $# -gt 0 ]; then
NAME=$1
virt-install \
--paravirt \
--name=$NAME \
--vcpus=1 \
--ram=256 \
#!/usr/bin/env perl
# Download PICS from HTML link in specified page.
# http://fetinavi.blog9.fc2.com/
use strict;
use warnings;
use HTML::LinkExtor;
use IO::File;
use LWP::UserAgent;
use URI;

test

test2

hoge

@takatoshiono
takatoshiono / 1hour-perl.md
Last active August 29, 2015 13:55
[WIP] 1時間でわかるPerl

準備する

現在の環境を確認しょう

$ perl -v
$ perl -V
$ which perl
@takatoshiono
takatoshiono / gist:8857495
Created February 7, 2014 04:49
Smarty3 と mb_internal_encoding
<?php
mb_internal_encoding('EUC-JP');
// http://www.smarty.net/docs/en/charset.tpl
// define('SMARTY_RESOURCE_CHAR_SET', 'EUC-JP');
require_once 'lib/smarty/Smarty.class.php'; // Smarty3
print mb_internal_encoding() . "\n"; // => EUC-JP
$smarty = new Smarty();
@takatoshiono
takatoshiono / gist:3d1116b34a57441ba5a8
Created May 15, 2014 07:28
モジュールとprivate

モジュールでは private 宣言しても private メソッドにならないけど、class << selfして特異クラスになると private メソッドを定義できるようになる。

$ irb
irb(main):001:0> module Foo
irb(main):002:1>   def self.hello
irb(main):003:2>     puts "Hello"
irb(main):004:2>   end
irb(main):005:1> end
=> :hello
#!/usr/bin/env ruby
# http://codekata.com/kata/kata02-karate-chop/
require 'test/unit'
def chop(target, values)
index = values.index(target)
index.nil? ? -1 : index
end
@takatoshiono
takatoshiono / test_chop.rb
Created August 20, 2014 14:20
1つ目のちゃんと動く実装
#!/usr/bin/env ruby
# http://codekata.com/kata/kata02-karate-chop/
require 'minitest/autorun'
def chop(target, values)
min_index = 0
half_index = values.length / 2
max_index = values.length - 1
@takatoshiono
takatoshiono / test_chop.rb
Created August 21, 2014 00:48
2つ目は再帰
#!/usr/bin/env ruby
# http://codekata.com/kata/kata02-karate-chop/
require 'test/unit'
def chop(target, values)
index = values.length / 2
return index if values[index] == target
return -1 if index.zero?
@takatoshiono
takatoshiono / test_chop.rb
Created August 26, 2014 00:19
これも再帰。ちょっと日を置いて書いたらすんなり書けた
#!/usr/bin/env ruby
# http://codekata.com/kata/kata02-karate-chop/
require 'test/unit'
def chop(target, values)
middle = values.length / 2
return -1 if values[middle].nil?
return middle if target == values[middle]