Skip to content

Instantly share code, notes, and snippets.

View gaganawhad's full-sized avatar

Gagan Awhad gaganawhad

  • Desiring God
  • Minneapolis, MN
View GitHub Profile
#### 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
gaganawhad / ruby-object-mapper.md
Last active August 29, 2015 14:27
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?
ActiveRecord

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
gaganawhad / rubocop_pre_commit_hook
Last active August 29, 2015 14:26 — 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.
#!/usr/bin/env ruby
require 'english'
require 'rubocop'
require 'byebug'
ADDED_OR_MODIFIED = /A|AM|^M/.freeze
changed_files = `git status --porcelain`.split(/\n/).
select { |file_name_with_status|
@gaganawhad
gaganawhad / insert-rack-auth-digest-md5-middleware.rb
Last active August 29, 2015 14:06
Setting up Rack::Auth::Digest::MD5 middleware in Rails
#References:
# https://github.com/zufrieden/stopwatch/blob/master/config/environments/staging.rb
# http://rubydoc.info/github/rack/rack/Rack/Auth/Digest/MD5
# http://www.sitepoint.com/understanding-http-digest-access-authentication/
# http://levick.tumblr.com/post/65244327897/encrypted-http-basic-auth-in-rails-digest-auth
#"Staging" is the 'realm',
# SecureRandom.base64 is the opaque
# "foo" is the username
Name:
Date:
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
gaganawhad / passenger-nginx-font-accept-header.md
Last active January 22, 2016 04:16 — 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
gaganawhad / i18n conventions.md
Last active July 24, 2023 19:11
Moved to obsidian. Some conventions / guidelines / best practices that helped me while working on internationalization of a rails app.

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
gaganawhad / activerecord-cheatsheet.md
Last active September 9, 2022 19:05
This cheatsheet has been moved to Obisidian for now. Don't make edits here!!!!! Cheatsheet for git, rails, unix etc.

Jsonb AR querying:

  • All records where a particular key is present:

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

    OR

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

@gaganawhad
gaganawhad / scripture_meta.rb
Created December 1, 2012 21:29
Meta information about books of the bible / scripture
[{"id"=>1,
"abbrev"=>"GEN",
"name"=>"Genesis",
"chapters"=>
[{"id"=>1, "verse_count"=>"31"},
{"id"=>2, "verse_count"=>"25"},
{"id"=>3, "verse_count"=>"24"},
{"id"=>4, "verse_count"=>"26"},
{"id"=>5, "verse_count"=>"32"},
{"id"=>6, "verse_count"=>"22"},
def do_this
new_array = []
[{"id" => 1,"abbrev" => "GEN","name" => "Genesis","chapters" => 50},{"id" => 2,"abbrev" => "EXO","name" => "Exodus","chapters" => 40},{"id" => 3,"abbrev" => "LEV","name" => "Leviticus","chapters" => 27},{"id" => 4,"abbrev" => "NUM","name" => "Numbers","chapters" => 36},{"id" => 5,"abbrev" => "DEU","name" => "Deuteronomy","chapters" => 34},{"id" => 6,"abbrev" => "JOS","name" => "Joshua","chapters" => 24},{"id" => 7,"abbrev" => "JDG","name" => "Judges","chapters" => 21},{"id" => 8,"abbrev" => "RUT","name" => "Ruth","chapters" => 4},{"id" => 9,"abbrev" => "1SA","name" => "1 Samuel","chapters" => 31},{"id" => 10,"abbrev" => "2SA","name" => "2 Samuel","chapters" => 24},{"id" => 11,"abbrev" => "1KG","name" => "1 Kings","chapters" => 22},{"id" => 12,"abbrev" => "2KG","name" => "2 Kings","chapters" => 25},{"id" => 13,"abbrev" => "1KR","name" => "1 Chronicles","chapters" => 29},{"id" => 14,"abbrev" => "2KR","name" => "2 Chronicles","chapters" => 36},{"id" => 15,"abbrev" => "EZR","name" =