Skip to content

Instantly share code, notes, and snippets.

View reddyonrails's full-sized avatar

Jagan Reddy reddyonrails

View GitHub Profile
#!/usr/bin/env ruby
# Please read http://otobrglez.opalab.com for more information about this code.
class Book < Struct.new(:title)
def words
@words ||= self.title.gsub(/[a-zA-Z]{3,}/).map(&:downcase).uniq.sort
end
@reddyonrails
reddyonrails / active-record-mongo-linked-associations.rb
Last active August 29, 2015 14:00
Mongoid and Active record linked associations
#Extended this gist https://gist.github.com/knapo/8897592
class ActiveRecord::Base
def self.has_many_documents(association_name)
class_eval %<
def #{association_name}
#{association_name.to_s.singularize.classify}.where(#{name.underscore}_id: id)
end
>
end
@reddyonrails
reddyonrails / gist:11361991
Created April 28, 2014 04:44 — forked from dLobatog/gist:5853751
Ruby 2.0 curry function example
is_weekday = lambda {|day_of_week, time| time.wday == day_of_week}.curry
sunday = is_weekday[0]
monday = is_weekday[1]
tuesday = is_weekday[2]
wednesday = is_weekday[3]
thursday = is_weekday[4]
friday = is_weekday[5]
saturday = is_weekday[6]
@reddyonrails
reddyonrails / translator.rb
Created August 31, 2012 22:17 — forked from vraravam/translator.rb
Use Google translate to translate a yml file from one language to generate a new one for a different language
#!/usr/bin/env ruby
if ARGV.size != 2
puts "Usage: #{$0} <from_language> <to_language>"
exit -1
end
require 'rubygems'
require 'ya2yaml' # this gem is needed for this to work!
require 'yaml'
@reddyonrails
reddyonrails / gist:5421632
Created April 19, 2013 16:54
Class Attribute Mixin to list out attributes and its values as hash when included in Class
module ClassAttributeMixin
def self.included(base)
class << base
def attr_accessor(*splash)
@attributes ||= []
@attributes.concat splash
super
end
# First the end result of what we want:
class Foo
before_hook :whoa
before_hook :amazing
def test
puts "This is kinda cool!"
end
OK, Let's begin. Hello, Everybody.
My name is Narihiro Nakamura.
Today, I'm talking about "Parallel worlds of CRuby's GC".
I'm very happy now, because I'm meeting attendee in rubyconf.
And, one of my dreams is to talk in rubyconf.
So, I'm very happy and exciting.
Today is my first presentation in English.
My English is not good.
# DOCKER-VERSION 0.4.8
# am facing issue
# https://github.com/dotcloud/docker/issues/1123
FROM ubuntu:12.04
MAINTAINER Deepak Kannan "deepak@codemancers.com"
RUN apt-get -y install python-software-properties
@reddyonrails
reddyonrails / postgres_queries_and_commands.sql
Created April 8, 2016 17:40 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(query_start, clock_timestamp()), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(query_start, clock_timestamp()), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
for i in `seq 10` ; do rspec spec ; [[ ! $? = 0 ]] && break ; done