Skip to content

Instantly share code, notes, and snippets.

@murugan-r
murugan-r / gist:3046056
Created July 4, 2012 08:19 — forked from lunks/gist:953763
i18n issue
class Order < ActiveRecord::Base
has_many :order_items
validates_length_of :order_items, :minimum => 1, :message => :empty
accepts_nested_attributes_for :order_items
end
#en.yml
activerecord:
@murugan-r
murugan-r / add.js.erb
Created July 4, 2012 08:20 — forked from amardaxini/add.js.erb
redis i18n
<tr>
<td><%=@key.split(".").drop(1) %></td>
<td><%= @value%></td>
</tr>
@murugan-r
murugan-r / 0-readme.md
Created October 2, 2012 07:57 — forked from burke/0-readme.md
ruby-1.9.3-p194 cumulative performance patch.

Patched ruby 1.9.3-p194 for 30% faster rails boot

Overview

This script installs a patched version of ruby 1.9.3-p194 with boot-time performance improvements (#66 and #68), and runtime performance improvements (#83 and #84). It also includes the new backported GC from ruby-trunk.

Many thanks to funny-falcon for the performance patches.

This is how we test that all translation keys match up between locales.

Stuff that only goes in one locale (such as an admin section) or that can't be translated yet (if you use external translators) can simply go in files that don't match the path "config/locales/??.yml", like "config/locales/wip.fo.yml".

# Ways to execute a shell script in Ruby
# Example Script - Joseph Pecoraro
cmd = "echo 'hi'" # Sample string that can be used
# 1. Kernel#` - commonly called backticks - `cmd`
# This is like many other languages, including bash, PHP, and Perl
# Returns the result of the shell command
# Docs: http://ruby-doc.org/core/classes/Kernel.html#M001111
#!/usr/bin/ruby1.9.1 -Kw
# -*- coding: utf-8 -*-
class Edge
attr_accessor :src, :dst, :length
def initialize(src, dst, length = 1)
@src = src
@dst = dst
@length = length

Rails 4 Differences

Chapter 1

No differences.

Chapter 2

  • root :to => "dashboard#index" is now root "dashboard#index"`
  • Need to permit parameters within Subscribem::AccountsController
@murugan-r
murugan-r / gist:bf59d6b373f513c6544e
Created August 2, 2014 16:00
More strict web URL regex for validations. (better then URI.regexp)
require 'uri'
hostname = "(?:(?:[\\w\\-]+\\.)+[[:alpha:]]{2,})"
host = "(?:#{hostname}|#{URI::DEFAULT_PARSER.pattern[:IPV4ADDR]}|#{URI::DEFAULT_PARSER.pattern[:IPV6ADDR]})"
server = "//(?:#{URI::DEFAULT_PARSER.pattern[:USERINFO]}@)?#{host}(?::\\d*)?"
absolute_path = "(?:#{URI::DEFAULT_PARSER.pattern[:ABS_PATH]})?"
query = URI::DEFAULT_PARSER.pattern[:QUERY]
http_uri_regex = Regexp.new("\\A(?:http|https):(?:#{server}#{absolute_path})(?:\\?(?:#{query}))?\\z", Regexp::EXTENDED, 'N')
# put the cookbook path in solo.rb file.
echo 'cookbook_path ["/opt/aws/opsworks/current/site-cookbooks"]' > solo.rb
# create json file incase if you want use the attributes from opsworks.
opsworks-agent-cli get_json > attributes.json
#run chef-solo
/opt/aws/opsworks/current/bin/chef-solo -c solo.rb -o cookbook_name::default -j attributes.json --log_level=debug
curl -kL http://install.perlbrew.pl | sed "/\$PERLBREWDOWNLOAD/{N;s|$|sed -i -r '/@INC/ s/([)][}])/ vendorlib vendorarch\\\1/' \\\$LOCALINSTALLER\n|}" | bash