Did this blog help you solve a problem? Tip me with Bitcoins at: 17dQktcAmU4urXz7tGk2sbuiCqykm3WLs6

Tuesday, April 26, 2011

Setup Remote Shared Git Repository on Linux

Recently I set up Git on a remote Linux machine so that a friend and I could collaborate on a few coding projects. Following are the steps I took to get it all set up. The Linux distro I have installed on the remote host is Ubuntu.


Step 1: Install Git. SSH into the remoteserver and install git using apt-get. This installs git under /usr/bin
sudo apt-get update
sudo apt-get install git-core

Step 2: Set up Git Users
sudo groupadd developers
sudo useradd -G developers -d /home/timmolter -m -s /bin/bash timmolter
sudo passwd timmolter

Step 3: Passwordless SSH

Logged into remote account:
mkdir .ssh
From local account**:
scp ~/.ssh/id_rsa.pub timmolter@hostname:.ssh/authorized_keys
**assuming you already have a SSH key. If not try here.

Step 4: Setup a shared repository
Using an account with sudo-rights ("manager" - not a developer user that you just created):
cd ~
mkdir -p repositories/project.git
cd repositories/project.git
git init --bare --shared=group
ls -l
sudo chgrp -R developers .
ls -l

Now you have your Git repository and you can push you project to it!

Step 5 (optional):

Setup a symbolic link to the repository so the user can access it directly from his/her account.
sudo ln -s /home/manager/repositories/project.git/ /home/timmolter/


Piece of cake!!!

References

kovshenin.com
useradd

Eclipse Trick - Hide Jars on Classpath in Project Explorer

The trick for me was to use the Package Explorer View instead of the Project Explorer View.

Wednesday, April 20, 2011

Human Towers and Collapsing Human Towers

Casteller from Mike Randolph on Vimeo.

Get Year from Date Object in Java

To get the year from a java.util.Date object, we can use the java.text.SimpleDateFormat class. First, create a Date object. Next, create a SimpleDateFormat instance using the getDateInstance() method, passing the String "yyyy" as the argument. Finally, get the year as a String using the format() method passing in the java.util.Date object.

Get Year from Date in Java - Example Code

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

//
// The following example code demonstrates how to
// print out the Year from a Date object.
//
public class GetYearFromDate {

    public static void main(String[] args) {

        Date now = new Date();
        SimpleDateFormat simpleDateformat = new SimpleDateFormat("yyyy");
        System.out.println(simpleDateformat.format(now));

    }
}

Here is the output of the example code:
2011

Disable Spotlight on Mac OSX

Victory! After years of being somewhat irritated about the mdsworker and mds process running in the background and causing my fan to go on sometimes, I finally decided to do something about it. I never use Spotlight anyway so why not get rid it that and save some CPU cycles? There are many suggestions and tricks out there to disable Spotlight on Mac OSX, but most of them didn't make sense to me or didn't do exactly what I wanted when I tried them. The solution that I settled on here is the most effective, reversible, and safest in my opinion.

First a little background about OSX. When your mac boots up, it runs several property-list files (*.plist) via launchd, a unified, open source service management framework for starting, stopping and managing daemons, applications, processes, and scripts. So if we don't want Spotlight to start up and we don't want the mds process to index your drive(s), all we need to do it prevent launchd from starting the plist files that start these processes.

Here's how you do that (tested on Mac OSX Leopard 10.5)...

Spotlight

Open up Terminal, and run the command:
sudo launchctl unload -w /System/Library/LaunchAgents/com.apple.Spotlight.plist

MDS, MDSWORKER

In Terminal, run the command:
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist

Spotlight's Index Files

To get rid of Spotlight's files run the following command in Terminal:
sudo rm -r /.Spotlight-V100

Getting Spotlight back

If you change your mind after diabling Spotlight, all you need to do to start it again is to run the following commands in Terminal:
sudo launchctl load -w /System/Library/LaunchAgents/com.apple.Spotlight.plist
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist

Piece of Cake!!!

**Disclaimer - Use at your own risk. And remember, don't believe everything you read on the Internet! :)


References:

launchctl

Sunday, April 17, 2011

Install EGit for Eclipse

I recently decided to try out EGit, a GIT client plugin-for Eclipse. Following are the steps I took to get it running in Eclipse-Helios.

Step 1: In Eclipse go to Help --> Eclipse Marketplace



Step 2: In the wizard that pops up, highlight "Eclipse Marketplace" and click Next.


Step 3: Search for "git". On the top of the list, EGit showed up for me.


Step 4: Click Install and wait while it calculates requirements and dependencies. Click "Next".


Step 5: Accept the terms and conditions and click "Finish". Choose to restart Eclipse after the install finishes.

Step 6: Window --> Show View --> Other...


Step 7: Find and choose the Git View under Git > Git Repositories.


Now you should have your Git view and you can start using Git from within Eclipse!

Piece of Cake!!!

Remove Timestamp from Date in Java

To remove the timestamp from a java.util.Date object,
we can use the java.text.SimpleDateFormat class. First, create a Date
object. Next, create a SimpleDateFormat instance using the getDateInstance(SimpleDateFormat.SHORT) method. Next, create a String representing the Date without a timestamp with the format method. Finally, create a new Date object using the SimpleDateFormat instance's parse method and passing it the date String.

Remove Timestamp from Date in Java - Example Code

import java.text.DateFormat;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

// The following example code demonstrates how to
// remove the timestamp from a Date object.

public class RemoveTimestampFromDate {

    public static void main(String[] args) {

        Date date = new Date();
        System.out.println(date.toString());

        DateFormat df = SimpleDateFormat.getDateInstance(SimpleDateFormat.SHORT);
        String dateString = df.format(date);
        try {
            Date dateWithoutTimestamp = df.parse(dateString);
            System.out.println(dateWithoutTimestamp.toString());
        } catch (ParseException e) {

        }
    }

}

Here is the output of the example code:
Sun Apr 17 10:44:43 CEST 2011
Sun Apr 17 00:00:00 CEST 2011