What’s IRB? Not a Baby of IRs!

IRB stands for Interactive Ruby, and it’s a read, evaluate print loop. It can read what we type in, and value as a ruby code. Now the resource can give really quick feedback, and it’s gonna to loop back around and ask more ruby code.

So why we using IRB? Because we went to have some instant feedback, or sometimes we just want to experience to try somethings else. IRB is kind of like a dictionary to Ruby language, fast and easy!

How do I start? Just type in IRB in terminal.

What’s next? We can type in anything we want, and IRB will be give us feedback right away. For example:

If we type in string “My name is Grace.”, then IRB will reply “My name is Grace.”.

If we type in variable greeting = “My name is Grace.”, IRB will reply “My name is Grace.”

Now we assign “My name is Grace.” to variable, IRB will still reply “My name is Grace.” when we type in variable greeting.

Let’s have some fun time! What if I type in greeting.reverse? “.ecarG si eman yM” will be IRB’s answer.

What if I type in Time.new? IRB will show you the current time, such as 2015-02-04 17:55:14 -0800

Let’s take a look of some errors we might run into IRB. If we type too fast “My name is [enter] and now we are in second line, even we finish it on line 2 of Grace.”, IRB will read it as “My name is\nGrace.” What if we forget to assign anything to the variable only type in greeting =? IRB will get lost and ask “?”, and now you can finish it with the object you want to assign to your variable greeting by type in “My name is Grace.”. We are all human, of course all of us will have typo from time to time, such as typo in greeting. Don’t worry, IRB gonna tell  you with a long message such as NameError: undefined local variable or method ‘greting’ for main: Object from (IRB):10 from / Users/grace/.rvm/ruies/ruby-2.32-p0/bin/irb:16:in ”

What if I have enough fun with IRB, but now I just want to jump out? Oh, that’s easy! Just type in exit will do

Graces-MacBook-Pro:studio_game RiverGracefish$ irb
2.1.2 :001 > "My name is Grace."
=> "My name is Grace."
2.1.2 :002 > greeting = "My name is Grace."
=> "My name is Grace."
2.1.2 :003 > greeting
=> "My name is Grace."
2.1.2 :004 > greeting.reverse
=> ".ecarG si eman yM"
2.1.2 :005 > Time.new
=> 2015-02-06 16:01:54 -0700
2.1.2 :006 > "My name is
2.1.2 :007"> Grace."
=> "My name is\nGrace."
2.1.2 :008 > greeting =
2.1.2 :009 > "My name is Grace."
=> "My name is Grace."
2.1.2 :010 > greting
NameError: undefined local variable or method `greting' for main:Object
from (irb):10
from /Users/RiverGracefish/.rvm/rubies/ruby-2.1.2/bin/irb:11:in `<main>'
2.1.2 :011 > exit
Graces-MacBook-Pro:studio_game RiverGracefish$
view raw IRB.rb hosted with ❤ by GitHub

Hope you enjoy this  😉

Object in Ruby

Object in Ruby could be any value, even strings, numbers and a class itself. All objects in Ruby,  they have their own state and behavior. An object on the right side of “=” , and usually assign to a variable on the left side of “=”.

my_name = grace

In this case,  “grace” is an object, and it’s also a string.

An object can be number as well, such as

my_age = 28

28 in here is an object assign to the variable “my_age”.

However, we can have ONE string object to Two variable.

your_name = grace

“grace” over here is just ONE string object, but it assign to both variable “my_name” and “your_name” at the same time.

Object can also do things in Ruby. We tell an object to do something by calling a methods on that object. Sometime we refers to sending the methods to the object. Such as

my_name.capitalize

and it would show us the result of “Grace”, or

your_name.length

will show the result of “5”. Another example,

my_age * 2

the result will come out as “56”.

Since we tell the object “grace” to capitalize, both variable “my_name” and “your_name” get change to “Grace”, the same object they share.

You can change your name to another object, and not tie to me anymore. Re-assign another object to “your_name”

your_name = Laura

so “Laura” will be the new object for variable “your_name” currently, but variable “my_name” still has the same object “Grace”.

An object can be class itself, basically an object is created from a class, which a class provides the blueprints for objects. What an object of the class will consist of  and what operations can be performed on such an object, define as a class. The class object has to be capitalize, and it always come after the keyword class and followed by an end at the end. For example,

class Panda

end

Shortcuts that help us to be a SMART LAZY PROGRAMMER ;)

As a student in Jason Noble’s 3 months course at DaVinci, I learn an really important skill: Speed up in anyway you could to follow up. And here’s a big part of how to speed up: use your shortcuts! PS, These following shortcuts are only for Ruby on Rails, Mac Developers.

First of all, how to do a screen shotCommand + Shift + 4; ‘click and drag’ the area you need, it would be on your desktop once you let go. Now you can use in whatever way you need 😉  PS, this work on any Mac Book.

Search on computer: Command + <Space> opens Spotlight, working on any Mac.

Switch Windows: Command + Tap, any Mac can do it. 

When you need to bring up HTML from your Browser: Chrome @ Command + Option + U; FireFox @ Command + U

These following are shortcuts for Terminal/ I Term:

cd ==> go to : ~ home; . current directory; .. one directory up; / root

mv = move      eg. >>usage > mv <path>/<file name> <path>/<file name>

rm = remove      eg. >>rm -rf

 OR eg.>>rm <file name>

 

cp = copy      eg.>>cp ~/<directory/file> ~/<directory/file>

ls = list   ==> list all the files in the current directory you are in.

open ==> open file 

ps, you can see which directory you are in currently on the left side of >>

touch <file>.rb  ==> create new ruby file name <file>

mine .  ==> open ruby mine in current directory

mine <file>.rb ==> open ruby mine <file>

chmod 755 <file>  ==> make files executable 

git status  ==> shows the current status of your local git repo

git add ==> stages files locally

git commit -m ‘<message>’  ==> commit files with message you want to say in <message>, commits all the currently staged files.; OR gitx; Command A on the right will select all files, you can then drag
them to the left, thus “staging” them for commit. The commit message goes in the middle box. push ‘commit’ bottom; close gitx

git push ==> push files to your GitHub account.

echo ==> command to output which version or what types of gem-sets to the terminal.      

eg.>>echo ‘2.1.4’ > .ruby-version  OR  eg.>>echo  > .ruby-gemset

eg.>>echo ‘Hello’
Prints hello to the terminal
We use > to redirect that output to a file

bundle ==> is part of the bundler gem.  Running the bundle command will
look at the gems you requested in your Gemfile and install them.

rails new <name_of_rails_app>  -B -T  ==> create a new rails app;   -B skips the bundling step;

    -T skips the unit_test generation step

rails s = rails servers ==> run rails server. By default it will run
the server on port 3000, which you can access in a browser by going to
http://localhost:3000/

rrails g scaffold <name_of_scaffold> field1:<type> field2:<type> #note: keep going with all your fieldss:<types>    ==>  generate a scaffold for your rails app

If you have any typo on your scaffold, do rails d scaffold <name_of_scaffold> field1:<type> field2:<type> …    ==>  delete your scaffold, and now re-do generate scaffold

rake db:migrate  ==>  applies any migrations (stored in db/migrate/*) that
have not already been applied. You usually want to run this after
generating some rails code (migration, scaffold, model, etc)

rake routes  ==> provides a list of URLs that are available in your Rails App.

Control + A    ==> Go to beginning of the line, can be
used in IRB, rails console and the terminal.

Control + E    ==> Go to end of the line, can be
used in IRB, rails console and the terminal.

Control + C    ==> Cancel , can be
used in IRB, rails console and the terminal.

Control-u   ==> Deletes the current line in the terminal

Command + N  ==> opens a new iTerm/Terminal window

Command + T   ==>opens a new tab in iTerm/Terminal

guard init    ==>Initialize rubocop,   If you have guard-rubocop installed, it
will add Rubocop settings to the Guardfile.

guard    ==> Runs Guard, which waits for files to change.  Once files change,
it will run one or more guards (Rubocop, RSpec, etc).

Command + K    ==> Clears the terminal screen (clears the scroll buffer)

q = quit    ==> exits Guard…

exit    ==> Close/exit current Terminal

 

These following are shortcuts for Ruby Mind:

PS, if your shortcut in Ruby mine not working, do this to fix it: Go to the left top click on RubyMine/ Preference/ Key Map/ selective Pivotal/ hit Apply & OK 

If you want to fix the colors on your Ruby Mine:  Go to the left top click on RubyMine/ Preference/ Editor/ Colors & Fonts/ pick the colors and fonts you like on the right side.

Run the specific file you currently have open inside of Ruby Mine: Command + Shift + F8

Create new files in the directory you have highlighted: Command + N

Gives you an easy way to open files by filename: Command + Shift + N

 Duplicates the line that the cursor is on: Command + D

Undo: Command + Z

Show/hide the list of directories in your project: Command + 1

Type/Edit multiple lines at the same time: Option + ‘click’ on the lines where we want to add/edit at the same time

#{}  ==> Control + L

<%=  %>    ==> Shift + Command + .

 

You welcome to add any more that I don’t know yet 😉  Hope this help and have fun with them!

MVC is not Music Video Chose, but Model-View-Controller

MVC is not Music Video Chose, but Model-View-Controller, a software architectural pattern for user interfaces.

As we learn from Jason Noble’s class, Model who are the independent of user interfaces captures the behavior, and do most of the business action; View shown people the final resource output representation of information; and Controller, the most busy guy, are basically doing everything like a leader, which accepts input and converts it to commands for the model or view.

How do it work? First, USER using BROWSER as a window to ask ROUTER to route to CONTROLLER, CONTROLLER tells the MODEL what to do, and MODEL did what CONTROLLER told and let CONTROLLER hang the info to VIEW. VIEW said “Here’s your HTML” and we hang it all the way back to USER. Here’s a joke I find funny and want to share “So a Model, a View, and a Controller walk into a bar and sit down to order some drinks from the bartender. View has a bit too much to drink, so the bartender asks View for his keys. Controller reaches into Model’s pants and pulls out a set of keys which he then hands over to the bartender. Model yells out: “Somebody has just reached into my pants!” View hears Model yelling and turns to the bartender and says” “You have my keys now.” by Derek

Thank you for reading, and I hope you enjoy this MVC post 🙂  Here’s a Music Video Chose I would love to share with you http://www.youtube.com/watch?v=EdPa_MsRf-k&list=RDBGyFWhnFREQ&index=4 😉  Enjoy it!

~Be a warriors in Codewars~

My prof. Jason introduce Codewars in class today. I think it is really good way to practice our code so I’m going to share it on my blog 😉 Here’s the link http://www.codewars.com/r/79kSEg

And choose the languages you wish to train on, follow with the practice. After that you can link it to your GitHub account and pick your programming languages again on your home page.

Ready for some practice? Go to Kata and pick your level that you feel comfortable to work on. 8kyu is the most easy level, and 1kyu is the most hard level. Click the you want to work on, and click on the blue “Train” button. Fix the code in the code box on the top right, then hit “run tests” button on the bottom right to see if your code work or not. Finally, hit the “summit” button next to it when you get your “Excellent!” output on the left box. And you can keep practicing until you get enough 😉

When you go check on the top right area, you can go to your profile by click on “view profile”. You can check on the “Kata” you have been complete. You can click on the programming language button on the right side of the kata title you want to check, and click on “Past Solutions” on top right inside of the left box to check your answer.

I hope you enjoy and have fun! 😉

How to use git and the github repository

I find it useful 😉 borrow it to share, thanks~David

davidmowrer's avatardavidmowrer

What is github?

The technical description is a distributed revision control system.  It consists of multiple repositories.  What is a repository?  This is the area where you store your changes to code.  You will have different repositories for the different projects/ assignments you work on.  In the class you will have a homework repository, and in_class repository and others.  I think of this as separate databases for each area you are working on.  To use github you need to setup a github account.

What isgit?

Git is used to manage your code and code changes.  Git is used on your local pc.  The two main functions are to move/copy your code changes to github and to move/copy your code or others code from github to your local pc.  You use the command git push to move/copy your code from your pc to github.com to your account.  You use the…

View original post 864 more words

KISS principle

Life is rough for me lately, and I have been off class and off work for two weeks. Now I’m trying to catch up with life while I’m still trying to clear up my head. I ask myself, how can I keep going? Then I remember a kiss, and the kiss remind me of KISS principle ~ “Keep it simple, stupid!” by Kelly Johnson or later on people change it into “keep it short and simple” and “keep it simple and straightforward”.

Now how do I KISS since I have hard time to remember anything? I went out and bought myself a notebook, just write down whatever comes to my mind: to do list, billings, the wishes that my love one who just pass away recently etc.

I understand that I have a rough time in my life now, but I believe some other people out there in the world are worst than me and still fighting for a better life. I’m so lucky already, I have so many friends and family that care about me. With their full schedule and own issue in their life, they still find times to support me in many different ways. I’m thankful for all of them. One of my best friend share some of his experience and life problems he is having, but he told me that “No matter what, we need to keep smile and keep going forward!” KISS! I need to get back up and be strong, even tear in my eyes, even pain full fill into my life, I am still lucky that I am surrounded with so many people who love me.

Of cause, work! KISS, I need the income to cover everything specially this is happening out of plans. It’s hard, I’m not going to lie! I keep my eyes on the notice that I’ve been not looking for a while to make sure I don’t make any mistake at work. I understand how important for my clients to get correct information, and I’m so glad that my boss willing to trust me return to work with my unstable emotional stage. Keep it simple, stupid! I don’t want to disappoint any people who have trust in me.

Study. I’m so lucky to have a really strong school president Nancy, a women who know how to upbringing everyone around her, a women who have lots of idea to solve problems, a women who will support me in many ways to help me out. Of cause, my favor professor in the world, Jason Noble, a super patience man who will walk you step by step like a father. Oh, in his class, one rule: ask if you have any question. KISS, don’t be worry and just try your best. Most of systems work best if they are kept simple rather than made complicated, and I believe this KISS principle can be use well in class as well. For example, having trouble in terminal to push your files? Oh, KISS, go use gitx 😉 Another example, having hard time to understand but cannot find your answer on Google? KISS, Ask prof. Jason 😛

KISS principle help me out in a big way, and I think share it with everyone might help to. Hope you will find it useful in your life as well 😉

Git your life up! Let’s do it ;)

  • What is Git(Github)?

Git is a very powerful tool, a tool might help us to look good in an interview. Now a day, Git is a  conventional resume, and there are staple among of open-source development community require an active Github account to to qualify for a job.

  • Why we use Github?

As I learn from my professor Jason Noble’s class:

–Git is a distributed revision control system. It make scenes that it become a very powerful tool today for development community.

–It keeps track of changes made to one or more files over time. Think about this, after working in the fields for 5 and 10 years later, where can we find the basic error we fixed when we were a beginner developer? How awesome is that we can find the question we ask in our own blogs 8 years later? PS, Jason: How fun for you to have students in class search your blogs for in class questions? 😉

–Shows log messages of what changed and why. I believe this can help us to easily to remember our mistake and do not created the same type of bug again in the future, safe us a lot of time.

–Allows developers to share their changes easily. And we can also see even different style of coding (variable, objects, methods etc.) can come out of the same resource. You can study from other developers’ codes and learning new ways to codes everyday.

Git is a master station, it has three areas: Working directory, staging area, and git directory/repository. We use working directory to stage files into staging area, then from staging area to commit files upload to git directory/repository; last but not least, checkout the project from working directory. This is how we get the following 3 step to use Git workflow of modify files, commit files, and stage files. Magic 3 step to push your files into Github:

>git add <files>

>git commit -m “message you want to say”

>git push

  • Oh, wait! What if you didn’t set up Git yet? Here’s some steps I remember:

>git config –list

>git config –global user.name “Your Name”

>git config –global user.email “Your@email.address”

  • How do I getting some help with Git?

Most commands have help available

>git help commit

>git help branch

>git help tag

If you still don’t find what you need, we always have fallback of Google 😉

  • How to working with Remote Repos?

Public Repo Located on Server, can git pull into Private Repo Located on your local machine; also, from Pravate Repo Located on your local machine, can git push upload to Public Repo Located on Server.

  • I’m really forgetful, how do I know what status am I with the files I’m working on?

Easy, here we go

>git status

  • How do I find friends/developers I like in Github?

Go to the top search bar, just type in the name you want to search (eg. JasonNoble–my professor’s name, or RiverGracefish–my Github name). It will bring you to a new page, there’s a box with Users link on the left hang side, click the Users link. It will show all the match resource, you can follow them and go to their git when you having trouble of your coding (in our case, study of others homework’s difference).

  • Here’s my suggestion if you are my classmate, you should go to HipChat and find all your classmate, follow them and compare your homework. (Andy and Dan’s Git even have Guardfile and Greamfile info)
  • PS, I change my name into RiverGracefish.

Hope this will help you a little 😉

Study Tips from my own experience :)

As a new programmer who don’t have any programming background, I have a little hard time to follow-up sometime. However, as I go to class, reading books, doing homework, watching video…working on so many things in study. I start finding some study tips for myself.

>Why I write this blog to share?

I find it helpful for myself to keep moving on, and I hope it can help some other people who have the same problems I run into.

>What is programming?

As Chris Pine said in the book <<Learn to Program>>, programming is telling you computer how to do something.

>How to start programming when we are a beginner?

Chris Pine said “Large task must be broken up into smaller tasks, which must be broken up into still smaller tasks, down until you get to the most basic tasks that you don’t have to describe–the task your computer already knows how to do.” Such as we feel sick, we go see the doctor, and the doctor need to find out what symptoms we have to be able to find out what type of sickness, which type of medicine we should take, and how should we treat them to get better. You can not just go to the doctor say “I’m sick, give me some medicine to feel better.” with no explanation what is going on of your body. Just as programming, you need to tell the computer step by step what do you want it to do like holding a babe’s hand teach him/her how to walk slowly.

>So, a program is like a child/babe?

Yes, “A program is not built; it is grown” from Chris Pine. For me, learn to programming is like raising a child/babe. We need to be patient, spading time to understand their language, step by step teaching what you have, and see what is coming out from them.

>What is the best way to study programming?

Everybody have their different way, you need to find out which is the best way for you to study. Here’s my way to study: to understand is better than just follow along and doing the same thing everybody’s doing without understand what is going on. To tell your computer how to do something, you must use a programming language (Chris Pine). However, if you don’t even understand this language, how can your computer understand what output do you want?

>What if I don’t understand what to do, but I’m trying my best to following in class?

Use your resources, there are may resources around you!

>What resources do we have?

1. Really popular one– Google! Google know everything, and it’s on-line for everybody. (PS, here’s a funny video for you “If Google was a Guy: http://www.youtube.com/watch?v=YuOBzWF0Aws)

2. If you are in school, don’t ever forget your professor! They are here to help us, and most of them are happy when we go to them. We can always email them, asking questions in class, even make appointment with them to help us out one-on-one.

3. A really regular chat for programming field, HipChat.

4. A hot spot for gits and blogs, GitHup.

5. A professional web source, StackOverflow.

6. Of cause it would be super useful if you keep posting solution on your own blog, such as my professor Jason Noble can always find it on his own blog. If you don’t have enough on your own blog, I’ll suggest you to go find it from my professor Jason Noble’s blog  jasonnoble.org

There are more resources out there, but these are the resources I found useful for me so far. Hope this will help 😉

>Is it cheating when we using resource?

I don’t think so. In my understand, programming is like an open book exam. As long as you know how to use your resource, you are the smart one here.

>What attitude should we have when we feel smart?

Don’t be like “I feel that I am a genius, so I’m going to be a jerk.” As my professor Jason Noble said Google will not forget! Please remember, You are not the only one matter in this world! If you want to be a jerk, not a team player…no one want to be around you, no matter how smart you are. You will get isolate, you will have bad repetition to find a job, even those who love you will get hurt by your jerk action and don’t want to be around you anymore.

>How to be a good team player?

Pair programming consists of two programmers working at the same computer on a problem. ~ Such as ballroom dance, we should have led and follow. In programming will be driver (writes the code, logic, etc) and the other is the navigator (focused on overall goals, what’s next, etc). Once a while we should switch sits to understand what the other person need to duel with and become more understand of what to do; also, we will become more capable to program on our own while we need.  Every body are a unit individual, pair with different programmer will help us to learn more, and learn faster. We share our knowledge and grow together. Here’s some funny video from my professor Jason Noble’s presentation, enjoy it 😉 http://www.youtube.com/watch?v=rG_U12uqRhE     &      http://www.youtube.com/watch?v=dYBjVTMUQY0

>What to do when I’m overarm?

Take a deep breath, and remind yourself what is your gold? Write down your gold, how many steps you’ve already done, and what problems you have been solve. Then take a look of that, asking yourself “Is it worth it for me to keep go on?”. If your answer is yes, just take a little break, get some fresh air for your brain, get back and find the solution. If your answer is no, and don’t even waste you time anymore.

>What if I cannot find the solution (even use up all my resource)?

Just like lrthw (learn ruby the hard way) said, ignore it and go back later. Sometime we just need to keep go on because the answer might be coming up soon. There’s no rush to get it right away. We don’t want to waste time to stuck on one problems and forget everything else in life. Put it on the side and do another project. It might be your brain just get tired; sometime after a small break you will find the solution so easy that you cannot believe yourself stuck on this at all.

>I mess up all my homework, what can I do?

For me, I’ll try to re-organize them, and delete those I cannot re-organize, then re-do them. I find out this week in class that all my founders are in wrong directories, and I didn’t create different directories for different sections of my homework. Instead, I just delete all my codes and work on the new homework in the same file. I fall behind class in a big way, feeling so stress that I cannot catch up with home works and class. However, in the bright side, not only I learn from my mistake, but also it’s a chance to do my homework again from the beginning. I feel like I should be happy, cause practice make things perfect. Just like my favor quote “Life isn’t about waiting for the storm to pass. It’s about learn to dance in the rain.”

>What is more important?

Pivot Tracker is a really good software for developer to help us track the process of our work. The following are the function in Pivot Tracker. Ice box is a place for stories which not yet have been assign yet. Backlog is a place for stories that are priority. Current is a place for stories someone is working on. And there are some more details I might just open another blog to cover later.

How about outside of homework and works? What is important in life for you? I believe if we have a dream, we should fight for our dream. Don’t put our dream into Ice box. I use to spend a lot of time to missing the pass, lives in my memory. However, past is past, I should just leave it what it is. No matter what, times are not going to wait for us. As Jason said in class, change is what it is. Don’t be afraid to change! We are all going to be change. As my friend Laura Niss said “I’ll be afraid that I didn’t change ten years from now.” A really true indeed statement, isn’t it? Ten years ago, we are still kids don’t know enough to live. Now, most of my friends have been graduated, get into their career, got married, got divorce, have children etc. No matter what, we are not the same person as ten years ago. We should just all move forward even we have our fear. I believe most of us have different background, and we all run into different problems in programming, but we should all believe in ourselves that we will be good at programming some day in the future. Maybe ten years later, we will run into each other, go grab a coffee and talking about talking about the joy in class today.

>How do we find a balance point in life?

It take me a long way, and I’m still learning to balance my life. As I said before, when I stuck on something I cannot solve, I put them on side and gonna come back later. I’m running out of time to study, so I try to study in a smart way…try to understand and re-organize my notes. It talk me a while, but it make me catch up in class a lot more easy. It’s important that you organize your priority list. For example, in my life, friendship and future is more important than love cause people change, feelings change, things change, but knowledge I’ve learned will always be mind. That is why you will see me spend 45% of my time to work, 45% of time to study, 8% of time with my friends which I learn a lot of different knowledge from them, and only 2% for my family. We are all adults, we should all know what is our priority list and schedule our time. I understand even we plans something are always not work out, but we should at least have plans to follow, to keep us organize. We should play a little game of plans and resource: make a plan and write down our gold for which homework we going to do for how long, and check on WakaTime see the difference in between plans and resource.

>How to write a blog?

I saw some of my classmate have super awesome blog, some of them have super professional blog, some of them have really stylish blog. I have one suggestion: Be Yourself! Write something from your understanding, from your mistake become solve problem, something you think it might help others, even something that you think you will enjoy reading back 2 years later ( You will be surprise how much you yourself change 2 years from now on ). I always tell myself: Remember no matter how smart you are, there are some others out there more smart then you. However, don’t be so negative, some others out there is dueling with more issue than us and still fighting. We all choose our own path, and this is my blog, this is my path. What is your path? What do you want your path become?