Skip to content

Instantly share code, notes, and snippets.

class SmthWitUrl < ActiveRecord::Base
validates_format_of :url, :with => URI.regexp(['http', 'https'])
end
Autotest.add_hook :initialize do |at|
unless ARGV.empty?
at.find_directories = []
at.extra_files = ARGV.dup
end
end
def error_messages_for(object)
object = instance_variable_get("@#{object}")
return if object.errors.empty?
result = "<div id=\"errorExplanation\"><h2>The following errors prohibited this form from being saved:</h2><ul>"
object.errors.full_messages.each { |msg| result << "<li>#{msg}</li>" }
result << "</ul></div>"
result.html_safe
end
<FilesMatch "\.atom">
AddDefaultCharset UTF-8
ForceType application/atom+xml
</FilesMatch>
<FilesMatch "\.atom">
ForceType 'application/atom+xml; charset=UTF-8'
</FilesMatch>
@ptzn
ptzn / gist:343756
Created March 25, 2010 16:24
#ifdef RUBY_18 #2
#ifdef RUBY_18
# define STR(x) (RSTRING(x)->ptr)
# define LEN(x) (RSTRING(x)->len)
# define STR_AUX_CAPA(x) (RSTRING(buf)->aux.capa)
# define SET_STR_LEN(x, i) (RSTRING(x)->len = i)
# define FLOAT(f) (RFLOAT(f)->value)
# define ARRAY(a) (RARRAY(a)->ptr)
# define ARRAY_LEN(a) (RARRAY(a)->len)
@ptzn
ptzn / gist:343752
Created March 25, 2010 16:22
#ifdef RUBY_18 #1
#ifdef RUBY_18
# include "rubyio.h"
# include "intern.h"
#else
# include "ruby/io.h"
# include "ruby/intern.h"
#endif
$CFLAGS << ' -DRUBY_18' if RUBY_VERSION =~ /1.8/
@ptzn
ptzn / gist:320505
Created March 3, 2010 10:26
passenger detection
if defined?(PhusionPassenger)
PhusionPassenger.on_event(:starting_worker_process) do |forked|
if forked
# We're in smart spawning mode.
else
# We're in conservative spawning mode. We don't need to do anything.
end
end
end
@ptzn
ptzn / gist:288917
Created January 28, 2010 16:56
js sample of getting i18n messages
I18n.t("foo.bar"); // -> "baz"
I18n.t("nested.hash"); // -> "value"
I18n.t("message.times", {count: 3}); // -> "3 times"
@ptzn
ptzn / gist:288913
Created January 28, 2010 16:54
key samples in translation.js
var Translations = {
locale: 'ru',
"foo.bar": "baz",
nested: {
hash: "value"
},
message: {
times: "{{count}} times"