Skip to content

Instantly share code, notes, and snippets.

View authlogic_dont_lockout_api_key_or_http_auth.rb
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)
pwim / dateinput_converter.js
Created Nov 19, 2010
Convert Rails style date input to jQuery Tools' dateinput
View dateinput_converter.js
// Based on
$.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 / gist:984510
Created May 21, 2011
Facebook Graph API
View gist:984510
# javascript
$(function() {
var ids = $('//[data-fb-id]').map(function(){
return $(this).data("fb-id");
FB.api('/' + this, function(r){
$("//[data-fb-id='"+ r["id"] + "']").each(function(){
var attr = $(this).data("fb-attr");
pwim / gist:1039790
Created Jun 22, 2011
Rails 3.1.rc4 segfault
View gist:1039790
Started GET "/assets/application.js" for 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/ (119ms) (pid 65649)
Compiled app/assets/javascripts/application.js (0ms) (pid 65649)
Served asset /application.js - 304 Not Modified (150ms) (pid 65649)
pwim / gist:1042058
Created Jun 23, 2011
Rails 3.1 and after_intialize
View gist:1042058
class Invoice < ActiveRecord::Base
belongs_to :sender
after_initialize :assign_defaults
def assign_defaults
if new_record? && sender
self.fax ||= sender.fax
pwim / gist:1188099
Created Sep 2, 2011
Trying different encodings under Ruby 1.9
View gist:1188099
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?
pwim / widget.js
Created Mar 2, 2012
Widget Javascript Manifest
View widget.js
//= require getElementsByClassName-1.0.1
//= require domready
//= require_tree ./widget
View globalize_accessors.rb
# allows directly accessing the locale specific fields such as text_en and text_ja without using fallbacks
module GlobalizeAccessors
def translates(*attr_names)
attr_names.each do |attr_name| do |locale|
# writer
define_method :"#{attr_name}_#{locale}=" do |value|
write_attribute(attr_name, value, :locale => locale)
View boundio-example.rb
#!/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|
View original.css
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;