Skip to content

Instantly share code, notes, and snippets.

View sent-hil's full-sized avatar

Senthil Arivudainambi sent-hil

View GitHub Profile
module Dsl
class Resource
attr_accessor :name
def initialize(name)
@name = name
end
def get
puts name
@sent-hil
sent-hil / 2013_books_papers_blogs_screencasts.md
Last active December 10, 2015 11:18
Books, papers, blogs & screencasts I plan to read, watch in 2013 or at least try.

BOOKS IN PROGRESS:

  • Practical Object-Oriented Design in Ruby: An Agile Primer
  • Cracking the coding interview
  • Eloquent javascript

BOOKS:

  • Growing object oriented software guided by tests
  • Refactoring by martin fowler
  • Rails As She Is Spoke
  • The Passionate Programmer
@sent-hil
sent-hil / makers_schedule.txt
Last active December 10, 2015 14:28
Notes of Maker's Schedule, Manager's Schedule by [Paul Graham](http://www.paulgraham.com/makersschedule.html)
Jan 3, 2013 4:21 PM
Manager's schedule:
Traditional appointment book.
Each day cut into one hour intervals.
By default you've to change what you're doing each hour.
Maker's schedule:
Prefer longer units of time, at least half a day.
Can't work/switch every hour, barely enough time to get started.
@sent-hil
sent-hil / ego_depletion.md
Last active December 10, 2015 14:28
Notes of 'Understanding Ego Depletion' by Dan Ariely

On stressful days many of us give in to temptation and choose unhealthy options.

Six steps to avoid breaking unders stress

  1. Acknowledge the tension, don't ignore it - we use self control every time we force ourself to make the good, reasonable decision, and that self control, like other human capacities is limited.

  2. Call it what it is: ego depletion - depletion is the psychological sum of these feelings, of all the decisions you made that led to that moment.

  3. Understand ego-depletion - people under greater cognitive strain were less able to overturn their instintive desires.

@sent-hil
sent-hil / saran.rb
Last active December 10, 2015 14:48
Some cowbody coding I did couple weeks ago, totally forgot the design decisions and need to start over. :(
# approach 1
require 'bundler/setup'
require 'open_auth2'
require 'active_support'
require 'active_support/inflector'
require_relative 'saran/config_accessors'
require_relative 'saran/endpoint'
@sent-hil
sent-hil / sandi.md
Created January 5, 2013 06:42
Notes of 'Go ahead make a mess' by Sandi Metz

Your apps starts great and you love working with it up until beta when it becomes a mess and you hate it.

Your app is made up of things and know things about themselves and about others. The latter is dependencies. When the dependencies change, the object will need to change as well.

OO design makes you write code that your future self will love. Stop worrying and learn to love the mess.

@sent-hil
sent-hil / endpoint.rb
Created January 5, 2013 07:45
Refactoring of Saran's `Endpoint` class based on Sandi Metz's talk/book.
module Saran
# Makes http requests.
class Endpoint
attr_reader :verb, :path, :provider, :endpoint, :access_token
# TODO: remove config dependency,
# can combine path, endpoint, access_token
# depends on if OpenAuth can deal with full_url
# how to deal with provider?
@sent-hil
sent-hil / issue_with_modules.md
Last active December 10, 2015 17:58
Notes of 'My issues with Modules' by Ryan Bates. Source: https://gist.github.com/4172391

When working through unknown code method, ask:

What does a given method do?
What is the current object context that I am in?
What other methods can I call here?
module Purchasable
  def purchase
    result = Braintree::Transaction.sale(amount: total, credit_card: card)
@sent-hil
sent-hil / open_auth2_refactor_lessons.md
Last active December 11, 2015 04:28
A list of lessons learned from refactoring my open_auth2 library to make it a better OOP citizen.

Recently I've been learning a lot about OOP, especially how to structure code to make it easier to change in the future. The following are some of the ways I refactored my open_auth2 library.

Don't optimize prematurely

I did the mistake of assuming what sugars were required, only to realize I never used them. Source.

Inject dependencies

The Token object accesses Config object for information. Before it was hard coded into Token, so they're highly coupled, so now I pass it as an argument to #initialize. Better yet it defaults to OpenAuth2::Config.new so it's only optional. Source.

@sent-hil
sent-hil / gist:4641437
Last active December 11, 2015 18:28
zsh function to show specs to code ratio in a rails folder, anything over 0.75 is good.
prompt_rspec_stats() {
if [[ ((-d app || -d lib) && -d spec) ]]; then
if [[ (-d app) ]]; then
local app=`wc -l app/**/*.rb | grep -oE "[0-9]+" | tail -n 1`
else
local app=`wc -l lib/**/*.rb | grep -oE "[0-9]+" | tail -n 1`
fi
local spec=$((`wc -l spec/**/*.rb | grep -oE "[0-9]+" | tail -n 1`))+0.01
local ratio=`printf "%.2f\n" $((spec/app))`