2013年9月28日土曜日

Setting up a PC to run Linux/Fedora while keeping Windows install




Task 1 Prepare a USB drive with Fedora installation source

Why?

We need a media that contains Fedora on either CD/DVD or USB thumb drive. I chose USB drive since I have several old USB drives with smaller capacity sitting around at home.

How big should USB drive be?

Fedora 19 installation files is 951 MB. I used 2GB USB drive.


How do I "burn" Fedora installation image to USB drive?


You need to run a program called "USB Live Creator" which is available here.


Once you finish installing USB Live Creator, start the tool.


  • Select an appropriate Fedora image from "Download Fedora" drop-down
  • Insert your USB drive to your PC, and then select it at "Target Device" drop-down

(Press "Refresh" icon as necessary)


Once finished, you have an USB drive from which you can boot up a PC with Fedora.

Task 2 Parepare a USB drive with a partition tool

Why?

In order to keep your existing Windows OS, I need to free up my C: drive on my notebook computer.

I used a tool called Gnome Partition Editor (or Gparted for short). To use Gparted, you need to prepare a media with Gparted on it. I chose yet another USB thumb drive for that (but you can burn a CD too).

The size of Gparted is about 160MB. I have another 1GB USB drive that is used for anything useful at home (I bought this USB drive long time ago, paid $200 dollars back then, thinking it is a good investment! Now the price is so cheap that this is just a junk in my shoe box, but it now has some good use!)

How do I create a USB drive with Gparted?


I used a tool called "Tuxboot", which is available at SourceForge.

Once you download and lunch tuxboot,

  • Select "gparted-live-stable" under "On-Line Distribution" drop-down box (try "gparted-live-testing" if something goes wrong. I had to do that)
  • Select "USB Drive" at "Type:" drop-down.
  • Select an appropriate drive pointing to your USB drive.




Task 3 Prepare your hard drive with free partition

How to reboot using Gparted?

  • Shut down your PC
  • Insert your USB drive into a USB socket
  • Start your PC
  • While the machine is starting up, hit F12 to go to boot menu (NOTE: this key depends on you machine. Carefully watch the initial screen and look for "Boot menu")


At the boot menu, choose USB drive from the list of boot device 



Then, let Gparted start. Provide answers to a series of simple questions. Eventually Gparted user interface shows up.

How to shrink the Windows partition to free up space

With Gparted user interface, you can easily shrink a partition: use mouse to re-size, or punch in a number. As for the size, I chose to simply cut my 500GB drive into half: one for Window and the other for Linux.

How to reserve a primary partition for /home directory (Optional)


You can have an independent partition to be mounted as /home directory so that whenever I need to re-install Linux, I don't lose my data and some applications.

I created a primary partition of 100GB in size. The remaining free space will be used for other part of Linux installation.

Note that this step is optional. If you don't care, just leave the half of the HDD as "free"..

Here is the final state of my C: drive before I quit Gparted.


When you are happy, shut down the machine, and un-plug your USB with Gparted on it.


Step 4 Install Fedora using the USB drive

We will be using the USB drive, which contains Fedora, we created earlier.


  • Remove Gparted USB drive, if its still there
  • Insert the USB drive with Fedora into an USB slot
  • Restart your machine
  • Hit F12 to go to boot menu, then select USB drive.
  • Let Fedora OS to load.

Once Fedora is loaded from USB drive, you will see this choice. Choose "Install to Hard Drive"



Follow instructions. Everything is straightforward, except maybe the part where you configure disk storage.

How to mount my 100GB partition for /home directory


While configuring storage/partitions for Fedora install, I need to tell the install to use my 100GB partition to be mounted to /home

First, select a partition that corresponds to the 100GB partiion. In my case, it is listed as below.


Then, look at the right hand side pane. You can specify "/home" under "Mount Point:" field.



Configure other partitions


I followed information described in Fedora Recommended Partitioning Scheme to set up other major partitions such as /boo, root (/), swap, etc.

My final partitions look like this.



Complete Fedora installation

You need to at least provide a password for super user. Once done, just continue with the instructions.

You are done!

2013年9月19日木曜日

Setting up a HelloWorld Java project with Git and Jenkins under 5 minutes

What is assumed

  • Java is installed
  • Git is installed
  • Jenkins is installed

1. Create a HelloWorld java program



$ mkdir hello


$ emacs HelloWorld.java (or Notepad HelloWorld.java on Windows)


public class HelloWorld {
  public static void main (String[] args) {
    System.out.println("Hello World !!");
  }



$ emacs run.sh (Let's create a script to compile and run. Its Notepad run.bat on Windows)


javac HelloWorld.java
java HelloWorld


$ run.sh (execute the script you just created. Its run.bat on Windows)

2. Create a Git repository for HelloWorld source



$ git init


$ git add HelloWorld.java run.sh


$ git commit -m "created"


$ git log

3. Create a Jenkins job to get latest code from the Git repository and then build and run HelloWorld project



1. In Jenkins, bring up "Manage Plugins" screen




2. Make sure that Jenkins GIT plugin is installed. If not, install it.




3. Create a new Jenkins Job.



Name this job "git_test".


4. In the job configuration page, choose Git for "Source Code Management" and then set "Repository URL" point to your Git repository.




To figure out a string to put in to "Repository URL" box, see my local path to the Git repository can compare with you environment.

[tsuyoshi_watanabe@ywatanabe hello]$ pwd
/home/tsuyoshi_watanabe/sandbox/gittest/hello


5. Add run.sh script as a new build step





4. Putting all together

Choose "Build Now" for our newly created job.






Now, Jenkins hit our Git repository to clone a temporary source tree, and then execute our "run.sh" script.

2013年9月18日水曜日

Test publish a Jar file to your local Artifactory from Gradle build under 5 minutes

What you need:



What is assumed


  • Artifactory is installed at its factory default port 8081
  • Artifactory's pre-configured "admin" user's password is "password" (default)

Steps


1. Create a copy of Java Quickstart

2. Open build.gradle file and replace the content with the gradle script in the following:


buildscript {
    repositories {
        maven {
            url 'http://localhost:8081/artifactory/plugins-release'
            credentials {
                username = "admin"
                password = "password"
            }
        }
    }
    dependencies {
        classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '2.0.9')
    }
}

apply plugin: 'java'
apply plugin: 'artifactory'
apply plugin: 'maven'

sourceCompatibility = 1.5
version = '1.0.2'
group = 'test.quickstart'

jar {
    manifest {
        attributes 'Implementation-Title': 'Gradle Quickstart', 'Implementation-Version': version
    }
}


dependencies {
    compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
}

artifactory {
    contextUrl = "http://localhost:8081/artifactory"   //The base Artifactory URL if not overridden by the publisher/resolver
    publish {
        repository {
            repoKey = 'libs-release-local'
            username = "admin"
            password = "password"
            maven = true
            
        }
    }
    resolve {
        repository {
            repoKey = 'libs-release'
            username = "admin"
            password = "password"
            maven = true
            
        }
    }
}

3. At command prompt, run $ gradle artifactoryPublish

4. Verify that Quickstart.jar file is added to artifactory by checking localhost:8081

Done.

Yet another GIT tutorial under 5 minutes.

At your command prompt, type "git", Nothing happens? Please Google "How to install GIT" and come back.

Just keep typing the following and observe what happens. (This procedure is based on this blog).

Start at any junk directory/folder such as temp.

Start!


$ mkdir gittest


cd gittest


mkdir example.git


cd example.git


git init --bare


cd ..


git clone example.git example1


cd example1


$ emacs test.txt (use Notepad on Windows)


Type "hello" in test.txt, and then save and close notepad.


git add test.txt


git status 


git commit -a -m "new file added."


git status


git push origin master


cd ..


git clone example.git example2


cd example2


git log


emacs test.txt


Type "I am using GIT!" in test.txt, and then save and close notepad.


git status


git commit -a -m "added another line."


git status


git push origin master


cd ../example1


git log


git pull


git log


Done!


You have just simulated a typical coding cycles using any version control system.
  1. Created a new repository for the team
  2. A team member added a new source file (initial implementation)
  3. Another team member modified the file (bug fix)
  4. The first team member received the fix made by his buddy.

2013年7月18日木曜日

How to render JSON key-value properties using AngularJS

See a demo at JSFIDDLE


When you are developing REST API on server side, you sometimes want to have a page that renders JSON data in a bit nice way than a row JSON view (that most browsers do good job rendering, but still somewhat hard to read)

To render JSON data in a simple HTML table (or whatever) format with minimum AngularJS coding, here is how.


JSON Data

Let's say, you have a JSON data (this is from AngularJS Tutorial) available from a controller ("C" part of MVC)

function PhoneListCtrl($scope) {
    $scope.phones = [
        {
            "name": "Nexus S",
            "snippet": "Fast just got faster with Nexus S.",
            "age": 0},
        {
            "name": "Motorola XOOM with Wi-Fi",
            "snippet": "The Next, Next Generation tablet.",
            "age": 1},
        {
            "name": "MOTOROLA XOOM",
            "snippet": "The Next, Next Generation tablet.",
            "age": 2}
    ];
}

HTML markup 

...with AngularJS expressions. Note the expression "(key, value) in phone" below. (By the way, this is "V" part of MVC, and "phones" data is the "M" part, just for the sake of completeness!)

<div>
  <h1>Phones</h1
  <div ng-repeat="phone in phones">
    <h2>{{phone.name}}</h2>
    <table border="1px">
      <tr ng-repeat="(key,value) in phone">
        <td>{{key}}</td>
        <td>{{value}}</td>
      </tr>
    </table>
  </div>
</div>

Result

Phones

Nexus S

age0
nameNexus S
snippetFast just got faster with Nexus S.

Motorola XOOM with Wi-Fi

age1
nameMotorola XOOM with Wi-Fi
snippetThe Next, Next Generation tablet.

MOTOROLA XOOM

age2
nameMOTOROLA XOOM
snippetThe Next, Next Generation tablet.

2013年7月1日月曜日

How to run angular tutorial with IIS 7 or node.js


If you are a developer with Windows machine and want to play with AngularJS, here are the steps.

Downloading Angular tutorial

  1. Create a clone on your machine
    1. Go to https://github.com/angular/angular-phonecat
    2. Choose "Clone in Desktop" (This asks you to give permission to start GitHub windows client)
  2. Download a given "step" within the turoial
    1. Run "git checkout -f -step-0" (here 0 should change depending on which step you want)


    Running Angular tutorial using IIS

    1. Create a new test website
      1. Navigate to "Sites" folder
      2. Right-mouse click and choose "Add Web Site..."
        1. Name it "angulartest"
        2. Point to the directory where Angular tutorial web site exists
        3. Set Port value to 85 (or 86 or 8080, or whatever unused on your system)
    2. Configure permissions
      1. Right-mouse click on "angulartest" website and choose "Edit permissions..."
        1. Under "Sharing" tab, share the folder with "Everyone"
        2. Under "Security" tab, add "Everyone" to the list of users.
    3. Configure application pool for the test website
      1. In IIS, select "Application Pools"
      2. Select "angulartest" from the list
      3. Select "Basic settings..." from the Actions on the right hand side
      4. In Edit Application Pool
        1. Set "No Managed Code" to .NET Framework version
        2. Set "Classic" for Managed pipeline mode
      5. Select "Advanced settings..." from the Actions on the right hand side
        1. Set "NetworkService" at Identity property
    4. Run angular tutorial in a web browser
      1. Browse to localhost:85/app/index.html

    Running Angular tutorial using Node.JS

    1. Install node.js (just download an installer)
    2. Install http-server package
      1. Run "npm install http-server- g"
    3. Start web server
      1. CD into the root directory of Angular Tutorial
      2. Run "http-server -p85  (-p is to specify port)
    4. Run angular tutorial in a web browser
      1. Browse to localhost:85/app/index.html

    2013年6月30日日曜日

    Setting up angularjs on Windows 7

    My ultimate goal was to try out AngularJS, which supposedly gives us MVC in JavaScript world.

    For our game, which is written in .NET stack, I recently set up REST API and WebSocket, and about to embrace JavaScript-oriented browser client.

    Also, my colleague at work set up a web app (there, we use Java as the server) using YEOMAN.

    The world of JavaScript development is pretty alien to me. I've used JQuery and I know basic HTML5/CSS3 stuff, but not much more than that.

    This is just a log of what actions I've taken to get to the point where I have a AngularJS app running (probably integrated to ASP.NET MVC3 - or maybe side-by-side).

     Its work in progress so I may update this later.


    1. Installed Chocolately that gives us a mechanism to install all kinds of software, many of which we know and familiar with (but we use separate "Installers" to install it on Windows). Chocolately let you install at command line.
    2. I used Chocolately to install Yeoman as:
      1. cinst yeoman
    3. To scaffold a web app, this is the Yeoman command line I used, which worked
      1. yeoman init
    4. I was curious about other Yeoman command. One of them is "Yeoman list" to list all packages, but I run into an error:
      1. yeoman list
      2. Error Arguments to path.join must be strings
      3. I found an article that suggests a fix, but I could just not find the file to put a patch (even when I grepped the entire drive. I must be doing something stupid)
    5. I gave up and I decided to do clean install again. By this time, I realized that nodeJS's Node Plugin Manager (nmp) is the tool to install the tools that comprises YEOMAN, namely, yo, grunt, and bower. So I installed them one by one (I basically just followed the "installation" instruction at yeoman.io website.)
      1. npm install -g yo grunt-cli bower
      2. npm install -g generator-webapp
    6. At this point, I believe I have all the tools I needed, some were installed as part of Chocolately install, some other manually by hand. Verify this by just obtaining version number of each tool
      1. node --version
      2. git --version
      3. yo --version
      4. grunt --version
      5. bower --version
      6. ruby --version
      7. compass --version
    7. Once I got these tools installed, then I proceeded to generate AngularJS project (again, just follow "Usage" instruction at yeoman.io website.)
      1. npm install -g generator-angular
      2. yo angular
    This is as far as I got. AngularJS project has been created but I see bunch of errors too and not sure if they are show-stopper or not.