Make Better Things



I like to make better things.

Install Gitlabhq with Gitolite on Mac OS X server (Mountain Lion 10.8)

Recently I got a task of setting up a mac mini server (Mountain Lion) with gitlabhq (with gitolite). I tried for around 15 times and finally got succeed. Here are the steps which I followed to setup, hope it will help someone setting up mac server with gitlab.
Step 1 – Create a user “git”

Step 2 – Login into user “git”

Step 3 - Install xcode 4.5

Step 4 - Install command line tools in Xcode. (Xcode -> Preferences -> downloads -> install command line tools)

Step 5 - Install “rails installer” from rails installer.org (this will install many dependencies)

Step 6 - Download and Install mysql from here http://dev.mysql.com/downloads/mysql

Step 7 – Setup root password for mysql with this command

/usr/local/mysql/bin/mysqladmin -u root password NEW_PASSWORD_HERE

Step 8 – Install Homebrew on mac (needed to install few things)

$ ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"

After homebrew install run doctor -

$ brew doctor

Step 9 – Get ownership of /usr/local

$ sudo chown -R $(whoami) /usr/local

Step 10 – Install qt and icu4c with brew.

$ brew install qt
$ brew install icu4c
$ brew install redis

Step 11 – Enable ssh login in system preferences. System Preferences -> Sharing -> Enable remote login

Step 12 – Create a ssh key without a password

$ ssh-keygen -t rsa -N ''

Step 13 -Clone gitolite

$ git clone git://github.com/sitaramc/gitolite

Step 14 - Install gitolite

$ gitolite/install
use the following full path for gitolite:
/Users/git/gitolite/src/gitolite

Step 15 - Put this in .bashrc file and save in your home folder (~) -

export GIT_EXEC_PATH=/opt/local/libexec/git-core

Step 16 - Add this in .bash_profile and save in home folder (~)

$ sudo nano .bash_profile

and put this below text.

export PATH=/Users/git/gitolite/src:$PATH
export PATH=/Users/git/bin:$PATH
export PATH=/usr/local/mysql/bin:$PATH

Restart terminal

Step 17 -Setting up gitolite

Create link for .pub file

$ ln -s .ssh/id_rsa.pub GitlabAdmin.pub

setting up gitolite with ssh key

$ gitolite setup -pk ~/GitlabAdmin.pub

Step 18 - Making sure you can connect with ssh

$ ssh localhost

Step 19 - Confirm that you can connect to the gitolite-admin repository

$ git clone git@localhost:gitolite-admin

Step 20 - Cloning gitlabhq

$ git clone -b stable git://github.com/gitlabhq/gitlabhq.git

Step 21 - Running “bundle” on gitlabhq

$ cd gitlabhq
$ bundle

Step 22 - Bundle complete now -

$ bundle install --without development test

Step 23 - Configuriing gitlabhq

$ cp config/database.yml.example config/database.yml
$ cp config/gitlab.yml.example config/gitlab.yml

Step 24 - Now open this “config/gitlab.yml” and change “base_path” to “Users/git/repositories”

Step 25 - Open config/database.yml and change mysql password to your root account password. for production environment.

Step 26 - Setting up gitlabhq database in production environment -

 $ bundle exec rake db:setup RAILS_ENV=production
 

Got this error -

rake aborted!
dlopen(/usr/local/rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib
Referenced from: /usr/local/rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle
Reason: image not found – /usr/local/rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle

(See full trace by running task with –trace)

Got this fix on Stackoverflow -

$ sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

Running previous command again -

$ bundle exec rake db:setup RAILS_ENV=production

 $ bundle exec rake db:setup RAILS_ENV=production
 

Step 27 - Run redis

$ redis-server /usr/local/etc/redis.conf

Step 28 - Run this -

$ bundle exec rake db:setup RAILS_ENV=production
$ bundle exec rake db:seed_fu RAILS_ENV=production

Step 29 - Run -

</pre>
$ rails s -e production -p 8080
<pre>

Step 30 - open “localhost:8080″ in browser and login with -

login………admin@local.host
password……5iveL!fe

I hope you find this guide helpful. Comments are most welcome!

Open Settings app in iphone using Open URL Scheme

Update: This doesn’t work anymore from iOS 5.1
Thanks Toto.

Do you want to open settings app or any section of settings app from your iOS application? Now you can do this you can use below URLs to open different sections of Settings app.

Preference Shortcuts:
About — prefs:root=General&path=About
Accessibility — prefs:root=General&path=ACCESSIBILITY
Airplane Mode On — prefs:root=AIRPLANE_MODE
Auto-Lock — prefs:root=General&path=AUTOLOCK
Brightness — prefs:root=Brightness
Bluetooth — prefs:root=General&path=Bluetooth
Date & Time — prefs:root=General&path=DATE_AND_TIME
FaceTime — prefs:root=FACETIME
General — prefs:root=General
Keyboard — prefs:root=General&path=Keyboard
iCloud — prefs:root=CASTLE
iCloud Storage & Backup — prefs:root=CASTLE&path=STORAGE_AND_BACKUP
International — prefs:root=General&path=INTERNATIONAL
Location Services — prefs:root=LOCATION_SERVICES
Music — prefs:root=MUSIC
Music Equalizer — prefs:root=MUSIC&path=EQ
Music Volume Limit — prefs:root=MUSIC&path=VolumeLimit
Network — prefs:root=General&path=Network
Nike + iPod — prefs:root=NIKE_PLUS_IPOD
Notes — prefs:root=NOTES
Notification — prefs:root=NOTIFICATIONS_ID
Phone — prefs:root=Phone
Photos — prefs:root=Photos
Profile — prefs:root=General&path=ManagedConfigurationList
Reset — prefs:root=General&path=Reset
Safari — prefs:root=Safari
Siri — prefs:root=General&path=Assistant
Sounds — prefs:root=Sounds
Software Update — prefs:root=General&path=SOFTWARE_UPDATE_LINK
Store — prefs:root=STORE
Twitter — prefs:root=TWITTER
Usage — prefs:root=General&path=USAGE
VPN — prefs:root=General&path=Network/VPN
Wallpaper — prefs:root=Wallpaper
Wi-Fi — prefs:root=WIFI

Distribute Enterprise applications Over The Air (OTA)

iOS supports over-the-air installation of enterprise apps, letting you distribute in-house software to your users without using iTunes or iPhone Configuration Utility.

Here are the steps by which you can create OTA distribution for your Enterprise apps.

Step 1: Archive your project as usual and open Organizer.

Step 2: Select the file you want to distribute and press the Share button.

Step 3: Select “iOS App Store Package (.ipa) and press next.

Step 4: A new window will which will ask you to enter the name of the ipa file. There is a check box at the bottom of the screen “Save for Enterprise Distribution”, select this check box.

Step 5: The window will expand to look something like this.

It will ask you few information on where you want to host the file, its icons and title.

Make sure you enter the application URL to the complete url of the file you would host on your server. Then enter title, subtitle, large icon url (512×512) and small icon url (57×57). Once you select the “ok” a .ipa file and .plist file will save in your select folder.

Step 6: Now we need to create a html file which will have the link of the plist file. Here is the sample file -

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <title>Sushi App</title>
</head>
<body>
  <ul>
    <li><a href="itms-services://?action=download-manifest&url=http://122.160.153.125/sushi_ota_16_05_2012.plist"> Tap Here to Install the Application</a>
  </li>
  </ul>
</body> </html>

Notice the url in form – itms-services://?action=download-manifest&url=http://122.160.153.125/sushi_ota_16_05_2012.ipa
The above is just a sample html which have only the link, you can create more good looking files but just be careful with the link.

Step 7: Now upload .ipa file, .plist file and .html file on the webserver (which you mentioned while saving the ipa file).

Step 8: Open the html file in safari and tap the link to install the app on your device.

What is the difference among nil, NULL, Nil in Objective-C?

They are all zeros, the difference lies in their types

-> NULL is a generic pointer value ((void*)0, to be specific). It points to 0×0.
-> nil is an id. So its points to a non-existent objective-c object
-> Nil is a non-existent objective-c class
-> [NSNull null] is an object that’s meant to stand in for nil in situations where nil isn’t allowed. For example, you can’t have a nil value in an NSArray. So if you need to represent a “nil”, you can use [NSNull null]

Also there is no ‘null’ in the objective c its ‘NULL’ not ‘null’. ‘null’ exist in Java or in C# not in Objective-C

Variable number of arguments in Objective-C methods

Ever wondered how the NSString’s +stringWithFormat: method work? How you can pass endless arguments in it?

Well methods that take variable arguments are known as variadic methods.

Here is an example of such a method

Declare variable argument function in your .h file as below

- (void) appendObjects:(id) firstObject, ...; // This method takes a nil-terminated list of objects.

Here is the definition in .m file –

- (void) appendObjects:(id) firstObject, ...
{
     id eachObject;
     va_list argumentList;
     if (firstObject) // The first argument isn't part of the varargs list,
     {                                   
           [self addObject: firstObject];// so we'll handle it separately.
           va_start(argumentList, firstObject); // Start scanning for arguments after firstObject.
           while (eachObject = va_arg(argumentList, id)) // As many times as we can get an argument of type "id"
           {
               [self addObject: eachObject]; // that isn't nil, add it to self's contents.
           }
           va_end(argumentList);

     }

}