method PageHeaderHelper
def page_header(title, subtitle = nil, &contents)
PageHeader.new(self, title, subtitle, &contents)
end
class PageHeader
attr_reader :context, :title, :subtitle
def initialize(context, title, subtitle = nil)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Instructions: | |
| // 1. Visit https://clients.uber.com/#!/dashboard | |
| // 2. Click the "Show all trips" link | |
| // 3. Paste the following into the console | |
| // 4. Gasp in horror as you see how much money you've spent on Uber | |
| _($("td.num:contains($)")).map(function (el) { return $(el).text().substring(1) }).map(Number).reduce(function(memo, num) { return memo + num; }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module FieldsetWithSubtext | |
| def fieldset_with_subtext(main_text, subtext, options = {}, &block) | |
| View.new(self, main_text, subtext, options, &block) | |
| end | |
| class View | |
| attr_reader :context, :main_text, :subtext, :options, :block | |
| def initialize(context, main_text, subtext, options = {}, &block) | |
| @context = context |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Analyzer | |
| class << self | |
| include ActionView::Helpers::NumberHelper | |
| end | |
| CACHE_NAMESPACE = "analyzer" | |
| CACHE_LIFESPAN = 10.minutes | |
| class_attribute :items_to_analyze |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module ChronicAttribute | |
| extend ActiveSupport::Concern | |
| module ClassMethods | |
| def chronic(*attrs) | |
| attrs.each do |attr| | |
| define_method "#{attr}=" do |value| | |
| if value.is_a? String | |
| with_utc do | |
| self[attr] = Chronic.parse(value) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # Starting | |
| # | |
| # Start a new feature branch | |
| git checkout -b my_feature | |
| # Make changes | |
| # Add/Commit |
N.B. Things that are starred with * are local variable
- Ok, first generate a new rails app using this format:
- rails new app_name
rails new amit_test_blog
- Ok, next sketch out your models.
- We're going to have two models for this blog: User and Post
- One users can have many posts and many posts can belong to one users
- Figure out the fields in each model.
- Users will have these: field:type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Automatically instantiates views based on the `role` attribute. | |
| // | |
| // Example: | |
| // AA.Views.Workflow = Backbone.View.extend(); | |
| // AA.Views.Workflow.bindRole("workflow"); | |
| Backbone.View.bindRole = function (role) { | |
| var view = this; | |
| $(function () { | |
| $("@" + role).each(function () { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| RSpec.configure do |config| | |
| config.before(:suite) do | |
| DatabaseCleaner.strategy = :transaction | |
| DatabaseCleaner.clean_with(:truncation) | |
| end | |
| config.before(:each) do | |
| DatabaseCleaner.start | |
| end |