Skip to content

Instantly share code, notes, and snippets.

Methods can be no longer than five lines of code.

I feel like this one is always tricky for me, it has forced me to keep thinking about how to refactor more, so my code has definitely improved since when I first started at Turing, but it's still really hard for me.

Controllers can instantiate only one object.

I almost made this one my first choice, because for my personal project I had a multi-model form, and how the heck would I have not passed all those objects to the view? Then I saw her solution to that and it made so much more sense! I could have made a PORO to initialize all the objects for my multi-model form and then initialize that in the controller and send it off to the view.

Leap

my code

  • (code) This submission did not use the modulus operator, but instead checked if the result of dividing by a number was an integer.
  • (code) I liked this one because he created a method for checking if the year was divisible by a given number, it cleans the code up a lot.
  • (code) This solution doesn't take advantage of the fact that the bunch of logic will already return a boolean, no need to explicitly return true or false.
  • (code) Extremely similar to my solution, except that they are using == instead of the ===, which makes the code more readable, but might not be a good idea. I ran across this [resource](https://github.com/getify/You-Dont-Know-JS/blob
Ideal User
  • Person with asthma
  • Parent
  • Senior
  • Activist
  • Healthcare worker
  • Athlete
Habits

Air Alert

Pitch

This application is extremely important to people who are sensitive to air pollution or care about the enviroment and want to know ways to reduce their impact on air pollution.

Problem

There is currently no immediate notification system for air quality alerts.

Rails.application.config.middleware.use OmniAuth::Builder do
provider :instagram, ENV['INSTAGRAM_ID'], ENV['INSTAGRAM_SECRET'],
{:scope => "basic likes comments follower_list public_content relationships"}
end
🍇 ruby better_benchmarking/shuffle.rb
..............................
Set 1 mean: 1.586 s
Set 1 std dev: 0.092
Set 2 mean: 1.831 s
Set 2 std dev: 0.117
p.value: 6.797632810792956e-11
W: 57.0
The difference (+15.4%) IS statistically significant.
require 'better-benchmark'
@data = (1..100).to_a
result = Benchmark.compare_realtime(
:iterations => 30,
:inner_iterations => 500_000,
:warmup_iterations => 1,
:verbose => true
) { |iteration|
<h3>Victories: </h3>
<ul>
<% @dojo.winning_fights.each do |fight| %>
<li> <%= fight.winning_combatant.name %> defeated <%= fight.losing_combatant.name %> of <%= fight.losing_dojo.dojo_name %> </li>
<% end %>
</ul>
<h3>Defeats: </h3>
class Combatant < ActiveRecord::Base
belongs_to :dojo
has_many :winning_fights, :class_name => "Fight", :foreign_key => "winning_combatant_id"
has_many :losing_fights, :class_name => "Fight", :foreign_key => "losing_combatant_id"
end
class Dojo < ActiveRecord::Base
has_many :combatants
has_many :winning_fights, :class_name => "Fight", :foreign_key => "winning_dojo_id"
has_many :losing_fights, :class_name => "Fight", :foreign_key => "losing_dojo_id"

Descriptions of git commands:

  • git stash: Records the current state of the working directory and the index, but want to go back to a clean working directory. The command saves your local modifications away and reverts the working directory to match the HEAD commit.
  • git stash apply: Applies the stashed changes to the current branch you are working on. Does not remove the state from the stash list.
  • git shortlog: Summarizes git log output.
  • git commit --amend: convenient way to fix up the most recent commit. It lets you combine staged changes with the previous commit instead of committing it as an entirely new snapshot. It can also be used to simply edit the previous commit message without changing its snapshot.
  • git reset --hard: Resets the index and working tree (throws away uncommited changes). Any changes to tracked files in the working tree since are discarded.
  • git reset --soft: Does not touch the index file or the working tree at all (but resets the head to <