Skip to content

Instantly share code, notes, and snippets.

View ToniRib's full-sized avatar

Toni Rib ToniRib

View GitHub Profile
#
# Written by Mariusz Smykula <mariuszs at gmail.com>
#
# This is fish port of Informative git prompt for bash (https://github.com/magicmonty/bash-git-prompt)
#
set -g fish_color_git_clean 9ecc24
set -g fish_color_git_branch 9ecc24
set -g fish_color_git_remote 9ecc24

JavaScript Functions

I can explain the difference between function declarations and function expressions.

  • Function declarations do not declare var with a name before the function prior to the function keyword like function expressions do. With the expression, you cannot make a call to a function that is declared later in the file or it will throw an error because only the var part is hoisted to the top of the file, but the value of that (which is going to be a function) is still undefined. All function declarations (named functions) will be hoisted to the top of the file, so you can use them even before you actually defined them in the file.

I can explain what the value of this is in a normal function.

  • global window

I can explain what the value of this is when called from the context of an object.

  • the object

Part 1

Question 1:

What does MVC stand for and what does each part of MVC do?

  • MVC stands for "Model View Controller."
    • Model: Interacts with the database and knows information about the data itself. Basically it handles and any data and business logic. In true MVC, the model only interacts with the controller.
    • View: Displays information about the model to the user, but does not interact with the model directly. Instead, it interacts with the controller which provides it the necessary data for display.
  • Controller: Interacts with both the model and the view. The controller recieves the requests from the user and determines which action to call to retrieve the appropriate data. Once it gets the data from the model, it sends it to the view to be displayed to the user.
@ToniRib
ToniRib / package-management.markdown
Last active March 24, 2016 15:07 — forked from rrgayhart/package-management.markdown
The Dangers of Using Code You Don't Control
@ToniRib
ToniRib / es6.markdown
Last active March 23, 2016 15:54 — forked from rrgayhart/es6.markdown
es6 - 1510

Throughout the module (and your journey to Google enlightenment while working on IdeaBox2.0) you may notice a few different ways that JavaScript code is being written.

That might have something to do with something called ES6 and ES5

Fork this gist and answer the following questions:

  • What is ES6?
    • ES6 is "ECMAScript6" which is the next iteration of ECMAScript (aka what we commonly refer to as JavaScript). It has a bunch of cool features like string interpolation (finally!!!) and browsers are currently working on support for it. Apparently the official name is now also "ECMAScript2015." ES5 came out originally in 2009.
  • What is Transpilation and how does it relate to ES6?
  • Transpilation is the process of converting ES6 code to ES5 code. This can be done with a tool like Babel. This allows developers to write ES6 that can still run on browsers that might not support all of the functionality yet. Thus, you can take advantage of the updates from ES6 without having to worry about whether or

Array Prototype Methods

I understand that functions in JavaScript can take any number of arguments.

  • Yup. It's weird, but super flexible. I like the idea of being able to omit arguments that I don't need.

I can describe the similarity between blocks in Ruby and anonymous functions in JavaScript.

  • Blocks in ruby and anonymous functions in JS both can arguments of some type (often a collection) and will run some code related to those arguments. In JS we can pass arguments into an anonmyous function and do something with them inside of that to return some value, which is very similar to ruby. In the same way that we can pass a block to .each in ruby, we can pass an anonymous function to .forEach in JS.

Where are the methods available to all arrays (e.g. forEach, map, etc.) defined?

@ToniRib
ToniRib / javascript_reflections.md
Last active March 18, 2016 15:56
Speaking JavaScript Reflections
  • By far the most interesting thing I read was this: "JavaScript did not have exception handling until ECMAScript 3. That explains why the language so often fails silently and automatically converts the values of arguments and operands: it initially couldn’t throw exceptions." WHAT?? It literally couldn't throw exceptions until ES3? Why on earth would it be designed that way?
  • A lot of JavaScript seems like workarounds built on top of workarounds. I don't like that.
  • The concept of 'bind' seems flexible/useful but also confusing as it's a totally new concept to 'bind' one function to another. I don't yet see the benefit over just defining another function.
  • I skimmed the arguments section. It didn't seem that useful or interesting.
  • The reading made the concept of 'hoisting' a lot clearer for me.
  • I skimmed 'Use Cases for Window' because: "This section describes use cases for accessing global variables via window. But the general rule is: avoid doing that as much as you can."
  • The environments section
@ToniRib
ToniRib / sandi_metz_reflections.md
Created March 18, 2016 14:41
Sandi Metz's Rules for Developers Reflections

Which of Sandi's rules do you feel like might be the hardest to follow—why?

Rules

I feel like the 5 lines per method is the hardest to follow. In general, I have been trying to follow this rule since about halfway through mod 1, mostly with success, but sometimes I just can't find a way around it. They are correct in that I usually get stuck when I have an if/else situation in which it's difficult to pair down the internals to one line each. However, I also find it difficult to stay under 100 lines in a class sometimes when I have a class that I have a lot of methods for. I think I just need to spend more time refactoring classes to have a single responsibility to meet this rule.

@ToniRib
ToniRib / javascript_exercisms.md
Last active March 15, 2016 18:18
JavaScript Exercisms

Leap

My Code

Other Solutions

  1. Solution 1 - This person used an if/else statement to return true or false. It's actually unnecessary since the logical expression itself will return true or false. They could remove that and get rid of some lines of code.
  2. Solution 2 - This person did the same thing as solution 1. I also think they could refactor to pull out the logical statement into its own function to clean up the code.
  3. Solution 3 - This person had an interesting approach to the code by creating divisible variables to help the reader understand what is going on in the logical expression. I actually like this a lot as I think it makes it easier to read and cleans up the logical expression. However they could simplify line 8 by r
@ToniRib
ToniRib / toni_rib_lightning_talk_concerns.md
Last active March 8, 2016 20:50
Lighting Talk Mod 3 - ActiveSupport::Concern

ActiveRecord::Concerns - How To Share Scopes/Class Methods Between Modules

Intro

  • What is that 'concerns' folder that lives under models that you always delete? Why does it exist? You're about to find out!
  • Mostly a code-along lightning talk
  • Background: You have a scope that needs to be shared across multiple models and you don't want to repeat your code
  • Example: Rails Engine -> successful_transactions scope for Merchant and Customer

Code Along