This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
require 'anemone' | |
Anemone.crawl('http://www.example.jp') do |anemone| | |
anemone.on_every_page do |page| | |
puts page.url | |
puts page.doc.xpath('//head/title/text()').first.to_s if page.doc | |
puts page.doc.xpath("//meta[@name='keywords']/@content") if page.doc | |
puts page.doc.xpath("//meta[@name='description']/@content") if page.doc | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// before | |
function talk($person, $dialogue) | |
{ | |
echo "{$person} 「{$dialogue}」" . PHP_EOL; | |
} | |
talk('Bob', 'Hi'); | |
talk('Alice', 'Hi'); | |
/* | |
* Bob 「Hi」 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# see also | |
# http://ja.wikipedia.org/wiki/%E3%82%AB%E3%83%AA%E3%83%BC%E5%8C%96 | |
# before | |
div = -> x, y { x / y } | |
p div.call(6, 2)# 6 | |
# currying | |
cdiv = -> x { return -> y { x / y } } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class DynamicMethod | |
{ | |
protected $dynamic_methods = array(); | |
public function __call($name, $args) | |
{ | |
if ($this->dynamic_methods[$name]) { | |
return call_user_func_array($this->dynamic_methods[$name], $args); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* fuel/app/classes/myvalidations.php */ | |
class MyValidations | |
{ | |
// Method name must start at '_validation_' | |
public static function _validation_something_check($value) | |
{ | |
return $value ? true : false; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* fuel/app/config/profile.php */ | |
return array( | |
'name' => 'akihito', | |
'twitter' => 'NAKANO_Akihito', | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- app/views/files/select.php --> | |
<p>Select</p> | |
<?php if (isset($html_error)): ?> | |
<?= $html_error; ?> | |
<?php endif; ?> | |
<?= Form::open(array('action' => 'files/upload', 'enctype' => 'multipart/form-data')); ?> | |
<div> | |
<?= Form::label('ファイル', 'uploadfile'); ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
class Computer | |
attr_accessor :display, :motherboard | |
attr_reader :drives | |
def initialize(display = :crt, motherboard = Motherboard.new, drives = []) | |
@display = display | |
@motherboard = motherboard | |
@drives = drives |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'find' | |
# Interpreter pattern in Ruby | |
# for search file | |
class Expression | |
def |(other) | |
Or.new(self, other) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Subject | |
{ | |
private $observers; | |
public $message; | |
public function __construct() | |
{ | |
$this->observers = new SplObjectStorage(); | |
} |