Archive

Posts Tagged ‘OSX’

Mac OS X Package Management with Homebrew

December 13, 2010 Leave a comment

So I reformatted my Macbook Pro over the weekend and deceided to give Homebrew a try. So whats homebrew. Its a package management tool for Mac OS X developed in Ruby. Its really great. I can install library I want and the dependencies are also automatically installed. I really like it.

To get started make sure you install Xcode which is a requirement.

You can install by executing the following statement in the terminal.

ruby -e "$(curl -fsSL https://gist.github.com/raw/323731/install_homebrew.rb)"

Now your done.

Ok lets install some packages now 🙂

brew install git

This will install git to /usr/local/Cellar/git. Package are installed under the /usr/local/Cellar folder and are often symlinked to /usr/local/bin.

Removing a package is also easy.

brew remove git

You can get a list of packages available from https://github.com/mxcl/homebrew/tree/master/Library/Formula/

You can also search for packages using the following command.

brew search packagename

You can also information on packages using the following command.

brew info packagename

You can also update homebrew using the following command. You must have git installed to update.

brew update

There we go.

Hope this helps.

Blair

Advertisements

Crucial SSD Drive Mac Results

September 2, 2010 Leave a comment

Well I have the drive now and am using it with Parallels to run Windows 7 and Visual Studio 2010.
So how do I feel about it.

Well boot times for VMs are fast as with the Mac Book, VS 2010 feels good and thats with Re-sharper 5.1 🙂

Do yourself a favor buy an SSD drive I sure am Happy 🙂

Categories: Development Tags: , ,

Using syslog on Mac OS X in C/C++

May 30, 2010 Leave a comment

Just posting some code on how to write to the syslog in unix. Maybe the title of the post is mis-leading as this should work on all unix based systems. I guess I am just doing it on OS X.

#include <syslog.h>
#include <iostream>
#include <string>
using namespace std;

void writeMessageToSyslogd(const char* message);

int main(int argc, char *argv[])
{
    writeMessageToSyslogd("Blair is writing to syslog");
    return 0;
}

void writeMessageToSyslogd(const char* message){
    openlog("Demo",LOG_CONS,LOG_USER);
    syslog(LOG_ERR,message);
    closelog();
}

Blair…

Categories: Development Tags: , , , , ,

Abstract Methods and Classes in C# and C++

May 21, 2010 Leave a comment

Well here we again for our third post today. We are going to look at the diffrences between C# and C++ classes.
Okay so what just is an abstract class?
Well here is the definition from Wikipedia 🙂

“In programming languages, an abstract type is a type in a nominative type system which is declared by the programmer. It may or may not include abstract methods or properties that contains members which are also shared members of some declared subtype. In many object oriented programming languages, abstract types are known as abstract base classes, interfaces, traits, mixins, flavors, or roles. Note that these names refer to different language constructs which are (or may be) used to implement abstract types.
Two overriding characteristics of abstract classes is that their use is a design issue in keeping with the best object oriented programming practices, and by their nature are unfinished.”

Really abstract classes can define some implementation but really require the class to be subclassed. I really use these when I want some definition in a base class with some methods that have no implementation that need to be provided in the derived class. When in doubt if no fields or state is required but just property or method definition prefer interfaces.

using System;

namespace CSharpClasses
{

	public abstract class Shape
	{
		protected string shapename;
		public Shape(string shapeName){
			this.shapename = shapeName;
		}
		public abstract void DisplayName();
	}
	
	public class Rectangle : Shape{
		public Rectangle() : base("Rectange"){}
		public override void DisplayName ()
		{
			Console.WriteLine("Awesome: {0}", shapename);
		}
		
	}

	class MainClass
	{
		public static void Main (string[] args)
		{
			Shape s = new Rectangle();
			s.DisplayName();
		}
	}
}

The definition in C++ in not so nice. There is no abstract keyword it is implied when virtual methods have the = 0 on the end.

#include <iostream>
#include <string>
#include <typeinfo>

using namespace std;


class Shape{
protected:
    string shapename;
public:
    Shape(const string shapeName);
    virtual void displayName() = 0;
};

Shape::Shape(string shapeName){
    this->shapename = shapeName;
}

class Rectange : public Shape{
public:
    Rectange(const string shapename);
    virtual void displayName();
};

Rectange::Rectange(const string shapename) : Shape(shapename){
}

void Rectange::displayName(){
    cout << "Awesome: " << shapename << endl;
}

int main(int argc, char *argv[])
{
    Shape* s = new Rectange("Rectange");
    s->displayName();
    delete s;

    /*
        Shape test("Rectange");
        Wont compile as Shape has pure virtual functions - what c++ calls abstract methods
      */
    return 0;
}

Lets look at constructors in detail in my my next post

Blair..

Categories: Development Tags: , , , , , ,

Learning C++

May 17, 2010 Leave a comment

So I have taken the plunge and actually started learning C++. You may ask why. Well I want to see the difference between C++ templates and C# generics.
Interesting stuff.

Well I guess I can do some OS X development also 🙂

Blair….

Categories: Development Tags: ,

Mac OS X Dock 2D

May 16, 2010 Leave a comment

I actually prefer the OS X dock in 2D mode.

Type the following in your terminal and enjoy.
defaults write com.apple.dock no-glass -boolean YES; killall Dock

Categories: Development Tags: , , , , ,

NAnt Overriding properties from the console

May 13, 2010 Leave a comment

If you have a property in your project which may change depending on a commandline switch you can override it using the -D:name=value commandline switch.

I the sample below I am overriding the property from the commandline.

<?xml version="1.0" encoding="utf-8"?>
<project name="nantexamples" default="cli-property-overrides" xmlns="http://nant.sf.net/release/0.86-beta1/nant.xsd">
	<property name="mode" value="default"/>
	<target name="cli-property-overrides">
		<echo message="The value of mode is ${mode}" />
	</target>
</project>

[/Users/blairdavidson/Projects/NantExamples] nant -D:mode=cli-value -buildfile:NantExamples.build
NAnt 0.86 (Build 0.86.2898.0; beta1; 8/12/2007)
Copyright (C) 2001-2007 Gerry Shaw
http://nant.sourceforge.net

Buildfile: file:///Users/blairdavidson/Projects/NantExamples/NantExamples.build
Target framework: Mono 2.0 Profile
Target(s) specified: cli-property-overrides

[property] Read-only property “mode” cannot be overwritten.

cli-property-overrides:

[echo] The value of mode is cli-value

BUILD SUCCEEDED – 0 non-fatal error(s), 1 warning(s)

Total time: 0 seconds.

[/Users/blairdavidson/Projects/NantExamples]

Categories: Development Tags: , , , , , ,