This file contains 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
module M | |
def method; "method" end | |
def self.included(klass) | |
klass.extend ClassMethods | |
end | |
module ClassMethods | |
def c_method; "c_method" end | |
end |
This file contains 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
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use WWW::Mechanize; | |
use HTML::TreeBuilder::XPath; | |
use YAML; | |
use Encode; | |
use utf8; |
This file contains 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
(defun blank-line? () | |
(string-match "^\n$" (substring-no-properties (thing-at-point 'line)))) | |
(defun move-to-next-blank-line () | |
(interactive) | |
(progn (forward-line 1) | |
(if (blank-line?) () (move-to-next-blank-line)))) | |
(defun move-to-previous-blank-line () | |
(interactive) |
This file contains 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
arr = (1..3).to_a.cycle | |
arr.next # => 1 | |
arr.next # => 2 | |
arr.next # => 3 | |
arr.next # => 1 | |
arr.next # => 2 | |
arr.next # => 3 以下繰り返し | |
a = ('a'..'z').to_a |
This file contains 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
# coding:utf-8 | |
class NinjaGreeting | |
def initialize | |
@ninja = {} | |
end | |
def greet( name ) | |
puts @ninja[ name ] ||= begin | |
warn( 'First call' ) |
This file contains 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
params = (0..5).step(1) | |
multitask :deploy => [*params.map{|i| "task_#{i}"}] do | |
puts "Complete!" | |
end | |
params.each do |param| | |
task "task_#{param}" do |task| | |
puts "-- #{task.name} : #{param} --" | |
end |
This file contains 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
desc "Repeater" | |
task :repeat do | |
3.times do |i| | |
Rake::Task[:t].execute(i) | |
puts '---' | |
end | |
end | |
desc "Small task" | |
task :t, :arg do |task, arg| |
This file contains 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
words = open( stop_words_file ).readlines.map(&:chomp) | |
# 2行使うが分かりやすい | |
stop_words = {} | |
words.each {|word| stop_words[word] = true } | |
stop_words = Hash[ *words.zip([true]*words.size) ] # 醜い? | |
stop_words = Hash[ *words.map{|word| [word, true]} ] # 少し遅い? |
This file contains 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
# coding:utf-8 | |
require 'tweetstream' | |
TweetStream.configure do |config| | |
config.consumer_key = CONSUMER_KEY | |
config.consumer_secret = CONSUMER_SECRET | |
config.oauth_token = OAUTH_TOKEN | |
config.oauth_token_secret = OAUTH_SECRET | |
config.auth_method = :oauth | |
config.parser = :yajl |
This file contains 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
# coding:utf-8 | |
require 'date' | |
class AnkiData | |
include Enumerable | |
def initialize( &block ) | |
@anki_set_maker = block | |
@data = Array.new | |
end |