Tuesday, August 23, 2011

Useful Cygwin Commands

find -name \*.jpg
Finds all the files with extension as "jpg" including the subfolders.


ls - list (equivalent to dir in Windos)
cd - change directory


Monday, August 15, 2011

Objective C : NSConstantString(instance) does not recognize

In my attempt to understand Objective C, I have been doing a lot of testing and code writing.
Among many error I encountered, I would like to mention this one in particular since I was unable find much information about this in the internet.

ds@mypc ~/bsp/Cocoa/obj
$ TestAppPhotographer.exe
: Uncaught exception NSInvalidArgumentException, reason: NSConstantString(instance) does not recognize setCaption:

The reson I was getting this error message was due to the fact that when I created an init method to set initial values for our instance variables, I missed a like to "return self;".

Before:

-(id) init
{
if( self = [super init])
{
[self setCaption:@"Default Caption"];
[self setPhotographer:@"Default Photographer"];
}
}

After :

- (id) init
{ if ( self = [super init] )
{ [self setCaption:@"Default Caption"];
[self setPhotographer:@"Default Photographer"];
}
return self;
}

Once I added the above piece of code, it ran okay.

Photographer.h


#import

@interface Photographer : NSObject
{
NSString* caption;
NSString* photographer;
}

-(NSString*) caption;
-(NSString*) photographer;


-(void) setCaption: (NSString*)input;
-(void) setPhotographer: (NSString*) input;
@end


Photographer.m


#import
#import "Photographer.h"


@implementation Photographer

-(NSString*) caption
{
return caption;
}

-(NSString*) photographer
{
return photographer;
}

-(void) setCaption: (NSString*) input
{
//not using garbage collection, we need to release the old object, and retain the new one.
[caption autorelease];
caption = [input retain];
}

-(void) setPhotographer: (NSString*) input
{
[photographer autorelease];
photographer = [input retain];
}


- (id) init
{ if ( self = [super init] )
{ [self setCaption:@"Default Caption"];
[self setPhotographer:@"Default Photographer"];
}
return self;
}

@end


Main.m

#import
#import "Photographer.h"


int main (int argc, char *argv[])
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

Photographer *me = [[Photographer alloc] init];

[me setCaption: @"hello"];
NSLog(@"The caption is %@", [me caption]);

[pool drain];
return 0;
}

GNUmakefile

# Set a path variable to gnustep library directory
export GNUSTEP_MAKEFILES=/c/GNUstep/gnustep/System/Library/Makefiles

# Common Makefile Variables
include $(GNUSTEP_MAKEFILES)/common.make

# Console Project
include $(GNUSTEP_MAKEFILES)/tool.make

# Output Name
TOOL_NAME = TestAppPhotographer

# Source Files
TestAppPhotographer_OBJC_FILES = Main.m Photographer.m

# Class Header (Interface) files
TestAppPhotographer_HEADER_FILES = Photographer.h

# Additional Rules
-include GNUmakefile.preamble

# Objective C Rules
include $(GNUSTEP_MAKEFILES)/tool.make

# Additional Rules
-include GNUmakefile.postamble

Friday, August 12, 2011

Objective C : Difference between instance method (-) and the class method (+)

Ever since I started reading out the Objective C development. This term has come up many times.

Since, being from a .Net background I am always trying to compare the Objective C to .Net ( which is not what I should be doing but it helps me to grasp the idea quickly).

Hence, after running some research I was able to understand the difference between the class method and instance method in Objective C.

Well, “class method” is what we call static method in C#, while instance methods are only available once we have instantiated the object.

E.g

@interface DeepsClass : NSObject

+ (void)myClassMethod;
- (void)myInstanceMethod;

@end

It can now be used like this : -

[DeepsClass myClassMethod];

DeepsClass *object = [[DeepsClass alloc] init];
[object myInstanceMethod];

Thursday, August 4, 2011

IB : FAQ

Nothing on the Transaction Listing dropdown even thou the account is populated:

if (acc.Permissions.Contains(PermissionEnum.ShowTransactions))
{
ddlAccounts.Items.Add(new ListItem(acc.AccountNumber + " " + acc.AccountName + "- Available: " + String.Format("{0:C}", acc.AvaliableBalance / 100), acc.AccountNumber));
}

Thursday, August 12, 2010

Open file in Binary mode DOS

How can we open a .dat or text or any file on Binary mode?

Ans :
open command prompt and type "edit /70

/70
tell the command prompt to open the file in the Binary mode.

Tuesday, August 10, 2010

Using EVAL in asp.net

http://www.15seconds.com/issue/040630.htm


In ASP.NET 2.0, you should generally use the Eval method. And, to make this easier, the DataBinder object that exposes it has been made the default context for all non-hierarchical (rows and columns) data binding expressions. This means that you can use a much simpler syntax. If you just want to display a value without formatting it, use the Eval method directly:


<%# Eval("expression") %>

Or, if you need to format the value, use the second overload that accepts a format string:

<%# Eval("expression"[, "format"]) %>

The format parameter works here just like it does in v1.x. So, for example, you can format the value in a column named Price as currency using:

<%# Eval("Price", "{0:C}") %>

And, as in v1.x, you can use more complex format strings to display text as well as the current row value:

<%# Eval("Price", "Special Offer {0:C} for Today Only!") %>

Friday, July 23, 2010

Hosting WCF services in IIS7 and Windows Vista

Link from http://live.mscommunity.net/blogs/borissevo/archive/2007/10/30/hosting-wcf-services-in-iis7-and-windows-vista.aspx

Hosting WCF services in IIS7 and Windows Vista

Today I spent almost 2 hours trying to run a WCF service hosted in IIS7. After I read a lot of blog and forum posts I finally got a solution which works. Basically, you just need to do this four steps:

Step1: Change the C:\Windows\System32\inetsrv\config\applicationHost.config file. You must add handlers section and one mimeMap tag.

<location path="Default Web Site" overrideMode="Allow">
<system.webServer>
<asp />
<handlers>
<add name="svc-Integrated" path="*.svc" verb="*" type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="integratedMode" />
<add name="svc-ISAPI-2.0" path="*.svc" verb="*" modules="IsapiModule" scriptProcessor="%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv2.0,bitness32" />
</handlers>
</system.webServer>
</location>
...
<staticContent>
...
<mimeMap fileExtension=".svc" mimeType="application/octet-stream" />
...
</staticContent>

Step2: Then you should run servicemodelreg with a -i option:
C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation>ServiceModelReg -i

Step3: Turn a Windows Communication Foundation HTTP Activation feature on. Go to Add/Remove programs, Turn Windows Features on/off and install Windows Communication Foundation HTTP Activation (it is in a Microsoft .NET Framework 3.0 section).

Step4: Go to IIS Manager and add new application to your web site (you must choose Add Application ... option, I also tried with a Add Virtual Directory ..., but it didn't work for me) which physical path will point to your WCF service.

That's all. I hope it will help you if you run in a similar problem.

Friday, May 28, 2010

The type initializer for 'AuthenticationServ.Authentication' threw an exception.



I had this issue before as well but I couldn't remember what I did at that time to fix this issue.
Anyway, I ended up spending hours trying to fix this again.

This is not something a good developer should be doing.
A good develope should always take a note of the issue and remember the fix he did for it.

N'way the fix was simple, it was caused since we were missing log4net.config file in the bin folder.