Artikel getaggt mit git

Binary Search NSArray

Though CFArray comes with binary search capability, NSArray does not – at least not within the iPhone SDK. The indexOfObject:inSortedRange:options:usingComparator: can’t be found.

Plus the CFArrayBSearchValues doesn’t tell you whether the key actually is part of the list or not. That’s what the Java JDK does, so let’s implement some category methods

-(NSInteger)binarySearch:(id)key;
-(NSInteger)binarySearch:(id)key usingSelector:(SEL)comparator;
-(NSInteger)binarySearch:(id)key usingSelector:(SEL)comparator inRange:(NSRange)range;
-(NSInteger)binarySearch:(id)key usingFunction:(NSInteger (*)(id, id, void *))comparator context:(void *)context;
-(NSInteger)binarySearch:(id)key usingFunction:(NSInteger (*)(id, id, void *))comparator context:(void *)context inRange:(NSRange)range;
-(NSInteger)binarySearch:(id)key usingDescriptors:(NSArray *)sortDescriptors;
-(NSInteger)binarySearch:(id)key usingDescriptors:(NSArray *)sortDescriptors inRange:(NSRange)range;

ourselves, like

-(NSInteger)binarySearch:(id)key usingFunction:(NSInteger (*)(id, id, void *))comparator context:(void *)context inRange:(NSRange)range
{
    NSLogD(@"[NSArray(MroBinarySearch) binarySearch:%@ usingFunction:]", key);
    if(self.count == 0 || key == nil || comparator == NULL)
        return [self binarySearch:key usingSelector:nil inRange:range];
 
//	check overflow?
    NSInteger min = range.location;
    NSInteger max = range.location + range.length - 1;
 
    while (min < = max)
    {
        // http://googleresearch.blogspot.com/2006/06/extra-extra-read-all-about-it-nearly.html
        const NSInteger mid = min + (max - min) / 2;
        switch (comparator(key, [self objectAtIndex:mid], context))
        {
            case NSOrderedSame:
                return mid;
            case NSOrderedDescending:
                min = mid + 1;
                break;
            case NSOrderedAscending:
                max = mid - 1;
                break;
        }
    }
    return -(min + 1);
}

See the full interface + implementation + testcase without html encoding dirt at github.

Tags: , , , , , , , , ,

Upgrade to Snow Leopard

  1. Mac OS X 10.6 Snow Leopard (partition 25G, HFS+ Journaled, Upper/Lower)
  2. Mac OS X 10.5 Leopard (partition 25G, HFS+ Journaled, Upper/Lower)
  3. partition userspace 100G, HFS+ Journaled, Upper/Lower
    $ cat /etc/fstab
    # mount partition "userspace" as /Users
    UUID=D016E3FD-E322-3006-A8F5-D2348C6A5B7B	/Users	hfs	rw,auto
  4. create user “mig”
  5. TimeMachine restore Users + Settings
  6. delete user “mig”
  7. manually copy user “Shared”
  8. iPhone SDK 3.1.2 + XCode 3.2.1
  9. modgenerator 1.5 plus trick
    $ ln -s /Developer/usr/bin/momc /Developer/Library/Xcode/Plug-ins/XDCoreDataModel.xdplugin/Contents/Resources/momc
  10. git 1.6.5.2, manually add to .bash_profile:
    export PATH=$PATH:/usr/local/git/bin
  11. Macports / http://trac.macports.org/wiki/Migration
    $ sudo port selfupdate
    $ sudo port install bcpp pwgen wget lftp fortune optipng graphviz ragel imagemagick
    $ sudo port clean --all installed
    $ sudo port -f uninstall inactive
  12. graphviz-2.25.20091129.0545.pkg
  13. Textwrangler 3.0 (2538)
  14. Gimp 2.6.7
  15. NeoOffice 3.0.1
  16. Evernote 1.5.2 (62233)
  17. TrueCrypt 6.3a
  18. Dropbox v0.6.570
  19. Skype 2.8.0.722
  20. Firefox 3.5,5
  21. Miro Video Player 2.5.3 (775f9134)
  22. wxMaxima-0.8.3 & Maxima-5.19.2.dmg
  23. Twain SANE Scanner Support

Remaining issues:

  1. SenTestingKit error highlighting not working.

Tags: , , , , , , , , ,

Add a new repo to a gitosis server

Another quick recipe:

  1. create a local repo: git init
  2. add it to the gitosis conf (git pull, edit gitosis.conf, git commit, git push)
  3. git remote add origin git@example.com:repository.git
  4. git push --force --all

Tags: ,

Delta Debugging / git bisect

Just had the problem – which of the last 40+ commits broke a certain feature in Piccolo2D rev550. As I used git as a svn proxy before, I remembered having heard of it’s binary-search delta-debugging feature.

So I started my first git bisect session:

Den Rest des Eintrags lesen. »

Tags: , , , ,

billiger vServer als git Server

An git finde ich u.a. großartig, daß es so unkompliziert zu hosten ist (auf einem lokalen Filesystem, auf http (readonly), ftp oder webdav Shares, per gitosis (ssh getunnelt), als eigener (readonly) Dienst oder ganz ohne Server via Mail).

Den Rest des Eintrags lesen. »

Tags: , , ,

Re: Version Control is Your Friend

Jeff Lamarche blogs “Version Control is Your Friend”. I fully agree that version management is a phantastic pain killer – even when you’re a one man show.

The important difference version management makes to me, is, that I can delete, clean up and refactor with ease and without the fear of ever loosing anything. And removing cruft from my projects helps to remain focused.

Den Rest des Eintrags lesen. »

Tags: ,

vServer mit gentoo – oder doch besser ohne.

Vor 4 Tagen habe ich mir den kleinsten vServer von meinen Hosting Freunden vom Campusspeicher geholt um einige Git Repos (v.a. die Email Backups) jenseits des DSL Flaschenhalses zu lagern.

Außerdem wollte ich einen SSH-fähigen Lagerplatz, da mir eine unverschlüsselte FTP Übertragung auf Dauer einfach unangenehm war.

Den Rest des Eintrags lesen. »

Tags: , , ,

Git Repo auf WebDAV (1&1)

Eigene Git Repositories gehen auch mit billigem Shared Hosting recht bequem, falls der Hoster WebDAV anbietet. Z.B. bei 1&1 ist WebDAV auf Port 81 aktiviert.

Und so geht’s:

WebDAV Zugriff

Hier führen viele Wege nach Rom – ich wähle den via davfs2. Letztlich müssen wir nur in der Lage sein, ein Verzeichnis auf dem WebDAV Server anzulegen. Natürlich geht das auch per FTP, aber wenn wir schon WebDAV haben, benutzen wir’s auch gleich dafür.

  1. Eintrag in /etc/fstab:
    $ echo "http://www.myserver.example:81/	/home/localusername/mnt/myserver davfs noauto,user,nolocks 0 0" >> /etc/fstab
  2. WebDAV Zugangsdaten für davfs2:
    $ mkdir -p ~/.davfs2
    $ echo "http://www.myserver.example:81/ MyDavUser MyDavPwd" >> ~/.davfs2/secrets
    $ chmod 600 ~/.davfs2/secrets
  3. mounten:
    $ mount /home/localusername/mnt/myserver
  4. das leere Verzeichnis anlegen:
    $ mkdir /home/localusername/mnt/myserver/myproject.git

Ein (remote) Git Repo anlegen

Siehe dazu auch Shared Git Repository per Webdav.

  1. ein leeres Verzeichnis myproject.git auf dem WebDAV Server anlegen,
  2. lokal ein leeres Git Repo anlegen:
    $ mkdir myproject.git
    $ cd myproject.git
    $ git init --bare
  3. ggf. ein bestehendes Git Repo “importieren”:
    $ git pull UrlOfExistingRepo
  4. WebDAV Zugangsdaten für git hinterlegen:
    $ echo "machine myserver.example login MyDavUser password MyDavPwd" >> ~/.netrc
    $ chmod 600 ~/.netrc
  5. und das neue Repo hochladen:
    $ git push --all --force http://myserver.example:81/myproject.git

Nicht-WebDAV Zugriffe verhindern

Soll der Zugriff auf das Repo exklusiv nur per WebDAV erlaubt sein, empfiehlt es sich das Verzeichnis myproject.git auf dem Webserver zu sperren bzw. nur einen Benutzer zu erlauben, der ansonsten nicht benutzt wird.

Das geht über die Management Console des Webhosters oder indem man die entsprechende .htaccess Datei selbst erstellt und im Verzeichnis myproject.git ablegt.

Tags: ,