Skip to content

Instantly share code, notes, and snippets.

Gagan Awhad gaganawhad

View GitHub Profile
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 / 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
@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 / 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

View gist:2140121
$ cat /Users/mark/.rvm/log/ruby-1.9.3-p125/autoreconf.log
[2012-03-20 15:09:09] autoreconf
Can't exec "aclocal": No such file or directory at /usr/local/Cellar/autoconf/2.68/share/autoconf/Autom4te/FileUtils.pm line 326.
autoreconf: failed to run aclocal: No such file or directory
@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.

View gist:4185221
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" =
@gaganawhad
gaganawhad / scripture_meta.rb
Created Dec 1, 2012
Meta information about books of the bible / scripture
View scripture_meta.rb
[{"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"},
View gist:5207384
[1, 1, 1, 1, 2, 2, 3].to_histogram
=> {1 => 3, 2 => 2, 3 => 1}
@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.
You can’t perform that action at this time.