Skip to main content

Posts

Showing posts from November, 2016

what is html

HTML is like a page full of tags that allow the computer to know what is the meaning of the items in the computer. HTML is like a newspaper document. It has sidebars, headlines , body of text , images, have a listing. the main difference between newspaper and online webpage is the ability to link to another webpage. and also play video. For example: <img/> is a self-closing tag because you do not need to put text in between the text, you just need to link it up. <head> </head> tell the computer that this is the head part of the web page. A web page is a online document.

CSS

CSS is a language that defines the styling of a webpage. It can be written inside HTML file inside the <style> element, but usually written in its own file, and link via <link>

Class and objects

Explain classes and objects to a complete beginner classes is like a blue print to create object. object is like a bundle of variables + methods. in Ruby, most things are objects String is an object. It has states. For example, when called length method, it will return the number of characters for that string. It also has methods, for example (+) will append another string to the end of the first string. So if you have a custom object like computer class Computer    attr_accessor :mouse    def turn_on    end end It is capable to turning on. However, this is just the design of the computer object. In order to manufacture the object, you have to raise the following method calls. Computer.new This will create a new computer object, which you can save into a local variables computer1 = Computer.new Now, suppose we create a new object , mouse = Mouse.new, we could pass in mouse into computer for them to interact with each other. class Mouse     def click    

Heredoc

here = <<EOF This is the beginning of heredoc EOF this will save the string "This is the beginning of heredoc" into here. It doesn't seem to matter what word is used to replace "EOF"

||=

The operator  || (OR) will return whatever value that is truthy first Eg: "abc" || "cde" # return "abc" because it is truthy , and it return 'abc' without verifying 'cde'. The operator && (AND) will return whatever value that is 'false' or 'nil' first Eg: nil && false # return nil false && nil # return false 'abc' && 'cde' # return 'cde' because 'abc' is truthy. So the short-hand name ||= 'default' is equal to name = name || 'default' meaning that is name is not false or nil, then it is assigned back to name. eg : if name is already 'John' then name = 'John'. if name is false or nil, then || operator will evaluate the second part of OR operator, and return 'default' because it is truthy.

Sharing my Weakness

It makes sense to know about your weakness and do something about it. Here are my known weaknesses uncovered during my time in Launch School. 1. I don't like to refactor my code   - Your first draft will not be perfect. It works but it may not be efficient/readable/best practices. You final code will almost always be better than your first draft. - It is easier to separate the task between writing code that works and refactor later to make it efficient/readable/best practices. - If you refactor your code often, over time you will discover your bad habits and change it. 2. I don't like to read other people's code - There are more good programming practices in other people than in you (especially for beginners like me). - To be good , you need to know more than one pathways to solve a programming problem (and there are always more than one way). Then you can judge their merit. - Reason for dislikes    1. It is considerably harder to read code than to write one (be

Humility

I have been going through LS weekly challenge lately. The question are pretty tough and I spent many hours solving the problem. I felt ecstatic when the code finally works and pass all test cases. However, I found myself having a strong attachment to my code to the point that it is unhealthy. Let me explain. I am reluctant to study other people's code. When I see other people's code, I am thinking to myself "hey, my code works, and that's all that matters, why should I study their code.". I know this is my ego talking. What's the consequences ? Less learning. I found that my code pattern will follow only a few patterns. Without learning from others and refactoring my code, I can't break my old coding pattern/habits. It takes great humility to learn from other people's code and refactor your own. If you could do that, your learning progress will accelerate. Why? Because LS student are great, there are many

Enumerable #all? #one? #none #any?

For objects that include Enumerable (Hash, Array and Range), there are these methods that are useful All these methods takes a blog. 1. #all? iterate through all the element, will return true if only ALL of the block statement return truthy value. 2. #any? iterate through all the element, will return true if ANY of the block statement return truthy value. 3. #none? iterate through all the element , will return true if NONE of the block statement return truthy value. 4. #one? iterate through all the element , will return true if exactly one of the block statement return truthy value.

Checking surrounding tiles

If you want to check the surrounding tiles in a series of array. Instead of using this: if input[index_r-1]             result += 1 if input[index_r-1][index_e-1] && input[index_r-1][index_e-1] == "*"             result += 1 if input[index_r-1][index_e] == "*"             result += 1 if input[index_r-1][index_e+1] && input[index_r-1][index_e+1] == "*"           end                     result += 1 if input[index_r][index_e-1] && input[index_r][index_e-1] == "*"           result += 1 if input[index_r][index_e+1] && input[index_r][index_e+1] == "*"                     if input[index_r+1]             result += 1 if input[index_r+1][index_e-1] && input[index_r+1][index_e-1] == "*"             result += 1 if input[index_r+1][index_e] == "*"             result += 1 if input[index_r+1][index_e+1] && input[index_r+1][index_e+1] == "*" end Please use
If you want to initialize a Hash with the keys set to array ([]), do this: @grade = Hash.new { |roster, grade| roster[grade]  = [] } @grade[100]   # return []
class Machine      def start       flip_switch(:on)   end   def stop        flip_switch(:off)   end      private      attr_writer :switch   def flip_switch(desired_state)        self.switch = desired_state   end end You need self prepended to a private setter method. Unlike other private method where self is prohibited. This is to distinguish between setting a local variable and the instance method setter.