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 Hash | |
alias :old_default :default | |
def default(*args) | |
ret = old_default(*args) | |
ignore_these = [NilClass, TrueClass, FalseClass, Float, Symbol, Rational, Integer] | |
case ret | |
when *ignore_these: ret | |
else ret.dup | |
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
chars = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a | |
str = (1..50).map { chars[rand(chars.size)] }.join |
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 MessageMailer < Merb::MailController | |
include DataMapper::Validate | |
extend DataMapper::Validate::ClassMethods | |
def attribute_get(sym); @params[sym] end | |
def attribute_set(sym, val); @params[sym] = val end | |
[:from].each { |s| | |
class_eval " | |
def #{s}; attribute_get(:#{s}) 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 ruby | |
# A quick and dirty image combiner for CSS sprites | |
# Name your files something along the lines of file_name_1.jpg (all with same extensions, | |
# including casing if important on your OS) and this script will combine them in order, | |
# create a directory named 'sprites' and put the resulting CSS sprite image in that dir. | |
# Run this script in the directory that contains files that you want to combine. Takes | |
# one argument, specifying the highest number that the script will go up to. It defaults to 3. | |
# So if you have # 4 images for each sprite, simply pass the number 4 to the script like so: | |
# ./spriter.rb 4 |
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
def urlize_parameters(obj, prefix = '') | |
case obj | |
when Hash: obj.map { |k,v| urlize_parameters(v, prefix.blank? ? k : "#{prefix}[#{k}]")}.join('&') | |
when Array: obj.map { |v| urlize_parameters(v, "#{prefix}[]")}.join('&') | |
else "#{prefix}=#{obj}" | |
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
require 'socket' | |
require 'base64' | |
class SSMTP < TCPSocket | |
def self.start(*args) | |
s = new(*args[0..1]) | |
s.start(*args[2..5]) | |
yield s | |
s.close | |
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
# Please note that I adapted this code from an ancient (5 year old) article on IBM's site. | |
# I Forget the URL... | |
require "socket" | |
class ChatServer | |
def initialize( port ) | |
@sockets = [] | |
@port = port | |
end # initialize | |
def run |
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
dlocate libmysqlclient | |
libmysqlclient15-dev: /. | |
libmysqlclient15-dev: /usr | |
libmysqlclient15-dev: /usr/include | |
libmysqlclient15-dev: /usr/include/mysql | |
libmysqlclient15-dev: /usr/include/mysql/mysql.h | |
libmysqlclient15-dev: /usr/include/mysql/mysql_com.h | |
libmysqlclient15-dev: /usr/include/mysql/mysql_time.h | |
libmysqlclient15-dev: /usr/include/mysql/my_list.h | |
libmysqlclient15-dev: /usr/include/mysql/my_alloc.h |
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
(in /usr/local/src/do/do_mysql) | |
To cross-compile, install rake-compiler (gem install rake-compiler) | |
rm -r coverage | |
/usr/local/src/do/do_mysql/lib/do_mysql_ext.so: libmysqlclient.so.16: cannot open shared object file: No such file or directory - /usr/local/src/do/do_mysql/lib/do_mysql_ext.so (LoadError) | |
from /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' | |
from /usr/local/src/do/do_mysql/lib/do_mysql.rb:10 | |
from /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' | |
from /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' | |
from /usr/local/src/do/do_mysql/spec/spec_helper.rb:29 | |
from ./spec/integration/do_mysql_spec.rb:4:in `require' |
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
(in /usr/local/src/do/do_mysql) | |
To cross-compile, install rake-compiler (gem install rake-compiler) | |
rm -r doc | |
rm -r pkg | |
/usr/local/bin/ruby extconf.rb | |
checking for mysql.h... yes | |
checking for main() in -lmysqlclient... yes | |
checking for mysql_query()... yes | |
checking for mysql_ssl_set()... yes | |
creating Makefile |