Friday, December 24, 2010

Time

HAPPY HOLIDAYS!

Sunday, December 19, 2010

me, myself and C

Most beginning programmer get lost with the C programming language specifically the heart and soul which is POINTERS!

Why we need C/C++ POINTERS

1.Data management on the free store
2.Accessing class member data and functions
3.Passing variables by reference to functions

Example:

char m[] = {1,2,3,4,5}
char *p;
p = &m[3];

Pointers on C-POINTERS

1. Variables in C are memory locations
2. If you are going to change the variable you pass the variable by using pointers otherwise pass it by value e.g

changing the variable "s" pass by pointers

char *str( int i, char *s)
{
while(i) {
s++;
i--;
}
return s;
}


void none(int i)
{
i = i + 1;
return 1;
}

3.) C++ Friend function/classes are used for accessing methods + variables between classes of different type its a communication tool

4.) static void () the function is only visible in the file in which it is defined





Friday, December 17, 2010

Mono tips

Finally, after much sought speculation and stuff like that I installed the mono thingy into my
machine with the following configuration:


Configuration summary for mod_mono

* Installation prefix = /usr
* Apache version = 2.2
* Apache modules directory = /usr/libexec/apache2
* apxs = /usr/sbin/apxs
* apr-config = /usr/bin/apr-1-config
* apu-config = /usr/bin/apu-1-config
* CFLAGS = -g -O2 -I/usr/include/apache2 -I/usr/local/include -I/usr/include/apr-1 -I/usr/include/apr-1
* Verbose logging (debug) = no
* GCOV options used = no
* Profiling enabled = no
* mono prefix = /usr
* Default MonoApplicationsConfigDir = /private/etc/apache2/mod-mono-applications

Take note that there's a problem with the pkg-config-0.18.1.tar.gz stuff on Snow Leopard 10.6.5
you will need to download those shitnitz here http://ftp.novell.com/pub/mono/sources-stable/

:)

Thursday, December 16, 2010

XKCD 541 Emoticon Conundrum

Answer to emoticon conundrum http://xkcd.com/541/

When on Mac, press option+command+t and select the happy face character. Unfortunately that don't solve the problem entirely, there's no wink character ;-)

Saturday, December 11, 2010

Run multiple instances of an app on Mac OS X

Click Applications on Dock, select Automator. Choose Application. On searchbox, type: shell. Choose Run Shell Script, double click it. Then on text area, replace it with this text:

if [ -n "$*" ]; then
    open -n "$*"
else
    osascript -e 'tell app "Finder" to display dialog "PLZ DRAG AN APP 2 MULTIPLE INSTANCE" with title "MULTIPLE INSTANCE LAUNCHER" buttons { "OH HAI" } '
fi

On Pass input, change it to as arguments. Press command+S, on Save as type: Multiple Instance, on Where, choose Applications, click Save. Quit Automator.

Click Applications, drag Multiple Instance to Dock, preferably near Applications folder.

Click Applications, drag an app(example: Calculator) to Multiple Instance, repeat to launch multiple instance of that app.

Watch it on YouTube

mysql anyone?

Saying SEQUEL SERVER instead of MSSQL SERVER is a big no-no for me how about you ? What's up with that? What are the problems of the world ? Why are we here? Those questions intrigues me. Lol! To get you going with uninstalling MySQL on Mac OS X Leopard.

To uninstall MySQL and completely remove it (including all databases) from your Mac do the following:

Use mysqldump to backup your databases to text files!
Stop the database server

sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
edit /etc/hostconfig and remove the line MYSQLCOM=-YES-
rm -rf ~/Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*

The last two lines are particularly important as otherwise, you can't install an older version of MySQL even though you think that you've completely deleted the newer version!

Steve Ballmer on Developers

Are you a "Steve Ballmer" today? I mean, is the weather to hot that you sweat a lot? Your car aircon does not work? Is the sun so high you want to go to the beach?

You get my drift? Maybe this video can help.



This video came from this videos:



and



Credit goes to the respective YouTube uploaders.

Love/Hate Objective C

I recently realized that the learning curve of Java on Android compare to Objective C on iOS is a lot better. The documentations are robust anyway let's just cut the chase this post is about the beauty of Objective C .

OBJECTIVE C for starter

1.) NSLog is a function that
-- Can take one or more parameters. The first parameter is generally the string that is to be printed to the console. The @ symbol in front of the string tells the compiler that this is an Objective-C type string and not a C++ string. The @ symbol is typically used in front of all your strings for iPhone apps. If you do not use the @ symbol, you will probably get a compiler error.
2.) % is called the modulus operator.
This operator returns the remainder of its two operands.

3.) @ tells the O/S that is an objective C file

Classes Terminologies

4.) Pointers are like business card you don't see the real person yet you have the idea that you can reach him anytime.

5.) Two types of class methods
a.) class-method this are static function that uses the + sign (synonymous to public static function myMethod() in php )
+ used for messages that can be used before the object is created. (pseudo static )
b.) instance-method this are the default function of a class denoted by the - sign ( synonymous to private function myMethod() in php)
-(float) Power:(float)width:(float)height; in C/C++ you would write it like this float Power( float width , float height)

- (id)initWithName:(NSString *)newName atFrequency:(double)newFreq {
public function WithNameatFreq(new Name , new Freq)
char getName(char name)
{
}
@interface classname : superclassname {
// instance variables
}
+classMethod1;
+(return_type)classMethod2;
+(return_type)classMethod3:(param1_type)param1_varName;
-(return_type)instanceMethod1:(param1_type)param1_varName :(param2_type)param2_varName;
-(return_type)instanceMethod2WithParameter:(param1_type)param1_varName andOtherParameter:(param2_type)param2_varName;
@end

Note:
Class members declared PUBLIC can be accessed everywhere.
Members declared PROTECTED can be accessed only within the class itself and by inherited and parent classes.
Members declared as PRIVATE may only be accessed by the class that defines the member.
A private method is a method which is not inherited by subclasses. A private variable cannot be used outside the class
A public method is a method which can be called by any object of the class
A protected method can be called by any subclass within its class, but not by unreleated classes.

How to create a new Objective C class project

1.Choose MACOSX application
2.Select Command Line Tool ,ensure that Foundation is chosen for the type
3.If you want to add new objects Add New File
then choose Objective-C class from the MACOSX group make sure the Subclass
of dropdown is set to NSObject
4.How to initialize a class

myObject = [[MyClass alloc] init];
--
HelloWorld* myObject = [[HelloWorld alloc] init];
[myObject printGreeting];
[myObject release]; return 0;

self = meaning successful
nil = meaning failure

Happy coding! :)

nostalgia

Back in college my first assembly language machine problem is reading character input. I found the following old snippets from the nostalgia of my college days.

;======================
.model small
.stack 64
.data
pass db 'wade','$'
ass db '*','$'
input db 'Enter Password: ','$'
invalid db 'Sorry, Invalid Password',13,10,'$'
valid db 'Access Granted',13,10,'$'

.code
main proc near
begin:

add bx,1
mov ah,06
mov al,00
mov bh,07
mov cx,00
mov dx,184fh
int 10h
mov ax,@data
mov ds,ax
mov cx,4
lea SI,pass
mov ah,02
mov bh,00
mov dh,09
mov dl,30
int 10h
mov ah,09
mov dx,offset input
int 21h
compare:
mov dl,[SI]
mov ah,07
int 21h
cmp al,dl
JE right
jmp wrong
right: inc SI
mov ah,09
mov dx,offset ass
int 21h

loop compare
mov ah,07
int 21h
mov ah,02
mov bh,00
mov dh,13
mov dl,34
int 10h
mov ah,09
mov dx,offset valid
int 21h
mov ah,07
int 10h
mov ah,4ch
int 21h
start: JE begin
wrong: inc SI
mov ah,09
mov dx,offset ass
int 21h
mov dl,[SI]
mov ah,07
int 21h
cmp al,dl
loop wrong
mov ah,02
mov bh,00
mov dh,13
mov dl,29
int 10h

mov ah,09
mov dx,offset invalid
int 21h
mov ah,07
int 21h
cmp bx,1
JE start
cmp bx,2
JE start
jmp exit
exit:
int 18h
main endp
End main

That is all folks.

Tuesday, December 7, 2010

Fluent NHibernate: cannot convert lambda expression error

If you received this kind of error...

Cannot convert 'lambda expression' to non-delegate type Options

...just add System.Core in your References

Monday, December 6, 2010

Performing ORDER BY on DISTINCT on Linq to NHibernate(version 3)

You will received errors when doing OrderBy on Distinct result on Linq to NHibernate (NHibernate 3) at the time of this writing:

var cat = session.Query<Product>().Select(x => x.Category).Distinct().OrderBy(s => s);


Convert it to:

var cat = session.Query<Product>().Select(x => x.Category).OrderBy(s => s).Distinct();

Alternatively you can do this, which is quite neat:

var cat = 
        (from c in session.Query<Product>()
        orderby c.Category 
        select c.Category).Distinct();


Note the last two codes produces this(which is performant, heaven thanks):

select distinct category 
 from product 
 order by category asc

Not this:

select distinct category
 from 
 (select category from product
 order by category)


Be aware that if you are using Linq to SQL, the 3rd code construct cannot construct proper query (ORDER BY is omitted on generated query, silent error). Documented here: http://programminglinq.com/blogs/marcorusso/archive/2008/07/20/use-of-distinct-and-orderby-in-linq.aspx

He advises to move the orderby out of query to .Distinct() extension method.

var cat = (from c in session.Query<Product>()    
    select c.Category).Distinct().OrderBy(s => s);

Which leads to attaching two extension methods on the query just to make Linq to SQL emit the correct SQL. Which IMHO, renders the whole point of making Linq as query-like as possible lame.


I prefer the Linq to NHibernate approach than Linq to SQL. Not because NHibernate is database-agnostic(but it certainly adds appeal), but for the reason that it correctly informs the programmer that it cannot do something by not performing silent errors; it fail fast.

Here's the error emitted when performing OrderBy on Distinct expression:

Unhandled Exception: System.NotSupportedException: Operation is not supported.

Friday, December 3, 2010

Unix transport error when unit testing NHibernate for Postgresql under Mono

If you happen to encounter the following error while doing unit testing for NHibernate for Postgresql under Mono...

Internal error
        RemotingException: Unix transport error.

...Change your Npgsql version to a Mono one, then that error won't happen.

That error will appear on unit testing if you are using MS .NET version of Npgsql (example: http://pgfoundry.org/frs/download.php/2868/Npgsql2.0.11-bin-ms.net4.0.zip) under Mono. When unit testing under Mono, you must use Mono version of Npgsql (example: http://pgfoundry.org/frs/download.php/2860/Npgsql2.0.11-bin-mono2.0.zip)

Weird problem, the error only appear when the code is run under Unit Testing(built-in in MonoDevelop). But when run independently, MS .NET version of Npgsql will run just fine under Mono. Anyway, to make matters simple, use Mono version of the component if you are building Mono stuff



SMARTBROADBAND FAIL!