Skip to content

Instantly share code, notes, and snippets.

require 'htmlentities'
require 'i18n/backend/active_record'
module I18n
module Backend
require 'i18n/core_ext/object/meta_class'
# Just to enhance the I18n.
module JustALoader
include Metadata
module TranslationHelper
# foo = ActionView::Base.new.extend TranslationHelper
# TODO: If translation is missing
# get a translation from google
# and then add it to database, marked as dirty (how?)
def translate(key, options = {})
key = scope_key_by_partial(key)
options[:raise] = true
options[:request_locale] = options.has_key?(:locale) ? options[:locale] : I18n.locale
@jtsagata
jtsagata / run_tools
Created January 31, 2011 10:59
Run all rails tools in a KDE konsole
#!/bin/bash
#
# Create all konsoles with the rails tools!
#
# Create konsole Profiles with names RailsServer, RailsConsole etc..
# Set a static Title and a nice icon
# setTitle is not really working yet ...
# http://www.linuxjournal.com/node/1009239
# ref: http://bit.ly/fN2ep8
# http://twitpic.com/3rr8dk
def sass_colors
engine= Sass::Engine.new(File.read("app/stylesheets/_colors.scss"), :syntax => :scss, :load_paths => ["app/stylesheets"])
environment= Sass::Environment.new
visitor = Sass::Tree::Visitors::Perform.new(environment)
engine.to_tree.children.each do | node |
next unless node.kind_of? Sass::Tree::VariableNode
visitor.send(:visit, node)
@jtsagata
jtsagata / Gemfile
Created March 23, 2012 02:25
DRY Controller Example
gem 'responders'
gem 'has_scope'
gem 'kaminari'
# TODO: Find a better gem
gem 'csv_builder'
@jtsagata
jtsagata / test.rb
Created April 24, 2012 21:11
HStore
class Product < ActiveRecord::Base
attr_accessible :name, :category, :price, :description
validates_numericality_of :runtime, allow_blank: true
%w[author rating runtime].each do |key|
attr_accessible key
scope "has_#{key}", lambda { |value| where("properties @> (? => ?)", key, value) }
define_method(key) do
properties && properties[key]
options = %w(spaghetti beaf chicken salads fruit)
favs = []
def valid_answer(reply)
%w(yes no).include? reply
end
def ask question
reply = ""
@jtsagata
jtsagata / .tmux.conf
Created July 10, 2012 20:08
Tmux config
# Set the prefix to ^\
unbind C-b
set -g prefix `
bind-key ` send-prefix
# Set delay
set -sg escape-time 1
set -g base-index 1
setw -g pane-base-index 1
bind r source-file ~/.tmux.conf \; display "Config file reloaded!"
@jtsagata
jtsagata / admin.rb
Created July 11, 2012 20:31
ActiveAdmin template
# lib/templates/active_admin/resource/admin.rb
ActiveAdmin.register <%= class_name %> do
<% attributes = Kernel.const_get(class_name).attribute_names %>
<% columns = Kernel.const_get(class_name).columns %>
<% content_columns = Kernel.const_get(class_name).content_columns %>
# <%= class_name %> attributes are:
# <%= attributes.join(" ") %>
# The Index Page
index do |i|
@jtsagata
jtsagata / Readme
Created July 12, 2012 00:27
Linux rails-footnotes sublime-text-2
copy handler to /usr/local/bin
copy desktop file to /usr/share/applications
sudo update-desktop-database