Skip to content

Instantly share code, notes, and snippets.


Gagan Awhad gaganawhad

  • Desiring God
  • Minneapolis, MN
View GitHub Profile
View gist:2b9b5f5820bb6323ede25e0637006119
#### PRY
- ls (list methods) in self
- ls —grep finds specific names
- cd \<object\> cds into the object... ie that is the new self.
- ? (show-doc) Class#method / object.method
- $ (show-method) Class#method / object.method
- next (next line without stepping through function calls)
- step (next line respecting function call)
- play -l 6 (play line number 6... same as copyig and pasting that line)
- edit (opens up the editor to edit the file) / edit -m (edit current method)
gaganawhad /
Last active Aug 29, 2015
What is Ruby Object Mapper (ROM) and why should you be excited about it?
What is Ruby Object Mapper (ROM) and why should you be excited about it?

The Active Record pattern is described as

An object that wraps a row in a database table or view, encapsulates the database access, and adds domain logic on that data.

It is tightly coupled to the database schema. In other words, decisions that go into designing entities (objects/classes that hold application independent business logic) of your software project affect the database and vice versa.

Ideally, the database is a layer of abstraction lower than your application. What that means is that the decisions of your peristence layer should not affect design decisions of your business logic and vice versa. As an example, you should be able to think through the design decisions of a relational or a non relational database looking at peristence only and not having to wonder how that would affect the rest of your application. This is definitely not

gaganawhad / rubocop_pre_commit_hook
Last active Aug 29, 2015 — forked from mpeteuil/rubocop_pre_commit_hook
Ruby style guide git pre-commit hook using Rubocop as the style guide checker. Only runs on staged ruby files that have been added and/or modified.
View rubocop_pre_commit_hook
#!/usr/bin/env ruby
require 'english'
require 'rubocop'
require 'byebug'
changed_files = `git status --porcelain`.split(/\n/).
select { |file_name_with_status|
gaganawhad /
Last active Oct 5, 2015
Something about OOD that I am learning from Sandi Metz's books

I am learning something interesting about Object Oriented Design, thanks to Sandi Metz. I reckon it is interesting because it is counterintuitive.

Possibly because of how it is often described and taught, Object Oriented Design, to a novice seems primarily about creating objects and secondarily about about ascribing behavior/methods to them. A higher importance is given on identifying and creating the right objects at the onset. While that is not completely wrong, I am learning that that's backwards. Behavior/methods are primary in OOP, and classes, an appropriate way to house them. As behavior continues to grow, you start creating appropirate Classes. Where (What class or module or project or library) some behavior best fits in, is a design question, the answer to which changes as the software grows.

gaganawhad / insert-rack-auth-digest-md5-middleware.rb
Last active Aug 29, 2015
Setting up Rack::Auth::Digest::MD5 middleware in Rails
View insert-rack-auth-digest-md5-middleware.rb
#"Staging" is the 'realm',
# SecureRandom.base64 is the opaque
# "foo" is the username
View hope-test-4
No using computers or google:
For the following 5 questions, chose the option that answers the question.
1. If a variable is named ‘$var’ what type is it ?
gaganawhad /
Last active Jan 22, 2016 — forked from atiw003/nginx-font-serving
Setting Accept-Control-Allow--Origin header on ( font ) assets in nginx. Helpful when using passenger on heroku

Currently passenger 4.0.39 and above come with a default nginx configuration file with a location @static_assets block. Paste the following inside it.

  if ($request_filename ~* ^.*?/([^/]*?)$) {
      set $filename $1; 

  if ($filename ~* ^.*?\.(eot)|(ttf)|(svg)|(woff)$) {
    add_header Access-Control-Allow-Origin *;
gaganawhad / ruby 2.0.0 crash report
Created Jun 17, 2013
I get the following ruby crash report frequently when running rspec. Anyone found any solutions?
View ruby 2.0.0 crash report
Users/gaganawhad/.rvm/gems/ruby-2.0.0-p195/bin/ruby_noexec_wrapper: [BUG] Bus Error
ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.4.0]
-- Crash Report log information --------------------------------------------
See Crash Report log file under the one of following:
* ~/Library/Logs/CrashReporter
* /Library/Logs/CrashReporter
* ~/Library/Logs/DiagnosticReports
* /Library/Logs/DiagnosticReports
the more detail of.
gaganawhad / i18n
Last active Sep 22, 2017
Some conventions / guidelines / best practices that helped me while working on internationalization of a rails app
View i18n

Internationalization of a Rails App : conventions / guidelines / best practices

I have worked, and am currently working on internationalization of a Rails app. The apps require translating the ActiveRecord models. I have done some googling, but haven't really found any best practices / conventions / guidelines on how to think through this and what guidelines to follow.

I decided to create this document, to give myself a start and have it possibly help others. I am not an expert at any of this, and there may be things I am thinking incorrectly, but having it documented makes it easier to see the flaws and improve upon. If you have some ideas on additions, or think that somethings should change, get in touch.

Note: I use Globalize for model translations

  • I18n.locale controls the app wide locale. It refers to the particular localization version of the app. It defines how the app is localized to the user. It's scope is somewhat larger than the language/tran
gaganawhad /
Last active Sep 2, 2021
Cheatsheet for git, rails, unix etc.

Jsonb AR querying:

  • All records where a particular key is present:

    Groupings::Collection.where("document ? 'name'")


    Groupings::Collection.where("document ? :key", {key: 'name'}).