Coding Diary of Totz

Web and iOS by Coffee Driven Development (CDD)

Installing Go by Homebrew on Mac OS X

Install go by brew

Install golang by brew. I think that’s the easiest way to install go on OS X.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$ brew install go
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/go-1.4.yosemite.bottle.ta
######################################################################## 100.0%
==> Pouring go-1.4.yosemite.bottle.tar.gz
==> Caveats
As of go 1.2, a valid GOPATH is required to use the `go get` command:
  http://golang.org/doc/code.html#GOPATH

`go vet` and `go doc` are now part of the go.tools sub repo:
  http://golang.org/doc/go1.2#go_tools_godoc

To get `go vet` and `go doc` run:
  go get golang.org/x/tools/cmd/vet
  go get golang.org/x/tools/cmd/godoc

You may wish to add the GOROOT-based install location to your PATH:
  export PATH=$PATH:/usr/local/opt/go/libexec/bin
==> Summary
?  /usr/local/Cellar/go/1.4: 4557 files, 134M

Set Path for Go

Go needs paths for his root directory. I wrote like that.

1
2
3
4
5
# .zshrc
# go
export GOROOT=/usr/local/opt/go/libexec
export GOPATH=$HOME/.go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

It is actually religious problems how people set $GOPATH and $GOROOT. Let you set them up to your belief.

Run Tiny Program

To test, run tiny program of Hello World.

1
2
~/workspace
▶ vi hello.go
1
2
3
4
5
6
7
// hello.go
package main
import "fmt"

func main() {
  fmt.Printf("Hello, world!")
}
1
2
3
~/workspace
 go run hello.go
Hello, world!%

Now it’s working well!

Next time, I will make a command tool or http server in Go.

Maybe it is not good idea to web application in Go right…?


Lightest Weight Sinatra App Template for Heroku Deployment

I prefer use Sinatra to make simple web app rather than Ruby on Rails. And I like using Heroku when I wanna check simply how its going on.

So I made a simplest Sinatra app to deploy the app as soon as possible. You can clone the reporitory and deploy it soon.

Lightest Sinatra App for Heroku

I made two versions, one is using database by PostgreSQL, and another is not using one. If you do not have to use database on Heroku, please checkout light branch.

If you want to use database, please use master branch and do not forget runnning command below to add PostgreSQL addon for heroku.

1
$ heroku addons:create heroku-postgresql

And please edit migrate file to change the scheme of the table, or just remake the migration file. After finishing to edit the migration file, please run command below:

1
$ heroku run rake db:migrate

Please let you see README file for detailed usage.

If you find any bug or ideas, shoot me a message to my twitter account (@totzyuta) or create an issue on the repository page.

Thank you.


Set Up CUI Environment of iTerm and zsh for New Mac

New Mac

I love CUI, commands, the world of characters. And I got a new pc of OS X because of an internship of Cyber Agent I joined this summer. So I set up comfortable environment for nice CUI life by iTerm and zsh.

iTerm

Install

First, I installed iTerm from the URL below.

http://iterm2.com/index.html

That is nicer than default terminal of OS X, I guess. That is very customizable.

Theme Color

iTerm has a lot of color themes. You can access the repository fro the URL below.

https://github.com/mbadolato/iTerm2-Color-Schemes

iTerm2-Color-Shemes is very cool and easy tool. The README.md is really easy to understand and follow the introduction. I could install that easily.

I chose Espresso. That theme is not bright so I prefer.

zsh

zsh is a kind of shell. The default shell of OS X is bash. bash is also great (the author looks so strong anyway..lol) but zsh is nice for geeks who want to customize a shell easily and well.

First installed Homebrew to install other programs.

http://brew.sh/

1
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

And installed zsh by brew command.

1
$ brew install zsh

You can change the default shell if you want.

1
$ chsh -s /usr/local/bin/zsh

And I really want to reccomend oh-my-zsh. That is really easy tool to set many plugins and cool theme for zsh.

You can clone the repository and set up by the commands below.

1
2
% git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
% cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

Set the theme by editing ~/.zshrc file. I chose a theme, avit.

1
export ZSH_THEME="robbyrussell"  

All themes are in ~/.oh-my-zsh/themes/ and also check here: https://github.com/robbyrussell/oh-my-zsh/wiki/Themes

CUI

That is all! CUI is really useful and fun. Let’s enjoy it.


CLI Tool to Tweet from Terminal - twit

twit

I developed an application to tweet from terminal which I wanted (and actually as practice of Ruby).

Let me show the demo of it and how to install.

How to Use

You can tweet as you use a command in terminal.

1
$ twit "It is posted from terminal."

How to Install

The repository of twit is here.

https://github.com/totzYuta/twit

You can start to use this application just four steps.

1. Clone the repository

First, clone this repository into your HOME path. (If you have much knowledge of linux, that’s not a problem to clone into another place.)

1
$ git clone https://github.com/totzYuta/twit

2. Run setting file

Second, let you do setting of your twitter account.

Anyway, let us enter the directory.

1
$ cd ./twit/

And run the setting file by ruby. (If you have not installed ruby, let you install it. I don’t mention how to do it. Please google…)

1
$ ruby setting_twit.rb

After run the program, your default web browser will be automatically opened and the page will tell you to enter your Twitter ID and Password.

You can get the PIN code after login. Copy and paste that after the words “Please Enter Your PIN: ”

3. Set the pathes

Set the pathes to make it available to use “twit” command anywhere.

Then, please set absolute path. Change “YOUR_USER_NAME” to your user name.

1
2
3
$ sudo ln -s /Users/YOUR_USER_NAME/twit/setting_twit.rb /usr/bin/
$ sudo ln -s /Users/YOUR_USER_NAME/twit/setting.rb /usr/bin/
$ sudo ln -s /Users/YOUR_USER_NAME/twit/twit /usr/bin/

4. Tweet!

Okay, that’s it! You can Tweet from the terminal by ‘twit’ command!

1
$ twit "It's tweeted  from terminal"
1
♪ Tweeted

Conclusion

If you notice any problem, please let me konw. You can send me a message on Twitter (@yutaTotz) or create an issue at the repository’s page.

Thanks!