Search
Archive

You are currently browsing the archives for the Turoial category.

Categories
Ad

Archive for the ‘Turoial’ Category

share repositories in windows with osx using “git push”

Wednesday, June 17th, 2009

Problem

You have a git repos in Windows XP, and you want to share that with your MacOSX machine. The easiest way seems git clone in MacOSX. However, my win repos are in D drive and I did not find out how to write the repos path. I did

git clone tomoya@windows:d:\home\git.git
git clone tomoya@windows:d:\\home\\git.git
git clone tomoya@windows:d:/home/git.git
git clone tomoya@windows:"d:/home/git.git"

but all failed in vain.

Thus, I changed my mind to use git push from Windows.

Solution

SSH server on Windows

First, if you have not installed cygwin, or any SSH server for Windows, install freeSSHd. This programs runs on Windows as a SSH server.

create repository in MacOSX

[MacOSX]
tomoya@macosx% cd ~/Workspace/git
tomoya@macosx% git init

Add remote repository

[Windows]
D:\home\git> git remote add origin tomoya@macosx:/Users/tomoya/Workspace/git

Try connectiing to remote

[Windows]
D:\home\git> git remote show origin

Then I got a error as

Permission denied (publickey,keyboard-interactive).
fatal: The remote end hung up unexpectedly

This is because my MacOSX requires key authentication. So, I specified pub.key files just by creating config file in %HOME%/.ssh/.

[Windows]
D:\home\git> notepad "%HOME%\.ssh\config"

and, type

Host 192.168.1.21
  User tomoya
  Port 22
  Hostname 192.168.1.21
  IdentityFile C:/id_rsa
  TCPKeepAlive yes
  IdentitiesOnly yes

Try connecting again.

[Windows]
D:\home\git> git remote show origin
zsh: command not found: git-upload-pack
fatal: The remote end hung up unexpectedly

Great. I had these errors because my default login shell on MacOSX is zsh and my zsh does not know where git-upload-pack command is. Check whether git-upload-pack is installed correctly.

[MacOSX]
tomoya@macosx% which git-upload-pack
/opt/local/bin/git-upload-pack

OK. Now check if i have .zshenv file in your home directory.

[MacOSX]
tomoya@macosx% cat ~/.zshenv
cat: /Users/tomoya/.zshenv: No such file or directory

I do not. So I made a symbolic link to .zshenv.

[MacOSX]
tomoya@macosx% ln -s ~/.zshrc ~/.zshenv

More detailed infomation about .zshrc and .zshenv can be found at here: http://zsh.dotsrc.org/Intro/intro_3.html.
Try connecting fot the third time.

[Windows]
D:\home\git> git remote show origin
* remote origin
  URL: tomoya@192.168.1.21:/Users/tomoya/Workspace/git
  HEAD branch: master
  Remote branch:
    master tracked
  Local ref configured for 'git push':
    master pushes to master (up to date)

Hoora! We made it. Ok, move on to next task.

Push to OSX

[Windows]
D:\home\git> git push origin master

And on MacOSX,

[MacOSX]
tomoya@macosx% ls ~/Workspace/git

If you see no files in this directory, this is because pushed files are deleted temporarily, so revert all the files as

[MacOSX]
tomoya@macosx% git reset --hard HEAD

That’s all. Now you have the second repos in your Mac OSX.

Ruby Sinatra application on Google App Engine Java

Wednesday, June 17th, 2009

This article is all about what I have done to make my first Sinatra application on Google’s App engine/Java aka GAE. As you know, Sinatra is a light web application framework for Ruby. We can run Sinatra on GAE because GAE has started to support Java since April 2009 and there existed a Java implementation of Ruby called JRuby.

Before proceeding, you are sure that you already have a valid account for GAE. Otherwise, hurry up to register your account at here.

OK, now you are ready and let’s get started!

Install JRuby

First, download a JRuby package using git. If you are unfamiliar with Git, tutorials and articles on github, including screencasts and podcasts are your good introduction.

Installation of git on Ubuntu is as easy as

% apt-get install git-core

If you are using other operating systems, check http://github.com/guides/home.

To install JRuby, type

% git clone git://kenai.com/jruby~main

Do not type jruby-main. jruby~main is correct.

Moving to jruby~main directory, start compiling.

% cd jruby~main
% ant
% ant jar-complete

Check the jruby version with

% bin/jruby –version
jruby 1.4.0dev (ruby 1.8.6p287) (2009-06-16 6586) (Java HotSpot(TM) Client VM 1.5.0_16) [i386-java]

Install Sinatra and related gems

Check the gem version with

% bin/jruby –S gem –version
1.3.3

To install rubygems for your new jruby, try

% bin/jruby –S gem install rake sinatra wabler mongrel
JRuby limited openssl loaded. gem install jruby-openssl for full support.
<a href="http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL">http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL</a>
Successfully installed rake-0.8.7
Successfully installed rack-1.0.0
Successfully installed sinatra-0.9.2
Successfully installed warbler-0.9.13
Successfully installed gem_plugin-0.2.3
Successfully installed mongrel-1.1.5-java
6 gems installed

Did you see OpenSSL messages, too? You can leave it for now.

Install JRuby-Rack

Get a copy of jruby-rack from github.

% cd ../ # only if you are still in jruby~main directory
% git clone git://github.com/nicksieger/jruby-rack.git
% cd jruby-rack
% ../jruby\~main/bin/jruby -S rake SKIP_SPECS=true

Be careful not to forget to add “SKIP_SPECS=true” when you perform rake command in jruby-rack. Without it, rake will fail.

Create Sinatra Appcalition

Now, let’s create a new Sinatra application. First make a directory for our first app.

% mkdir myway-app

Make directories

% mkdir views public config lib

Create files

1. config.ru

require 'rubygems'
require 'sinatra'
root_dir = File.dirname(__FILE__)
set :environment, :production
set :root, root_dir
set :app_file, File.join(root_dir, 'app.rb')
disable :run
require 'app'
run Sinatra::Application

2. app.rb

require 'rubygems'
require 'sinatra'
 
get '/' do
  "Hello from Sinatra running on Java!"
end

3. appengine-web.xml

<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
    <application>live-ch</application>
    <version>1</version>
    <static-files />
    <resource-files />
    <sessions-enabled>false</sessions-enabled>
    <system-properties>
      <property name="jruby.management.enabled" value="false" />
      <property name="os.arch" value="" />
      <property name="jruby.compile.mode" value="JIT"/> <!-- JIT|FORCE|OFF -->
      <property name="jruby.compile.fastest" value="true"/>
      <property name="jruby.compile.frameless" value="true"/>
      <property name="jruby.compile.positionless" value="true"/>
      <property name="jruby.compile.threadless" value="false"/>
      <property name="jruby.compile.fastops" value="false"/>
      <property name="jruby.compile.fastcase" value="false"/>
      <property name="jruby.compile.chainsize" value="500"/>
      <property name="jruby.compile.lazyHandles" value="false"/>
      <property name="jruby.compile.peephole" value="true"/>
   </system-properties>
</appengine-web-app>

4. config/warble.rb

Warbler::Config.new do |config|
  config.dirs = %w(lib views public)
  config.includes = FileList["appengine-web.xml", "app.rb"]
  config.staging_dir = 'war'
  config.java_libs = []
  config.gems = ['sinatra']
  config.gem_dependencies = true 
  config.webxml.booter = :rack 
end

For a test run,

% ruby app.rb
== Sinatra/0.9.2 has taken the stage on 4567 for development with backup from Mongrel

Go to http://localhost:4567/, and you will see a string message that sinatra is running. OK, press Ctrl+C to stop the server.

Setup for GAE

You need to download GAE SDK for Java from here. The latest version at this moment is version 1.2.1, released on May 13, 2009.

After the download is finished, we need to copy appengine-java-sdk-1.2.1/lib/user/appengine-api-1.0-sdk-1.2.1.jar to Sinatra Application’s lib directory.

% cp ~/Downloads/appengine-java-sdk-1.2.1/lib/user/appengine-api-1.0-sdk-1.2.1.jar lib/

Also, we need to copy jruby-rack jars to lib directory.

% cp ../jruby-rack/target/jruby-rack-0.9.5-SNAPSHOT.jar lib/

Next, we need to copy jruby itself in lib directory, and split it into a two files because the original jruby-complete.jar is too big to use in GAE.

% cp ../juby~main/lib/jruby-complete.jar lib/

Then, create a shellscript called split-jar.sh

#!/bin/sh
 
rm -rf jruby-core.jar
rm -rf ruby-stdlib.jar
rm -rf tmp_unpack
mkdir tmp_unpack
cd tmp_unpack
jar xf ../jruby-complete.jar
cd ..
mkdir jruby-core
mv tmp_unpack/org jruby-core/
mv tmp_unpack/com jruby-core/
mv tmp_unpack/jline jruby-core/
mv tmp_unpack/jay jruby-core/
mv tmp_unpack/jruby jruby-core/
cd jruby-core
jar cf ../jruby-core.jar .
cd ../tmp_unpack
jar cf ../ruby-stdlib.jar .
cd ..
rm -rf jruby-core
rm -rf tmp_unpack
rm -rf jruby-complete.jar

And run

% sh split-jar.sh

Try “ls” to see that you have “jruby-core.jar” and “jruby-stdlib.jar” instead of “jruby-complete.jar”.

Now it is time to create “war” files with warbler.

% ../jruby~main/bin/jrruby –S warble

Run at localhost.

% ../appgengine-java-sdk-1.2.1/bin/dev_appserver.sh --port=18080 war

If you have no error, open http://localhost:18080/ with your own browser. you will see the messages.

Deployment

You need to overwrite APPLICATION-ID with your own in appengine-web.xml. When finished, create war files again as

% ../jruby~main/bin/jrruby –S warble

Then running deployment script

% ../appgengine-java-sdk-1.2.1/bin/appcfg.sh update war

If you run this script first time, you will be prompted to input your email address and password. Input your email of your GAE account correctly. After a while, the script will be finished, and you can see your Sinatra/GAE apps at http://{YOUR-APPLICATION-ID}.appspot.com.

 

This is all. Enjoy making Ruby web application on GAE!