Skip to content

Instantly share code, notes, and snippets.

@no6v
no6v / local_ip.rb
Created October 12, 2008 20:05
local_ip for rails' controller
module ::ActionController
class Request
unless method_defined?(:local_ip)
require "socket"
require "ipaddr"
def local_ip
f = Socket.do_not_reverse_lookup
Socket.do_not_reverse_lookup = true
ip = IPAddr.new(remote_ip)
@no6v
no6v / irb-block-history-1.8.7.patch
Created November 2, 2008 11:54
block-awareness history handling for irb
diff --git a/irb/context.rb b/irb/context.rb
index de70945..0c114ef 100644
--- a/irb/context.rb
+++ b/irb/context.rb
@@ -215,6 +215,7 @@ module IRB
end
def evaluate(line, line_no)
+ @io.savehist
@line_no = line_no
#!/usr/bin/env ruby
require 'rubygems'
require 'open-uri'
require 'nokogiri'
module Jleague
module_function
def miniscore2mobile
uri = "http://www.tbs.co.jp/supers/miniscore#{rand( 3 ) + 1}.htm"
@no6v
no6v / cat.rb
Created April 26, 2009 00:46
cat(1)
#!ruby1.9
# -*- coding: us-ascii -*-
Encoding.default_external = "ASCII-8BIT"
require "optparse"
def squeeze_blank
re = /\A\Z/
lfd = 0
->(block) do
block.replace(
# What?
# Monkey patch for https://rails.lighthouseapp.com/projects/8994/tickets/1708
#
# Where?
# Rails 2.3.2 (gem)
# $ rails test_foo
# $ cd test_foo
# $ ruby script/generate model TestFoo name:string
# $ rake db:migrate RAILS_ENV=test
# $ env RAILS_ENV=test ruby -I test test/unit/test_foo_test.rb -v
@no6v
no6v / test-result-changes-from-ruby-dev39038.diff
Created September 12, 2009 01:15
Hmm, +1F with the patch in [ruby-dev:39038].
--- /tmp/prev 2009-09-12 10:12:20.000000000 +0900
+++ /tmp/post 2009-09-12 10:12:25.000000000 +0900
@@ -1,14 +1,14 @@
-Finished in 518.233488 seconds.
+Finished in 535.442002 seconds.
1) Failure:
test_free=(DL::TestCPtr) [/var/tmp/ruby/trunk/test/dl/test_cptr.rb:12]:
[ruby-dev:39269]
-pid 834 killed by SIGABRT (signal 6)
module Rack
class Lint
unless method_defined?(:call_with_close)
def call_with_close(env = nil)
call_without_close(env).tap do |status, headers, body|
body.close if body.respond_to?(:close)
end
end
alias_method_chain :call, :close
@no6v
no6v / recvgrowl.rb
Created November 23, 2009 06:33 — forked from ohac/recvgrowl.rb
#!/usr/bin/ruby
require 'rubygems'
require 'ruby-growl'
require 'socket'
require 'shellwords'
require 'cgi'
UDPSocket.open do |u|
u.bind('localhost', Growl::GROWL_UDP_PORT)
loop do
@no6v
no6v / bt
Created November 29, 2009 02:38
GNU gdb (GDB) 7.0-debian
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /usr/lib/debug/usr/bin/ruby1.8...done.
@no6v
no6v / bt
Created November 29, 2009 23:14
ruby 1.8.7 (2009-11-25 patchlevel 225) [i686-linux]
GNU gdb (GDB) 7.0-debian
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu".
For bug reporting instructions, please see: