Skip to content

Instantly share code, notes, and snippets.

@laurynas
laurynas / mail_delivery_catchall.rb
Created January 6, 2011 18:32
Add option to deliver all ActionMailer mails to one address. Useful in staging environment.
# Initializer:
# require 'mail_delivery_catchall.rb' if Rails.env.staging?
# Rails 3
module ActionMailer
class Base
class << self
def deliver_mail_with_catchall(mail, &block)
@laurynas
laurynas / will_paginate_jquery_mobile_renderer.rb
Created December 30, 2010 16:12
Rails3 will_paginate Jquery Mobile renderer
class WillPaginateJqueryMobileRenderer < WillPaginate::ViewHelpers::LinkRenderer
def container_attributes
super.merge({
:'data-role' => 'navbar'
})
end
def pagination
@options[:page_links] ? windowed_page_numbers : []
@laurynas
laurynas / fix_html_helper.rb
Created November 29, 2010 08:44
Fix invalid html using Nokogiri
# Close unclosed tags
def fix_invalid_html(html)
Nokogiri::HTML::DocumentFragment.parse(html).to_html
end
@laurynas
laurynas / globalize3_hash_setter_patch.rb
Created November 26, 2010 23:11
Allow setting hash values for Globalize3 (hash keys - locale codes)
module Globalize
module ActiveRecord
class Adapter
def write_with_hash(locale, name, value)
if value.is_a?(Hash)
value.each do |locale, value|
self.write_without_hash(locale, name, value)
end
else
@laurynas
laurynas / item.rb
Created November 26, 2010 10:00
SearchLogic problem with left join in order SOLVED!
class Item < ActiveRecord::Base
named_scope :ascend_by_optional_category_title,
:joins => "LEFT JOIN categories AS optional_categories ON optional_categories.id=items.category_id",
:order => "optional_categories.title"
named_scope :descend_by_optional_category_title,
:joins => "LEFT JOIN categories AS optional_categories ON optional_categories.id=items.category_id",
:order => "optional_categories.title DESC"
@laurynas
laurynas / mail_delivery_catchall.rb
Created November 24, 2010 09:50
Add option to deliver all mails to one address. Useful in staging environment.
# Add option to deliver all mails to one address. Useful in staging environment.
# config.action_mailer.delivery_method = :catchall
module ActionMailer
class Base
def perform_delivery_catchall(mail)
original_to = mail.to
mail.to = "youremail@yourdomain"
mail.cc = ""
@laurynas
laurynas / watermark.rb
Created November 20, 2010 19:27
Paperclip Watermark processor
# Based on
# https://github.com/ng/paperclip-watermarking-app/blob/master/lib/paperclip_processors/watermark.rb
# Modified by Laurynas Butkus
module Paperclip
class Watermark < Processor
# Handles watermarking of images that are uploaded.
attr_accessor :format, :whiny, :watermark_path, :position
def initialize file, options = {}, attachment = nil
@laurynas
laurynas / form_builder_helper.rb
Created November 15, 2010 21:20
Add multi_locale_field helper to form builer
module FormBuilderHelper
def multi_locale_field(method, opts = {})
opts = {
:type => :text_field
}.merge(opts)
type = opts.delete(:type)
html = []
@laurynas
laurynas / update_geolite_cities.sh
Created November 4, 2010 12:15
Fetch GeoLite Cities database from MaxMind
#!/bin/sh
#
# Update GeoLite Cities database from MaxMind
# (C) 2010 Laurynas Butkus laurynas.butkus at gmail.com
#
TMP=/tmp
TARGET_DIR=/usr/local/share/GeoIP
cd $TMP
@laurynas
laurynas / gist:658139
Created November 1, 2010 13:12
Berlin (nuo Dončiaus)
Usualy we hang out in Kreuzberg, Friedrichshein and Prenzlauerberg areas as well as Mitte (center).
http://berlin.unlike.net/locations/39-Club-der-Visionaere
Club der Visionaere - an outside bar/club/place to hang out in Kreuzberg. It's IN one of the canals, on some sort of floating rafts.
Schlesische str., leading to the club is also worth noticing with one of the best indian food restaurants and lots of small watering holes. L.U.X .with live bands and Vendel with experimental poetry in german are my favourites:)
Bar 25 - another outside bar on the bank of river. 3 day parties or just to sit back and spend a warm afternoon. Also has circus, motel and restaurant.
http://berlin.unlike.net/locations/272-Bar-25
Hops & Barley brewery pub (Friedrichshain) - locally brewed beer in one of my favourite neighbourhoods. The whole area between Boxhander str and Simon Dach str. is dense with pubs, thai food restaurants and Kieze-kiosks (small shops with astounishing variety of beers).