Kang-Kyu Lee

Ruby + Rails codewriter

Page 4


setup Rails ubuntu 14.04 LTS

what I tried

ubuntu 14.04 LTS install / and update
—after that
open terminal ctl+alt T
install git - at ubuntu software center

(need git to install rbenv)

$ git --version
git version 1.9.1

install rbenv

$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
$ echo 'eval "$(rbenv init -)"' >> ~/.bashrc
$ exec $SHELL 
$ type rbenv
"rbenv is a function"

https://github.com/sstephenson/rbenvinstallation
https://github.com/sstephenson/ruby-buildreadme

$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
$ rbenv install -list

install three of ruby versions

$ rbenv install 1.9.3-p547
$ rbenv install 2.0.0-p481
$ rbenv install 2.1.2

rbenv install 2.0.0-p451 didn’t work so tried

$ rbenv global 1.9.3-p545
$ ruby -v
ruby 1.9.3p545

and then tried again

$ rbenv install 2.0.0-p451

...

Continue reading →


install zsh ubuntu 14.04 LTS

What I did is…

open ubuntu software center and install “Shell with lots of features” (the first one on top when search by “zsh”)

then did this (alternate way to install zsh) and, got “don’t have to” message.

$ sudo apt-get update && sudo apt-get install zsh 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
zsh is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 21 not upgraded.

then went to “oh-my-zsh” and follow the guides

$ git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
$ cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
$ chsh -s /bin/zsh 

reopen terminal and then… restart Ubuntu and then.

$ subl ~/.zshrc

open and edit this file…

ZSH_THEME="robbyrussell"
plugins=(git)

into

ZSH_THEME="ys"
plugins=(git rbenv gem bundler)

find themes

$ cd ~/.oh-my-zsh/themes/
$ ls

https...

Continue reading →


Setup Ruby with Ubuntu

setup Ruby on Ubuntu 12.04 LTS with rbenv - I installed Ubuntu to my old laptop (Windows 7) with - wubi. And I did

open terminal = ctrl + alt + T

(and then connect to Wi-Fi )

install git

$ sudo apt-get update
$ sudo apt-get install git

https://github.com/sstephenson/rbenvinstallation

https://github.com/sstephenson/ruby-buildreadme

follow direction and install rbenv + ruby-build

$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
$ echo 'eval "$(rbenv init -)"' >> ~/.bashrc
$ exec $SHELL 
$ type rbenv
"rbenv is a function"
$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

install ruby - stable versions

  • Ruby 1.9.3-p545
  • Ruby 2.0.0-p451
  • Ruby 2.1.1
$ rbenv install 1.9.3-p545
$ rbenv install 2.0.0-p451
$ rbenv install 2.1.1
$ rbenv versions
$ rbenv global 2.0.0-p451
$
...

Continue reading →


HTTP, a stateless protocol

  1. The Protocol Every Web Developer Must Know - Part 1
  2. HTTP Made Really Easy

These two links are what I read on. From requests, server make it responses.

It’s a stateless, application-layer protocol for communicating between distributed systems.

There are “verbs” such as

  • GET
  • POST
  • PUT
  • DELETE

and “status codes”

  • 200 OK
  • 301
  • 404 Not Found
  • 500 Internal Server Error

Have a Request, three things

  • url (Link / Path / Route)
  • a verb
  • parameters

give a Response

  • status code
  • message body (payload)

check Request header. Response format. use “HTTP client” tool.

and use Chrome/webkit inspector.

Continue reading →


Terms: parameter, argument

if a method takes arguments, we say it accepts or expects those arguments.

The argument is the piece of code you actually put between the method’s parentheses when you call it, and the parameter is the name you put between the method’s parentheses when you define it.

def square(number)
    puts number**2
end

square(2) 

 number <= parameter
 2 <= argument

It is always good to know the terms right, again from Codecademy.

View →


have a hash with a default value

Revisiting codecademy Ruby… it says:

If you have a hash with a default value, and you try to access a non-existent key, you get that default value.

irb(main):001:0> a = Hash.new
=> {}
irb(main):002:0> b = Hash.new(0)
=> {}
irb(main):003:0> a["john"]
=> nil
irb(main):004:0> b["john"]
=> 0
irb(main):005:0> a == b
=> true

This is great…

View →


start with Git

Steps to start Github.com

  1. open the terminal

  2. in a local directory, say

    git init
    

    as like

    ~/projects/first_repo $ git init
    

    (before this step, install “git” on your laptop)

  3. and then, say

    git remote add origin repo_url
    

    with the repo URL (before this, open a github.com account & get a repo)

  4. then it worked. after that, whenever edit something on the directory (when have something to commit) use

    git status git add . 
    git commit -m "description"
    
  5. and when say finally,

    git push
    

    then it asks login ID & password at github.com

View →


only one copy of symbol

irb(main):001:0> "string".object_id == "string".object_id
=> false
irb(main):002:0> :string.object_id == :string.object_id
=> true

The .object_id method gets the ID of an object—it’s how Ruby knows whether two objects are the exact same object.

irb(main):002:0> string = "string"
=> "string"
irb(main):003:0> string.object_id == "string".object_id
=> false
irb(main):004:0> string = :string
=> :string
irb(main):005:0> string.object_id == :string.object_id
=> true

View →


short circuit evaluation

Ruby doesn’t look at both expressions unless it has to; if it sees

false && true

it stops reading as soon as it sees && because it knows false && anything must be false.

View →


Setup Ruby with Macintosh

http://www.gotealeaf.com/blog/how-to-install-ruby-on-rails-development-environment-for-mac-os-x/

when install rbenv:

echo 'eval "$(rbenv init -)"' >> ~/.bash_profile

if (~/.bashrc) : ‘gem install rails’ not working. why?

when upgrade rubygems:

$ gem update --system
           may need to be administrator or root

https://rubygems.org/pages/download

when install sublime_text

ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl

~/bin/subl seems not working. why?

View →