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 ruby | |
#-*- coding: utf-8 -*- | |
#* required yaml format | |
#=begin | |
#global: | |
# ip: 127.0.0.1 | |
# site: | |
# myhost: example.com | |
# id: hoge |
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 ruby | |
class Integer | |
def prime? | |
return false if self < 2 | |
return true if self == 2 | |
return false if self % 2 == 0 | |
max = Math::sqrt(self).ceil | |
(3..max).step(2) {|i| | |
return false if (self % i == 0) | |
} |
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
#template.rb | |
# Set up initializer | |
initializer 'myconfig.rb', <<-END | |
Rails::Initializer.run do |config| | |
config.action_controller.session = { | |
:key => '_myapp_session', | |
:secret => '#{(1..40).map { |x| (65 + rand(26)).chr }.join}' | |
} | |
config.action_controller.relative_url_root='/myapp' |
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 ruby | |
require 'rubygems' | |
require 'twitter' | |
# config_file format from: | |
# http://twitter4r.rubyforge.org/rdoc/classes/Twitter/Client.html#M000050 | |
# | |
# envname: | |
# login: mytwitterlogin | |
# password: mytwitterpassword |
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 ruby | |
require 'dl/import' | |
module LIBC | |
extend DL::Importable | |
dlload "libc.dylib" | |
extern "int strlen(char *)" | |
end | |
puts LIBC.strlen("hogehoge") |
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
# Usage: | |
# ruby twitter_stream_api_test.rb USERNAME PASSWORD | |
require 'rubygems' | |
require "socket" | |
require 'base64' | |
require 'json' | |
username, password = *ARGV[0..1] |
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
class Object | |
def send_through(object, *args) | |
object.dispatcher_for(self).call(self, *args) | |
end | |
end | |
module Dispatcher | |
class DispatcherNotFound < StandardError; end | |
def self.extended(klass) |
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/ruby | |
RLSP_VERSION = "1.4.1" | |
class Lambda | |
attr_accessor :args, :body | |
def initialize(args=[],body="") | |
@args = (args.class == Array) ? args : [args] | |
@body = body | |
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
<?php | |
require 'Benchmark/Timer.php'; | |
$timer = new Benchmark_Timer(); | |
$a = array(1,2,3,4,5); | |
$max = 20; | |
function _map($i) { return $i . 'hoge';} | |
$timer->start(); |
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 ruby | |
# -*- coding: utf-8 -*- | |
def merge ary1, ary2 | |
new_ary = [] | |
until (ary1.empty? || ary2.empty?) | |
if ary1.first < ary2.first | |
new_ary << ary1.shift | |
else | |
new_ary << ary2.shift | |
end |
OlderNewer