Skip to content

Instantly share code, notes, and snippets.

Gagan Awhad gaganawhad

Block or report user

Report or block gaganawhad

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
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
gaganawhad / ruby-object-mapper.md
Last active Aug 29, 2015
What is Ruby Object Mapper (ROM) and why should you be excited about it?
View ruby-object-mapper.md
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 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'
ADDED_OR_MODIFIED = /A|AM|^M/.freeze
changed_files = `git status --porcelain`.split(/\n/).
select { |file_name_with_status|
@gaganawhad
gaganawhad / oop-thought-sandi-metz.md
Last active Oct 5, 2015
Something about OOD that I am learning from Sandi Metz's books
View oop-thought-sandi-metz.md

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
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
#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
View hope-test-4
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 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
View passenger-nginx-font-accept-header.md

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 / 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
gaganawhad / i18n conventions.md
Last active Sep 22, 2017
Some conventions / guidelines / best practices that helped me while working on internationalization of a rails app
View i18n conventions.md

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 Aug 27, 2019
Cheatsheet for git, rails, unix etc.
View activerecord-cheatsheet.md

Jsonb AR querying:

  • All records where a particular key is present:

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

    OR

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

You can’t perform that action at this time.