Configuring an SVN Server on OS X on your Local Network

The following post walks through the steps required to setup a simple SVN server to share files with users on the network. Note: Familiarity with Terminal Commands is required. Please go through the following blogs: Terminal Commands, Terminal Commands 2, Terminal Commands 3

Note:

The following steps illustrate the process of setting up an SVN server for a simple scenario. It can be easily scaled to handle multiple computers & users. In a real world situation you would have to deal with stronger authorisation procedures & larger networks.

 

Requirements for this demo

  • 3 Apple Computers running OS X Mavericks
  • All 3 computers should be on the same network
  • Knowledge of Terminal commands

 

Pre-setup steps

1.Decide which computer you want to setup as the SVN server. Change the hostname of the computer to SVN Server.

2.To change the hostname open System Preferences > Sharing > Click on Computer Name > Enter SVN Server.

3.Create a Share Point where you will be hosting the server. For this exercise we will be creating a separate partition & will be sharing it with other users on the network.

4.To create a new partition open Disk Utility > Select the Disk entry (not the volume entry) > Click on Partition Tab > Select the Partition you want to further partition >  Click on the ‘+’ sign > Specify the name, size & format for the partition (for this demo we will use SVN, 10 GB, Mac OS Extended Journaled) > Click Apply

5.Access authorisation for this share point will be via a sharing only user. Create to users called Employee1 & Employee2. Give them a password emp1 & emp2 respectively.

6.To create sharing only users open System Preferences > Click on Users & Groups > Click on ‘+’ sign to add new user (If necessary authenticate as an admin user to unlock) > From the drop down select Sharing User > Provide the login credentials specified above.

7.Repeat the above step for the second user.

8.Now that we have our users ready we should go ahead & setup the newly created partition for sharing.

9.Open System Preferences > Sharing > Click on File Sharing in the service list, make sure the checkbox is checked > Click the ‘+’ sign under ‘Shared Folders’, add the newly created partition > Under the ‘Users’ list add the newly created sharing users Employee1 & Employee2, remove all other users except Admin > Give the admin user, Employee1 & Employee2 Read-write access & Everyone No Access.

10.Create a folder called ImportFolder in the Documents folder.

cd ~/Documents 

mkdir ImportFolder

  11.  Now that we have prepared the server computer, test the new shared folders from the other 2  computers (which will be used by Employee1 & Employee2).

 

Setting up the svn server

Perform these steps on the SVN Server machine

  1. Create a folder called SVNRepository in the newly created partition: mkdir SVNRepository
  2. Run the command to give admin privileges: sudo chgrp -R admin /Volumes/SVN/SVNRepository/
  3. Create the svn repository. For this exercise lets call the repository as DocumentsRepository.   svnadmin create /SVN/SVNRepository/DocumentsRepository
  4. The next few steps involve configuring the settings for your server.
    1. Enter the /SVN/SVNRepository/DocumentsRepository folder cd /SVN/SVNRepository/DocumentsRepository.
    2. Enter the conf folder. cd conf
    3. Edit the svnserver.conf file.
      1. Edit the following elements in the file, make sure that there is no white space before the line.
      2. anon-access = read //this means no authentication is required to read
      3. auth-access = write
      4. password-db = passwd
      5. Save the file.
    4. Edit the passwd file.
      1. Edit the following elements in the file.
      2. Under users add the following users.
      3. employee1 = password1
      4. employee2 = password2 (Note: For a real world implementation make sure that you use stronger authentication methods for your server.)
      5. Add as many users as you wish.
      6. Save the file.
  5. Start the svnserver (as root) using the following command: sudo /usr/bin/svnserver -daemon -root /SVN/SVNRepositories
  6. Navigate to the folder where all your data is located
    1. cd ~/Documents/ImportFolder
    2. Run the import command to add the files to your repository.
    3. sudo svn import . file://SVN/SVNRepository/DocumentsRepository/ -m “Initial Checkin”
  7. This has setup your svn server with some initial data in it.
  8. Now we perform a sanity check to make sure that all is working well.
    1. cd ~/Documents/
    2. mkdir Test (This is the folder where we will check-out the files from the server)
    3. svn co svn://<ip address of your server>/DocumentsRepository
    4. This should check-out all the files from the repository into your folder.
    5. Check to make sure that all the files were checked out.
  9. If all went ok, then you server is up & ready.

 

Testing the svn process from the 2 different computers

We are now ready to test this on different computers.

  1. Make sure the computer for Employee1 is on the same network.
  2. Open Finder & Browse for the Network partition being shared by the server.
  3. Mount the shared volume in Finder. Authenticate using Employee1’s sharing user credentials if necessary.
  4. Open the Terminal application.
  5. Navigate to the Document’s folder: cd ~/Documents
  6. Create a project folder: mkdir Project.
  7. Navigate to the Project folder: cd Project.
  8. Now we run the command to checkout files into your folder: svn co svn://<ip address of your server>/DocumentsRepository.
  9. Browse through the newly checked out files.
  10. Let us try adding a file to the repository.
    1. Create a new file using TextEdit.
      1. Open Text edit.
      2. Type “This file was created by Employee 1”.
      3. Save the file as Employee_1_Report in the ~/Documents/SVNRepository/DocumentsRepository folder.
    2. Now run the command svn add Employee_1_Report.
    3. Lets commit the changes to the repository: svn ci —message “Adding new file” Employee_1_Report
    4. If prompted to authenticate enter the details you specified in the passwd  file employee1 as the username & password1 as the password.
  11. Now you have added a file to repository from your client machine.
  12. Repeat steps 1 – 9 for Employee2 from a different machine.
  13. Verify that files added from one machine appear on the other.
  14. Thats it. You now have a working svn-server on your local area network.
  15. You can try adding & editing files to check if the changes reflect on both the computers.

 

C++ in iOS – 2

Continuing from the previous post. This one will look into a working example for the same. The code used here is pretty trivial. It is organized in the following sets of files. A c++ header file which contains the declaration of a class. A c++ implementation file (.cpp) where the member functions are implemented. An Objective-C++ header file which holds the C wrapper struct & an Objective-C wrapper object. An Objective-C++ implementation file (.mm) which implements the C struct & all the member functions for both the C struct as well as the Objective-C class.

CppStruct.h


#include <string>
class MyObject
{
     public:
          std::string getName();
          void setName(std::string tempName);
          MyObject();
      private:
           std::string name;
 };

CppStruct.cpp

#include "CppStruct.h"
#include <string>
#include <iostream>

std::string MyObject::getName()
{
     return name;
}

void MyObject::setName(std::string tempName)
{
     name = tempName;
}

MyObject::MyObject()
{
     name = "NIL";
}

CppStructWrapper.h

struct PersonWrapper;

@interface CppStructWrapper : NSObject
{
     struct PersonWrapper *obj;
}

-(void) makeAPerson;
-(void) setName:(NSString *) personName;
-(NSString *) getName;
@end

CppStructWrapper.mm

#import "CppStructWrapper.h"
#include "CppStruct.h"
#include <string>

@implementation CppStructWrapper

struct PersonWrapper
{
     MyObject *personObj;
     std::string getName();

     void setName(std::string tempName);
     PersonWrapper();
};

std::string PersonWrapper::getName()
{
     return personObj->getName();
}

void PersonWrapper::setName(std::string tempName)
{
     personObj->setName(tempName);
}

PersonWrapper::PersonWrapper()
{
     personObj = new MyObject;
}

-(id) init
{
     self = [super init];
     if(self)
     {
          obj = nil;
     }
     return self;
}

-(void) makeAPerson
{
     obj = new PersonWrapper;
}

-(void) setName:(NSString *) personName
{
     std::string temp([personName UTF8String]);
     obj->setName(temp);
}

-(NSString *) getName
{
     NSString *str = [[NSString alloc] initWithUTF8String:obj->getName().c_str()];
     return str;
}

@end

ViewController.m

//this code could be anywhere I have put it inside the ViewController.m within the init message.
#import "ViewController.h"
#import "CppStructWrapper.h"

-(id) init
{
     self = [super init];
     if(self)
     {
          CppStructWrapper *obj = [[CppStructWrapper alloc] init];
          [obj makeAPerson];
          [obj setName:@"ABC"];
          NSString *str = [obj getName];
          NSLog(@"%@",str);
     }
     return self;
}

 

C++ in iOS

As we know there are many libraries out there that are written in C++. Now it would be really nice & handy if we could integrate them into our iOS App. There are many blogs out there that discuss the same.

I found this particular article quite good: http://philjordan.eu/article/strategies-for-using-c++-in-objective-c-projects

The article talks about the PIMPL approach. There is another link to the same related article by the same author:http://philjordan.eu/article/mixing-objective-c-c++-and-objective-c++

The following is one approach towards integrating C++ API into your App. To make things simpler there is a lot of wrapping to do.

Declare your class in the C++ header file as is.

Now to use this class in Objective-C we need a wrapper. To create this wrapper go ahead & make a simple Objective-C class which inherits from NSObject. But once you are done making, rename the extension of the implementation file from .m to .mm, this makes it an Objective-C++ file.

In this file we will be forward declaring a struct which will eventually wrap our C++ class. Create a pointer variable of the struct to be a member of the Objective-C++ class.

Implement the struct in the .mm file to have an object to our c++ class & some member functions to access it. Remember a struct is a valid “C” type. We have created an Opaque struct, but in the implementation it is ok to have member functions (which is allowed in C++). So this struct acts as a bridge between C & C++.

Once you have done this you are set.

The flow for the entire code will be in the form

IOS App Code -> Your Objective-C++ Wrapper -> Your struct wrapper -> Your C++ class in the header file

Continue reading

Attention to Details

One of the most defining things to come out of the Mobility Development revolution is the renewed focus on the User Experience. 

User experience is not a new concept. It has been there around since the beginning. The introduction of GUI (Graphical User Interfaces), & the mouse was one of the first steps taken towards making the users experience better. Its the first thing that people notice. At the launch of a new product people are curious to know how a particular product will look like.

Its the one thing that people say about Apple’s products. “They just look good”. Different companies have tried in their own way to make the User Experience a wonderful experience. But just what makes it click. 

As users we are able to tell when a product looks great & when it doesn’t or lacks in some aspect. This fact is highlighted even more in Mobile Devices. Attention to Detail.

This is most visible in Gaming. Introducing the effects of gravity to give a realistic feel, making sure objects move in the manner & direction in which people expect upon collision, or just moving the screen elements in accordance to the phone. Many of these changes are subtle. We as users would not even realize these things. But we will know for sure if they are absent. It takes some degree of effort to get the attention to detail in place.

A point to note. Im many cases, adding these small features may not improve or enhance the performance/utility at all. But they add a huge advantage in that it gives the user a feeling that he/she is using a great product. Putting in that little extra effort does have an additional value.

BOTTOM LINE: Put in the extra effort to add those nice features to your app. Either something that makes the app look & feel more realistic &/or something that increases the visual appeal of the app.

C++ in todays Day & age

Anyone entering the programming industry at this point in time will be spoilt for choice. There are a whole host of Operating Systems & machines available. The choice caters to all budgets, backgrounds & likes. There is a huge choice in programming languages too. Although some programming languages like C# & Objective-C force users to pick the OS. Others like C,C++,Java don’t place such constraints on the users.

Now there are many rankings available for which programming language is the best. Here are a few links for the same:

http://spectrum.ieee.org/at-work/tech-careers/the-top-10-programming-languages

http://www.siliconindia.com/shownews/10_Most_Popular_Programming_Languages-nid-106520-cid-2.html

The fact that C & C++ are still extremely popular would surprise a lot people. The fact is that a lot of languages that came after these 2 still derive many concepts & features from C & C++. They are must know languages for anyone venturing into the world of programming. Once a person learns these 2 languages it is very easy to branch out & leaner virtually any other language.

Other than C & C++ the other language that is most popular is Java. A lot of people like Java because of the platform independence that it offers. C & C++ are not platform independent. However, they are cross platform languages. Which means that you can develop applications using C & C++ on virtually any OS.

A list of major applications that use C++: http://www.mycplus.com/featured-articles/top-10-applications-written-in-c-cplusplus/

At the end of the day, the decision as to which language is good for developing applications depends on a lot of factors. Discarding C++ early on is not a wise choice. Simply because it is very relevant even today. It has a large set of libraries & is thoroughly time tested.

Bottom line: Do consider using C++, its a highly relevant language & a good place to start your programming career or to make a career out of.