Skip to content

Instantly share code, notes, and snippets.

odule Authlogic::Session::Timeout::DontLockoutApiKeyOrHttpAuth
def self.included(klass)
klass.class_eval do
dont_lockout = "single_access? || persist_by_http_auth?"
before_persisting_callback_chain.detect {|c| c.method == :reset_stale_state }.options.update(:unless => dont_lockout)
after_persisting_callback_chain.detect {|c| c.method == :enforce_timeout }.options.update(:unless => dont_lockout)
end
end
end
@pwim
pwim / dateinput_converter.js
Created November 19, 2010 06:21
Convert Rails style date input to jQuery Tools' dateinput
// Based on http://snipt.net/boriscy/datetime-jquery-formtastic/
$.tools.dateinput.localize("ja", {
months: '1月,2月,3月,4月,5月,6月,7月,8月,9月,10月,11月,12月',
shortMonths: '1月,2月,3月,4月,5月,6月,7月,8月,9月,10月,11月,12月',
days: '日曜日,月曜日,火曜日,水曜日,木曜日,金曜日,土曜日',
shortDays: '日,月,火,水,木,金,土'
});
$.tools.dateinput.conf.format = 'yyyy-mm-dd';
@pwim
pwim / gist:984510
Created May 21, 2011 13:13
Facebook Graph API
# javascript
$(function() {
var ids = $('//[data-fb-id]').map(function(){
return $(this).data("fb-id");
})
$.unique(ids).each(function(){
FB.api('/' + this, function(r){
$("//[data-fb-id='"+ r["id"] + "']").each(function(){
var attr = $(this).data("fb-attr");
$(this).text(r[attr]);
@pwim
pwim / gist:1039790
Created June 22, 2011 10:00
Rails 3.1.rc4 segfault
Started GET "/assets/application.js" for 127.0.0.1 at 2011-06-22 18:54:39 +0900
Compiled app/assets/javascripts/application.js (4ms) (pid 65649)
Compiled ~/.rvm/gems/ruby-1.9.2-p180/gems/jquery-rails-1.0.11/vendor/assets/javascripts/jquery.js (1ms) (pid 65649)
Compiled ~/.rvm/gems/ruby-1.9.2-p180/gems/jquery-rails-1.0.11/vendor/assets/javascripts/jquery_ujs.js (0ms) (pid 65649)
Compiled vendor/assets/javascripts/externals.js (2ms) (pid 65649)
Compiled vendor/assets/javascripts/jshashtable-2.1.js (0ms) (pid 65649)
Compiled vendor/assets/javascripts/jquery.numberformatter-1.2.2.min.js (0ms) (pid 65649)
Compiled app/assets/javascripts/invoices.coffee (119ms) (pid 65649)
Compiled app/assets/javascripts/application.js (0ms) (pid 65649)
Served asset /application.js - 304 Not Modified (150ms) (pid 65649)
@pwim
pwim / gist:1042058
Created June 23, 2011 06:56
Rails 3.1 and after_intialize
class Invoice < ActiveRecord::Base
belongs_to :sender
after_initialize :assign_defaults
def assign_defaults
if new_record? && sender
self.fax ||= sender.fax
end
end
end
@pwim
pwim / gist:1188099
Created September 2, 2011 07:34
Trying different encodings under Ruby 1.9
escaped = CGI.unescape(query)
return escaped if escaped.valid_encoding?
%w[EUC-JP Shift_JIS].each do |encoding|
s = escaped.force_encoding(encoding)
return s.encode("UTF-8") if s.valid_encoding?
end
escaped
@pwim
pwim / widget.js
Created March 2, 2012 02:57
Widget Javascript Manifest
//= require getElementsByClassName-1.0.1
//= require domready
//= require_tree ./widget
@pwim
pwim / globalize_accessors.rb
Created March 14, 2012 05:29
GlobalizeAccessors
# allows directly accessing the locale specific fields such as text_en and text_ja without using fallbacks
module GlobalizeAccessors
def translates(*attr_names)
super
attr_names.each do |attr_name|
I18n::AVAILABLE_LOCALES.map(&:to_sym).each do |locale|
# writer
define_method :"#{attr_name}_#{locale}=" do |value|
write_attribute(attr_name, value, :locale => locale)
end
@pwim
pwim / boundio-example.rb
Created March 23, 2012 04:12
Boundio Example
#!/usr/bin/env ruby
# encoding: UTF-8
require "boundio"
require "csv"
include Boundio
greeting = AudioFile.create(:convtext => "こんにちは、")
message = AudioFile.create(:convtext => "さん。")
CSV.parse($stdin) do |row|
input#profile_min_age, input#profile_max_age {
width: 26px;
}
input#profile_height, input#profile_min_seek_height, input#profile_max_seek_height {
width: 36px;
}