Skip to content

Instantly share code, notes, and snippets.

class TeachPgToGroupConcat < ActiveRecord::Migration
def self.up
return unless adapter_name == "PostgreSQL"
execute <<-EOF
CREATE FUNCTION _group_concat(text, text, text)
RETURNS text AS $$
SELECT CASE
WHEN $2 IS NULL THEN $1
WHEN $1 IS NULL THEN $2
ELSE $1 operator(pg_catalog.||) $3 operator(pg_catalog.||) $2
@maxlapshin
maxlapshin / sqlite_group_concat.rb
Created February 26, 2009 22:23
Sqlite group_concat
module ActiveRecord
module ConnectionAdapters
class SQLite3Adapter
def initialize(*args)
Rails.logger.debug "Adding group_concat to SQLite database"
super
raw_connection.create_aggregate("group_concat", 2) do
step do |func, value, separator|
if String(func[:concat]).empty? then
func[:concat] = String(value)
@maxlapshin
maxlapshin / production_images_download.rb
Created March 20, 2009 15:53
Production Images Download
# В config/initializers/development.rb
#
# config.middleware.insert_before(::Rack::Lock, ::ProductionImagesDownload, "www.lookatme.ru")
class ProductionImagesDownload
# Перехватывает отсутствующие картинки и пытается слить их с lookatme.ru
def initialize(app, host)
Rails.logger.debug "Production images downloader started"
@app = app
@host = host
module ActiveRecord
module ConnectionAdapters
class PostgreSQLAdapter
def quote_table_name(name)
schema, name_part = extract_pg_identifier_from_name(name.to_s)
return quote_column_name(schema) unless name_part
table_name, name_part = extract_pg_identifier_from_name(name_part)
"#{quote_column_name(schema)}.#{quote_column_name(table_name)}"
end
@maxlapshin
maxlapshin / flash_cookie.rb
Created April 24, 2009 13:24
Flash sessions rails 2.3.2
@maxlapshin
maxlapshin / message_verifier.rb
Created July 6, 2009 07:12
JSON session store
# This is a monkey patch for MessageVerifier — I need to change Marshal.load to JSON
if defined?(ActionController::Flash::FlashHash)
class ActionController::Flash::FlashHash
def to_json(*args)
{}.merge(self).merge({:used => @used}).to_json
end
end
end
#!/usr/bin/env ruby
require 'rubygems'
require 'sinatra'
require 'active_support'
require 'haml'
require 'thin'
gem 'tmm1-amqp'
require 'mq'
From 7bb6d8424ad931aee5b016c5986dcb4d0e12f5d2 Mon Sep 17 00:00:00 2001
From: Max Lapshin <max@maxidoors.ru>
Date: Tue, 28 Jul 2009 11:10:38 +0400
Subject: [PATCH] Added support for server redirection.
http://www.rabbitmq.com/clustering.html
---
lib/amqp/client.rb | 18 ++++++++++++++++++
1 files changed, 18 insertions(+), 0 deletions(-)
# = Schema Information
#
# Table name: *comments*
#
# id :integer not null, primary key
# user_id :integer not null
# commentable_id :integer not null
# commentable_type :string(255) not null
# body :text
# parent_id :integer
class AsyncRequestLogger
def initialize(app, logger = nil)
@app = app
@logger = logger || Logger.new(STDOUT)
end
def call(env)
time = Time.now
status, header, body = @app.call(env)
ensure