Tuesday, March 19, 2013

Ubuntu setup Git Server

1. Setup

1.1 install Git-Core in Ubuntu server

        sudo apt-get install git-core

1.2 install Gitosis in Ubuntu server

        sudo apt-get install python-setuptools
        mkdir ~/src
        cd  ~/src
        git clone https://github.com/res0nat0r/gitosis.git
        cd gitosis
        sudo  python setup.py install




2. Configuration

2.1 Enable ssh service in Ubuntu server
   
      to use ssh-server, must open port 22 for
      install ubuntu open ssh
   
       sudo apt-get install openssh-server

       to make sure ssh server enable or not, run  ps -e | grep ssh

       if only can see ssh-agent, means ssh-server not start yet, if see sshd means, ssh-server already start.

       And then restart ssh server
       run :     sudo /etc/init.d/ssh restart

3. Add new user

3.1 cd to gitosis-admin
 
      copy new user's id_rsa.pub to keydir folder, named as new_user.pub

3.2  edit gitosis.conf

       vim gitosis.conf

      edit as follow:

     [group ProjectName]
     members = old_user1 old_user2 new_user
     writable = ProjectName

   save and exit

3.3 back to gitosis-admin folder, push the change to server, then the sever will allow new member to download

       git add .
       git commit -am "add new user"
       git push

       Now the user can clone from the new user

 
4. Create new project

 4.1    in local pc, open gitosis.conf, enter

     [group NewProject]
     members = matthewlu@mamembers = matthewlu@matthews-MacBook-Pro.local vic mac_mini
     writable = NewProject

   save and exit

   push the change to server
   git commit -am "create a new project"
   git push

4.2 in server, in repositories folder , create a new folder
      mkdir NewProject

     cd to NewProject

     Init a new git repository
     git init --bare

 4.3 in local machine

       Create the NewProject

       mkdir NewProject
      git init
      git remote add origin admin@YOURSERVER:NewProject
      git add .
      git commit -am "init a new project"
      git push origin master
 

5. Create .gitignore for new create Xcode git project

   5.1 touch .gitignore
         The location of .gitignore is same as .git, .gitignore is not inside .git


   5.2. vim .gitignore
           add the content below to .gitignore

# Mac OS X
*.DS_Store

# Xcode
*.pbxuser
*.mode1v3
*.mode2v3
*.perspectivev3
*.xcuserstate
project.xcworkspace/
xcuserdata/

# Generated files
*.o
*.pyc


#Python modules
MANIFEST
dist/
build/

# Backup files
*~.nib
   
Then save and exit

5.3  add .gitignore to git

      git add .gitignore
      git commit  -am "create .gitignore file"
      git push origin master



6. Add ssh key to server

    get the publick key  key.pub

    copy the key content to server authorzied_key

    refresh ssh

7. gitignore file for visual studio

    #
# Windows and Mac OS X Temp Cache Files
#
[Tt]humbs.db
*.DS_Store

#
#Visual Studio files
#
*.[Oo]bj
*.user
*.aps
*.pch
*.vspscc
*.vssscc
*_i.c
*_p.c
*.ncb
*.suo
*.tlb
*.tlh
*.bak
*.[Cc]ache
*.ilk
*.log
*.lib
*.sbr
*.sdf
ipch/
obj/
[Bb]in
[Dd]ebug*/
[Rr]elease*/

#
#Tooling
#
_ReSharper*/
*.resharper
[Tt]est[Rr]esult*

#
#Project files
#
[Bb]uild/

#
#Subversion files
#
.svn

#
# Microsoft Office Temp Files
#
~$*

# End of File


8. windows connect to ubuntu server
    the path format is below:
 
    192.168.1.26:repositories/EngagerIntranet.git

       

Monday, March 18, 2013

Converting Longitude and Latitude to a Meaningful Address



This part of code is from Book , Vandad Nahavandipoor.


1. Declare a property of type CLGeocoder


    #import
   #import  
     @interface
     Converting_Meaningful_Addresses_to_Longitude_and_LatitudeViewController UIViewController
    @property (nonatomicstrongCLGeocoder *myGeocoder;
    @end 



2. In viewdidload

            CLLocation *location = [[CLLocation alloc] initWithLatitude:+38.4112810
longitude:-122.8409780f]; self.myGeocoder = [[CLGeocoder alloc] init];
[self.myGeocoder
reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
if (error == nil && [placemarks count] > 0){
CLPlacemark *placemark = [placemarks objectAtIndex:0]; /* We received the results */
NSLog(@"Country = %@", placemark.country); 
NSLog(@"Postal Code = %@", placemark.postalCode);
NSLog(@"Locality = %@", placemark.locality);
}
else if (error == nil &&
[placemarks count] == 0){ NSLog(@"No results were returned.");
}
else if (error != nil){
NSLog(@"An error occurred = %@", error); }
}]; 

Converting Meaningful Addresses to Longitude and Latitude


This part of code is from Book , Vandad Nahavandipoor.


1. Declare a property of type CLGeocoder


     #import
     #import

     @interface
     Converting_Meaningful_Addresses_to_Longitude_and_LatitudeViewController UIViewController
    @property (nonatomicstrongCLGeocoder *myGeocoder;
    @end 


2. In view did load


  • NSString *oreillyAddress =
    @"1005 Gravenstein Highway North, Sebastopol, CA 95472, USA";
    self.myGeocoder = [[CLGeocoder alloc] init];
    [self.myGeocoder
    geocodeAddressString:oreillyAddress completionHandler:^(NSArray *placemarks, NSError *error) {
    if ([placemarks count] > 0 && error == nil){

    NSLog(@"Found %lu placemark(s).", (unsigned long)[placemarks count]); CLPlacemark *firstPlacemark = [placemarks objectAtIndex:0];
    NSLog(@"Longitude = %f", firstPlacemark.location.coordinate.longitude);
    NSLog(@"Latitude = %f", firstPlacemark.location.coordinate.latitude); 
    }
    else if ([placemarks count] == 0 &&
    error == nil){ NSLog(@"Found no placemarks.");
    }
    else if (error != nil){
    NSLog(@"An error occurred = %@", error); }
    }]; 










Sunday, March 17, 2013

Ten online resource for learning coding


  1. Code/Racer
  2. MIT OpenCourseWare
  3. Udacity
  4. Mozilla Developer Network
  5. The CodePlayer
  6. Coursera
  7. Codeacademy
  8. Khan Academy
  9. Learn Python the hard way
  10. HTML5 Rocks

Wednesday, March 13, 2013

ios- Map shows all annotations

The following code is to show all the pin in the map,  it finds the most top pin and the most bottom pin, and count the center and delta.


Here is the code:

-(void)zoomToFitMapAnnotations:(MKMapView*)mapView
{
    if([mapView.annotations count] == 0)
        return;

CLLocationCoordinate2D topLeftCoord;
    topLeftCoord.latitude = -90;
    topLeftCoord.longitude = 180;

    CLLocationCoordinate2D bottomRightCoord;
    bottomRightCoord.latitude = 90;
    bottomRightCoord.longitude = -180;

    for(MapAnnotation* annotation in mapView.annotations)
    {
        topLeftCoord.longitude = fmin(topLeftCoord.longitude, annotation.coordinate.longitude);
        topLeftCoord.latitude = fmax(topLeftCoord.latitude, annotation.coordinate.latitude);

        bottomRightCoord.longitude = fmax(bottomRightCoord.longitude, annotation.coordinate.longitude);
        bottomRightCoord.latitude = fmin(bottomRightCoord.latitude, annotation.coordinate.latitude);
    }

MKCoordinateRegion region;
    region.center.latitude = topLeftCoord.latitude - (topLeftCoord.latitude - bottomRightCoord.latitude) * 0.5;
    region.center.longitude = topLeftCoord.longitude + (bottomRightCoord.longitude - topLeftCoord.longitude) * 0.5;
    region.span.latitudeDelta = fabs(topLeftCoord.latitude - bottomRightCoord.latitude) * 1.15// Add a little extra space on the sides
    region.span.longitudeDelta = fabs(bottomRightCoord.longitude - topLeftCoord.longitude) * 1.15// Add a little extra space on the sides

    region = [mapView regionThatFits:region];
    [mapView setRegion:region animated:YES];
}