Skip to content

Instantly share code, notes, and snippets.

@gom
gom / dyndns.rb
Created December 12, 2008 15:50
Update DDNS at Dyndns.org
#!/usr/bin/env ruby
#-*- coding: utf-8 -*-
#* required yaml format
#=begin
#global:
# ip: 127.0.0.1
# site:
# myhost: example.com
# id: hoge
#!/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)
}
@gom
gom / gist:60380
Created February 8, 2009 13:19
my rails application template
#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'
@gom
gom / twcl.rb
Created February 10, 2009 05:06
Post my status to twitter
#!/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
#!/usr/bin/env ruby
require 'dl/import'
module LIBC
extend DL::Importable
dlload "libc.dylib"
extern "int strlen(char *)"
end
puts LIBC.strlen("hogehoge")
# Usage:
# ruby twitter_stream_api_test.rb USERNAME PASSWORD
require 'rubygems'
require "socket"
require 'base64'
require 'json'
username, password = *ARGV[0..1]
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)
@gom
gom / rlsp.rb
Created November 9, 2009 05:02 — forked from h0rs3r4dish/rlsp.rb
#!/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
<?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();
#!/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