SVN: Recursive Svn Ignore

The easiest way to do this is by creating a global svn ignore file that you wish to copy recursively into all sub-directories.

Step 1: Create global.svn.ignore file. Type "emacs global.svn.ignore"

Step 2: Type files/directories to ignore, each on its own line (ie. *.txt, build)

Step 3: Close emacs by entering Ctrl+x, Ctrl+c, y (for yes)

Step 4: Type "svn propset -R svn:ignore -F global.svn.ignore ."

When complete the command prompt should read:
property 'svn:ignore' set (recursively) on '.'

SVN: Simple Svn Ignore

To svn:ignore on one single directory:

Step 1:
In console, type "svn propedit svn:ignore ."

Step 2: This will open emacs & blank document.

Step 3: In emacs, type file/directory to ignore, each separated by a newline (ie. *.txt, build)

Step 4: Close emacs by entering Ctrl+x, Ctrl+c, y (for yes)

ACROBAT: Graphical Digital Signatures

Step 1: Create an image of your signature as a PNG

Step 2: Create a signature pdf (File > Create PDF > From Blank Page)


Step 3: Paste the signature image onto new pdf

Step 4: Crop the page so the signature dimensions are as small as necessary (Documents > Crop Pages...)


Step 5: Manipulate the Margin Controls fields to control crop size


Step 6: Create a signature template (Acrobat > Preferences...)


Step 7: Select Security on the left, and create new signature by clicking on New...


Step 8: Configure Signature Appearance, select Imported Graphic, click on File...


Step 9: Now you can insert the signature by selecting Appearance

IPHONE: XIB Overlay over openGL

This is an example of overlaying an XIB on top of the Apple openGL template project.

Step 1: Create new OpenGL Template


Step 2: Create new files (Cocoa Touch Classes > UIViewController subclass)


Step 3: Create new xib (User Interfaces > View XIB)


Step 4: Customize the xib however you like


Step 5: Link xib to class (select File's Owner -> Apple+Shift+I. Under 'i' tab, type Class = subclass name)


Step 6: Make view bg transparent (select View -> Apple+Shift+I. Under > Settings > View > Background > set opacity to 0%)


Step 7: Right-click & drag from File's Owner to View


Step 8: Select view


Step 9: In AppDelegate header, alter as follows


Step 10: In AppDelegate class, alter applicationDidFinishLaunching method


Step 11: Run the application.

IPHONE: Unable to locate a suitable developer disk image

PROBLEM:
When attempting to open Xcode with the iPod Touch plugged in (running OS 2.1.1), user receives error: "Unable to locate a suitable developer disk image"

SOLUTION:
cd /Developer/Platforms/iPhoneOS.platform/DeviceSupport
ln -s 2.1/ 2.1.1

IPHONE: Setting up certificates

Even though this is explained in detail on the Programmers Portal... sometimes it's just better with a second tutorial.

Step 1: Create certificate using Keychain Access









Step 2: Upload certificate for authentication

Step 3: Download the issued certificate

Step 4: Drag drop the certificate into Keychain Access > Certificates

JAVA: NIO Socket Implementation (SERVER)

ServerSocketChannel socket = ServerSocketChannel.open();
socket.configureBlocking(false);
socket.socket().bind(new InetSocketAdress("127.0.0.1", 8000);
selector = Selector.open();
socket.register(selector, SelectionKey.OP_ACCEPT);

while(true) {
        if(selector.select()==0) continue;
        Set setKeys = selector.selectedKeys();
        Iterator iteratedKeys = setKeys.iterator();

        while(key.hasNext()) {
                SelectionKey key = (SelectionKey) key.next();
                keys.remove();

                // accept connection
                if(key.isAcceptible()) {
                        // get SocketChannel from key
                        SocketChannel channel = server.accept();
                        channel.configureBlocking(false);
                        // enable read write to channel
                        channel.register(selector, SelectionKey.OP_READ |
                                SelectionKey.OP_WRITE);
                }

                // accept readable package
                if(key.isReadable()) {
                        // get SocketChannel from key
                        SocketChannel channel = (SocketChannel)
                                key.channel();
                        if(channel.isConnectionPending())
                                channel.finishConnect();
                        int read = 0;
                        Charset charset =
                                Charset.forName("ISO-8859-1");
                        CharsetDecoder decoder = charset.newDecoder();
                        CharBuffer charbuffer = null;
                        ByteBuffer buffer = ByteBuffer.allocate(1024);
                        ByteArrayOutputStream stream =
                                new ByteArrayOutputStream();
                        while((read = target.read(buffer)) > 0) {
                                stream.write(buffer.array(), 0, read);
                                buffer.clear();
                        }
                        charbuffer = decoder.decode(
                                ByteBuffer.wrap(stream.toByteArray()));
                        stream.close();
                        return charbuffer;
                }

                // write to channel
                if(key.isWriteable()) {
                        // get SocketChannel from key
                        SocketChannel channel =
                                (SocketChannel) key.channel();
                        channel.write(ByteBuffer.wrap(
                                new String("hello from server").getBytes()));
                }
        }
}

REGEX: Samples

- Search for [c] until the next [

(\\[c\\])[^\\[]*

IPHONE: Http POST request

Execute a POST request

// target URL
CFURLRef URL = CFURLCreateWithString(
        kCFAllocatorDefault,
        CFSTR("http://www.apple.com"),
        NULL);

// request type
CFStringRef requestMethod =
        CFSTR("POST");

// setup request
CFHTTPMessageRef myRequest =
        CFHTTPMessageCreateRequest(
                kCFAllocatorDefault,
                requestMethod,
                URL,
                kCFHTTPVersion1_1);

// body
CFStringRef bodyString =
        CFSTR("[[post content value-pairs]]");

// set body in msg
CFHTTPMessageSetBody(
        myRequest,
        CFStringCreateExternalRepresentation(
                NULL,
                bodyString,
                kCFStringEncodingMacRoman,
                '?'));

// header
CFHTTPMessageSetHeaderFieldValue(
        myRequest,
        CFSTR("Content-Length"),
        (CFStringRef) [NSString stringWithFormat: @"%d",
                CFStringGetLength(bodyString)]);

// header property #1
CFHTTPMessageSetHeaderFieldValue(
        myRequest,
        CFSTR("Host"),
        CFSTR("www.apple.com"));

// header property #2
CFHTTPMessageSetHeaderFieldValue(
        myRequest,
        CFSTR("Content-Type"),
        CFSTR("application/x-www-form-urlencoded"));

// POST it
CFReadStreamRef myReadStream =
        CFReadStreamCreateForHTTPRequest(
                kCFAllocatorDefault,
                myRequest);

CFStreamClientContext myContext =
        { 0, (void*)NULL, NULL, NULL, NULL };

CFReadStreamSetProperty(
        myReadStream,
        kCFStreamPropertyHTTPAttemptPersistentConnection,       
        kCFBooleanTrue);

CFReadStreamSetClient(
        myReadStream,
        kCFStreamEventHasBytesAvailable |
        kCFStreamEventErrorOccurred |
        kCFStreamEventEndEncountered,
        ReadStreamClientCallBack,
        &myContext);

CFReadStreamScheduleWithRunLoop(
        myReadStream,
        CFRunLoopGetCurrent(),       
        kCFRunLoopCommonModes);

CFReadStreamOpen(myReadStream);

CFRelease(myRequest);
CFRelease(URL);

Access the message returned

// debug print message
CFDataRef msgFromRequest =
        CFHTTPMessageCopySerializedMessage(myRequest);

// length of msg
int msgLength =
        CFDataGetLength(msgFromRequest);

// buffer to hold data
Byte* buffer =
        (Byte*) malloc (sizeof(Byte) * msgLength);

// grab data place into buffer
CFDataGetBytes(msgFromRequest, CFRangeMake(0, msgLength), buffer);

// clean up
CFRelease(msgFromRequest);
free(buffer);

XCODE: Change Executable Name

1. Right click on Targets click on General Tab
2. Change the Name to desired Executable Name

SVN: Commands (Continued)

SVN command-line commands

SVN IGNORE

1. Navigate to the parent directory that you wish to edit
2. Type "svn propedit svn:ignore ."
3. In EMACS (default) type the directory/file name, ie.

build
*.txt
text_*.txt

SVN STATUS
1. Allows you to see the diff between local & server

SVN SWITCH

1. Allow you to switch the root directory repository location
2. Type "svn switch --relocate svn://1.2.3.4 svn://5.6.7.8"

SVN CHECKOUT
svn co [src url] [dest dir]
ie. svn co http://svn.collab.net/repos/svn/trunk svn

SVN: Authorization Failed
- You probably need to restart your SVN service
- You probably need to restart your Apache service

OBJ-C: Primitive Array Length

// this accurately obtains the size

int INTS[] = {1, 2, 3, 4, 5};
int length = sizeof INTS / sizeof INTS[0];
RESULT => length = 4

// this fails. returns the size of the pointer (4 bytes)

int* INTS_PTR = &INTS[0];
int length = sizeof INTS / sizeof INTS[0];
RESULT => length = 1

OBJ-C: Printing with NSString

// Printing a single NSString

NSString* string = @"hello world!";
printf("%s", [string UTF8String]);
printf("%s", [string cString]);

// Printing from an array of NSString

NSString* strings[3] = {@"1st string", @"2nd string", @"3rd string"};
for(int i=0; i<3; i++) {
    printf("%s", [strings[i] cString]);
}

OBJ-C: Properties

// if we want to use auto-synthesize

@interface ClassName : NSObject
{
@private
    int variableName;
}
@property (nonatomic) int variableName;
@end

@implementation ClassName
@synthesize variableName;
@end

// if we want to manually make accessors

@interface ClassName : NSObject
{
@private
    int variableName;
}
@property (nonatomic) int variableName;
- (int) variableName;
- (void) setVariableName : (int) param;
@end

@implementation ClassName
@dynamic variableName;

- (int) variableName
{
    return variableName;
}

- (void) setVariableName : (int) param
{
    variableName = param;
}

@end

NOTE:
This allows the user to use
1. instance.variableName = x;
2. x = instance.variableName;
Which is normally NOT allowed because variableName was declared private

instance->variableName is only allowed if
1. instance is a pointer
2. variableName was declared public (does not go through accessors)

In either case, users can use the methods directly due to @synthesize
1. [instance setVariableName:x];
2. x = [instance variableName];

JAVA: Clones

Java cloning will return a shallow copy of the current object.

Vector<Object> objs1 = new Vector<Object>();
objs1.add(new Object());

Vector<Object> objs2 = (Vector<Object>) objs1.clone();

System.out.println(objs1 == objs2); // return false
System.out.println(objs1.elementAt(0) == objs2.elementAt(0)); // return true

This means that clone() creates a totally separate instance of the original, uses up the same amount of space, but each of its Object children point to the same data as the original copy.

OBJ-C: Multi-variable parameters

- (id) foo : (id) firstElement, ...
{
    // list place-holder
    va_list elements;
   
    id first = firstElement;
    id next;
   
    // where to start counting from
    va_start(elements, firstElement);

    do {
        // grab next id
        next = va_arg(elements, id);
        // do something with next
    } while (next != nil); 
   
     // end variable list
     va_end(elements);

     return nil;
}

J2ME: Force Transparency in MIDP2

grab each pixel color using getRGB
mask each pixel color with 0xFF00000

JAVA: How do StringBuffers work?

new StringBuffer(), creates a StringBuffer with capacity of 16 characters.



Java String concatentation operator (+) is implemented using the StringBuffer class

Given:
  String a = "a";
  String b = "b";
  String c = "c";

The following produces the same results at run-time (speed, memory allocation).
  a + b + c
  new StringBuffer().append(a).append(b).append(c).toString();



When does it make sense to use StringBuffer?
  String d = a + b;
  d = d + c;

This now gets compiled into:
  String d = new StringBuffer().append(a).append(b);
  d = new StringBuffer().append(d).append(c);

This obviously is more costly/slower than:
  String d = new StringBuffer().append(a).append(b);
  d.append(c);

JAVA: What is the String Literal Pool?

class a { public static String a = "hello"; }
class b { public static String b = "hello"; }
class c {
  public void static main(String args[]) {
    System.out.println(A.a = B.b); // true
  }

At compile-time:
  Step 1: compile class a, tag "hello" as a special variable that can be loaded into the literal pool during run-time.
  Step 2: compile class b, tag "hello" as a special variable that can be loaded into the literal pool during run-time.

At run-time in main:
  Step 1: load String literal from class A ("hello") into literal pool
  Step 2: attempt to load String literal from class B ("hello") into literal pool.
  Step 3: "hello" already exists, return existing reference to "hello" in the literal pool


Tricking the Compilation for the String Literals

class c {
  public void static main(String args[]) {
    String a = "a";
    String b = "b";
    String c = "a" + "b";
    String d = a + b;
    System.out.println(c==d); // false, because a and b are variables subject to change
  }
}

class d {
  public void static main(String args[]) {
    final String a = "a";
    final String b = "b";
    String c = "a" + "b";
    String d = a + b;
    System.out.println(c==d); // true, because a and b are constants!
  }
}

class e {
  public void static main(String args[]) {
    String c = "a" + "b";
    String d = "ab";
    System.out.println(c==d); // true, because both RHS are constants!
  }
}

String a = "hello";
String b = "hello";
final String c = new String ("hello");
String d = a.intern();

a == b // true
a == c // false
a == d // true


JAVA: Access getResourceAsStream() in static context

Typically, we are used to using:

SomeClassName obj = new SomeClassName();
stream = obj.getResourceAsStream();


Instead, we can access the method statically like so:

stream = SomeClassName.class.getResourceAsStream();

JAVA: What is the Method Area?

Inside a Java virtual machine instance, information about loaded types is stored in a logical area of memory called the method area. When the Java virtual machine loads a type, it uses a class loader to locate the appropriate class file. The class loader reads in the class file--a linear stream of binary data--and passes it to the virtual machine. The virtual machine extracts information about the type from the binary data and stores the information in the method area. Memory for class (static) variables declared in the class is also taken from the method area.

ie. For each object loaded, there is a method table created.

SVN: Start SVN as Windows Service

Type into cmd:
sc create svn
binpath= "\"C:\Program Files\Subversion\bin\svnserve.exe\" --service -r \"C:\Program Files\Subversion\repos\""
displayname= "Subversion Server"
depend= Tcpip
start= auto

Should read: [sc] created successfully.

Now use IPCONFIG to find your IP, on a remote computer type: svn://ipaddress:3690


To delete a service:
sc delete , ie.
sc delete svn


Note:
In the sc create example, the service name is actually svn and NOT Subversion Server.

XP: Windows Registry Hacks

1. Disabling Windows Desktop Search

A. Regedit > HKEY_CURRENT_USER\Software\Microsoft\Windows Desktop Search\DS
B. Set ShowStartSearchBand = 0

2. Search Including Files Without Extensions

A. Regedit > HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ContentIndex
B. Set FilterFilesWithUnknownExtensions = 1

J2ME: Eclipse Error Fixes

ERROR:

java.lang.UnsupportedClassVersionError: com/sun/tools/javac/Main (Unsupported major.minor version 49.0)


SOLUTION:
  • Window > Preferences > Ant > Runtime > Ant Home... > Select C:/.../Ant directory
  • Window > Preferences > Ant > Runtime > Global Entries > Add External JARs... > Select C:/.../JDK142/lib/tools.jar

ERROR:

Errors running builder 'Preverification' on project 'XXXXXXXX' init init


SOLUTION:
  • Right Click Project > Properties > Java Build Path > Libraries tab > Add External JARS... > add CLDC1.1 stub from MPowerPlayer
  • Right Click Project > Properties > Java Build Path > Libraries tab > Add External JARS... > add MIDP2.0 stub from MPowerPlayer

XP: Adding 'Command Prompt' to Context Menu

To bring up Context Menu right click in Windows Explorer

1. Open Regedit

2. HKEY_CLASSES_ROOT\*\shell\cprompt
    @=Command Prompt
3. HKEY_CLASSES_ROOT\*\shell\cprompt\command
    @=c:\windows\system32\cmd.exe

4. HKEY_CLASSES_ROOT\Directory\shell\cprompt
    @=Command Prompt
5. HKEY_CLASSES_ROOT\Directory\shell\cprompt\command
    @=c:\windows\system32\cmd.exe /k cd "%1"

The first part adds the command for all *.* files
The second part adds the command for all directories

JAVA: Quick and Safe Class Splitting

When a class is too large and you need to split it apart.. Best way is to utilize an inner-class, which will split A.class into A.class and A$B.class. Move all static methods of the outer class into the inner class.

For example:

class Outer {
  private int var = 0;
  private static void doSomething() { var = 10; /* large remaining chunk of code */ }
}

into:

class Outer {
  private int var = 0;
  private static doSomething() { Inner.doSomething(); }
  static class Inner {
    private static void doSomething() { var = 10; /* large remaining chunk of code */ }
  }
}

NOTES:
1. Yes static inner classes are allowed. And is required in order to have the static inner method.
2. Yes static inner classes can successfully access the outer class' member variables without any tricks.

VI: Cool Tricks in VIM

Search For Text Beginning of Line
^\<word\>

Search For Multiple Words in a Line (remove spaces)
\(    \<word1\>    \|    \<word2\>    \)

Text Capture (search and replace sometext to sometextxt)

:%s#somete\(xt\)#somete\1\1#g

Replace only WHOLE WORDS (static & !statical)
:%s#\<static\>##g

Globally keep all lines containing the text "profile"
:g!/profile/d

Globally delete all lines containing the text "profile"
:g/profile/d

Globally delete all EMPTY lines in a file
:g/^$/d

Search for the word 'text' only at the end of a line
:text$

DOS: Commands (Continued)

1. Escape characters in DOS
    Use ^

2. Write lines into a file in DOS (write new file)
    Echo Text > text.txt

3. Write lines into a file in DOS (append to file)
    Echo Text >> text.txt

MORE ------------------------------------------

In the following examples, we iterate a list of files and use the idiom ~[idiom] to extract certain part of a given filename.

Extract the filename without the extension : ~n

for %i in (*.*) do echo %~ni

Extract the file extension without the filename : ~x

for %i in (*.*) do echo %~xi

Extract the file attribute : ~a

for %i in (*.*) do echo %~ai

Extract the file time : ~t

for %i in (*.*) do echo %~ti

Extract the drive only : ~d

for %i in (*.*) do echo %~di

Extract the path only : ~p

for %i in (*.*) do echo %~pi 

Extract the complete name : ~s

for %i in (*.*) do echo %~si 

Extract the file length (in bytes) : ~z

for %i in (*.*) do echo %~zi 

The path (with drive) where the script is : ~dp0

set BAT_HOME=%~dp0
echo %BAT_HOME%
cd %BAT_HOME%

The path (without drive) where the script is : ~p0

set BAT_HOME=%~p0
echo %BAT_HOME%
cd %BAT_HOME%

The drive where the script is : ~d0

set BAT_DRIVE=%~d0
echo %BAT_DRIVE%

The complete script name : ~s0

set BAT_PATH=%~s0
echo %BAT_PATH%

The script name only (as called with or without the extension): %0

set BAT_NAME=%0
echo %BAT_NAME%


BREW: Enabling Network for Simulator

To ENABLE, change the following:

delete this line
EVT_TAP 0

change to 0
ENCODING 1

delete this line
SOCKETS 1 0 0 0 1472

C++: Array Initialization C++ vs Java

typical local declaration (with 3 ints allocated in memory)
int x[3] = {1,2,3};

typical local declaration 2 (with 3 ints allocated in memory)
int x[] = {1,2,3};

local declaration with no initial values (with 3 ints allocated in memory)
int x[3]; // ok, initial values undefined

initialization of only SOME values (with 3 ints allocated in memory)
int x[3] = {1}; // x[1] = x[2] = 0

specify size but and initialize the rest to 0 (with 100 chars allocated in memory)
char c[100] = "hi"; // size = 100, c[2-99] = 0

implicitly specify size (with 3 chars allocated in memory)
char c[] = "hi"; // size = 3

SVN: Installing Eclipse Subversion

Step 1: Install MYLAR (now MYLYN)

http://www.eclipse.org/mylyn/downloads/builds.php

Step 2: Install Buckminster

http://download.eclipse.org/technology/buckminster/3.2/updates

Step 3: Install Mylyn

http://download.eclipse.org/tools/mylyn/update/e3.2

Step 4: Install Eclipse SVN (subclipse)

http://subclipse.tigris.org/update_1.2.x

C++: Avoid Memory Fragmentation

Memory fragmentation means having free memory ("holes") between allocated and in-use memories that can't be used because that slot of memory is too small to fill with data. It is not technically a memory leak, but the memory is technically unusable during run-time.

It is believed C# automatically defrags memory so this would not occur.

Example of memory fragmentation:

for( cnt = 0; cnt < 10000; cnt+=3 )

    // Allocate 30 bytes
    m_memory[ cnt ] = new allocator (30 );
    // Allocate 10 bytes
    m_memory[ cnt + 1 ] = new allocator( 10 );
    // Allocate 110 bytes
    m_memory[ cnt + 2 ] = new allocator( 110 );
   
    // De-allocate 10 bytes
    m_memory[ cnt + 1 ] = null;
    System.gc();
}

The 10 bytes deallocated is stuck between 30 and 110 bytes respectively, and is too small to be reused later on.

---- Memory looks like ----

=================
    OCCUPIED                   30 bytes
    OCCUPIED
=================
    LOST...                        10 bytes
=================
    OCCUPIED                   110 bytes
    OCCUPIED
    OCCUPIED
    OCCUPIED
    OCCUPIED
    OCCUPIED
    OCCUPIED
=================

C++: Friends

Friends are external classes that is given permission to access private/protected members of this class.

---- Scenario 1: Friend functions ----

class apples{
    private:
        friend func();
};
class oranges{
    void foo();
};
void oranges::foo() {
    apples* a = new apples();
    a->func();        // this is ok because func is a friend
}

---- Scenario 2: Friend classes ----

class apples{
    friend class oranges;
    private:
        int value;
};
class oranges{
    void foo();
};
void oranges::foo(){
    apples* a = new apples();
    a->value = 10;        // this is ok because oranges is declared as a friend of apples
}

PHOTOSHOP: Key Shortcuts

Shift + [Key] = toggle command

A: Path Selection
B: Brush/Pencil
C: Crop
E: Erase
F: Full Screen Toggle
G: Paint
H: Hand
I: Eyedrop
J: Healing
K: Slice
L: Line
M: Cut
N: Notes
O: Dodge
P: Pen Tool
Q: Quick Mask
R: Blur/Sharpen
S: Clone
T: Text
U: Shapes
V: Move Tool
W: Wand
X: Swap Color Palettes
Y: History
Z: Magnify

C++: Virtual Destructor

Works in the same way as virtual functions, used only when you want to specify which destructor you want to call.

---- Scenario 1 ----

class Parent{
    ~Parent();
};
class Child : public Parent{
    ~Child();
};

Parent* kid1 = new Child;
Child* kid2 = new Child;
delete kid1;        // calls parent destructor because Parent.~Parent is not virtual
delete kid2;        // calls parent destructor followed by child destructor (usual behavior)

---- Scenario 2 ----

class Parent{
    virtual ~Parent();
};
class Child : public Parent{
    ~Child();
};

Parent* kid1 = new Child;
Child* kid2 = new Child;
delete kid1;        // calls child destructor because Parent.~Parent is virtual
delete kid2;        // calls parent destructor followed by child destructor (usual behavior)

C++: Pure Virtual Functions

  1. Pure virtual functions are REQUIRED to be implemented by a child class.
  2. Classes containing pure virtual functions cannot be instantiated.
  3. To use that class a deriving class must eventually implement all pure virtual functions.
  4. Similar to java abstract classes.

C++: Virtual Functions

---- Scenario 1 ----

class Parent {
    public:
        int foo();           // <-- called if Parent.foo is not virtual
};
class Child : public Parent {
    public:
        int foo();           // <-- called if Parent.foo is virtual
};

Child kid;
(Parent) kid.foo();        // calls PARENT version, because Parent.foo is not virtual

---- Scenario 2 ----

class Parent {
    public:
        virtual int foo();
};
class Child : public Parent {
    public:
        int foo();
};

Child kid;
(Parent) kid.foo();        // calls CHILD version, because Parent.foo is virtual

SVN: Externals

1. Right-click on any versioned directory
2. TortoiseSVN > Properties
3. Add...
A. Property name: svn:externals
B. Property value: [DEST:sub-directory] [SRC:svn-location-URL]
ie. res_ext svn://xxx.xxx.xxx.xxx/software/res

Commit the changes. Done!

BREW: ImageMagick Command PNG->BMP

(Install ImageMagick)

for %%i in (*.png) do call convert -background "#ff00ff" %%i -flatten %%i.bmp

Using BMP palettes instead of 24bit color:

for %%i in (*.png) do call convert -background "#ff00ff" %%i -flatten -type "Palette" +matte -colors 256 BMP2:%%i.bmp

C++: Memory Allocation

class A {
    int i;
    class B {
        char c[1024];
    };
};

When we call "A* myA = new A()" the memory looks like this:
- 4 bytes in heap allocated, B was instantiated/allocated

When we call "A myA = A()", the memory looks like this:
- 4 bytes in stack allocated, B was instantiated/allocated

class A {
    int i;
    class B {
        char c[1024];
    } myB;
    // the same as
    // B myB;
};

When we call "A* myA = new A()" the memory looks like this:
- 4 + 1024 bytes in heap allocated, B was instantiated/allocated

When we call "A myA = A()", the memory looks like this:
- 4 + 1024 bytes in stack allocated, B was instantiated/allocated

BREW: Trouble-shooting

"ClassName" : No appropriate default constructor available

Scenario:

Parent: parentConstructor(int x, int y);
Child: childConstructor(int x, int y, int z);

Fix:

Parent: parentConstructor(int x, int y);
Child: childConstructor(int x, int y, int z) : parentConstructor(x, y);

Reason:

This will force the childConstructor to use specifically use parentConstructor(x, y), instead of looking for parentConstructor(x, y, z).

DOS: Recursive set command

Sample recursion to set one environment variable to a collection of text:

set COLLECTION=
setlocal ENABLEDELAYEDEXPANSION

for %%i in (a b c d e) do ( set COLLECTION=!COLLECTION! %%i.cpp )

:: result, COLLECTION=a.cpp b.cpp c.cpp d.cpp e.cpp
echo %COLLECTION%


C++: Preprocessing Messaging

This will print the message "Compiling against Brew SDK v1.1" whenever AEE_SIMULATOR is defined.

#if AEE_SIMULATOR
#pragma message( "Compiling against Brew SDK v1.1" )
#endif

BREW: Batch compile MIF file

In order to DYNAMICALLY insert values into the MIF, you must have .dtd files with the appropriate properties. You then import its properties using the MFX file.

Sample DTD file (cid.dtd)

<!ENTITY APPLICATION_CLASSID "0x00ABCDEF">

Another Sample DTD file (ver.dtd)

<!ENTITY APPLICATION_VERSION "1.0.0">

Sample MFX file

<?XML version="1.0" encoding="utf-8"?>
<!DOCTYPE BREWRes
[
<!ENTITY % version_dtd SYSTEM "ver.dtd">
<!ENTITY % classid_dtd SYSTEM "cid.dtd">
%version_dtd;
%classid_dtd;
]>

... some mfx stuff here

<String Id="8" Name="IDS_STRING_8">
<Text>&APPLICATION_VERSION;</Text>
</String>

... more mfx stuff here

<Applet BaseId="1000" CLSID="&APPLICATION_CLASSID;">

... more mfx stuff here

Finally, to put it all together, just make sure the MFX file can find the *.dtd files, and then call this in command prompt:

brewrc.exe -o output.mif -nh input.mfx

And you're done.

TRAC: Subdomain access

Step 1: Edit C:/Windows/System32/drivers/etc/hosts file by adding:

127.0.0.4      trac.localhost

Step 2: Edit C:/Konami/Web/Apache/conf/extra/httpd-vhosts.conf by adding:

<VirtualHost 127.0.0.4>
    DocumentRoot "C:/Konami/Web/Apache/htdocs/trac"
    ServerName trac.localhost.com
    ServerAlias www.trac.localhost.com
</VirtualHost>

Step 3: Run trac service by using the following command:

bash -c 'C:/Konami/Python/Scripts/tracd
--hostname="trac.localhost"
--port=80
"C:/Konami/Web/Apache/htdocs/trac"'


Now you should be able to access the trac server by entering 'trac.localhost' into your browser.

TRAC: Trouble-shooting

1. "UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position "

Look in: C:\Konami\Python\share\trac\wiki-default for 0xe2

Replace all instances of 0xe2 with "

2. POST does not return users to the correct URL because it's missing the base-url

Look in: C:\Konami\Web\Apache\htdocs\trac\conf\trac.ini

base_url = http://trac.localhost/trac/

3. The 'repository_dir' has changed, a 'trac-admin resync' operation is needed.

./trac-admin "C:/Konami/Web/Apache/htdocs/trac" resync

BREW: Sample BREW batch file

In MAKE_XXX.bat
set GAME_DEFINES=-Ddefine1 -Ddefine2 -Ddefine3
call build_brew.bat contra LG_VX7000 BREW2

In build_brew.bat
set GAME_NAME=%1
set GAME_BUILD=%2

if("%3"=="BREW1) set BREW_SDK=lib\1.1.0
if("%3"=="BREW2) set BREW_SDK=lib\2.1.3
if("%3"=="BREW3) set BREW_SDK=lib\3.1.5

set BUILD_SOURCE=.\src
set BUILD_DEFINES=-DDYNAMIC_APP %GAME_DEFINES%
set BUILD_INCLUDES=-I%BUILD_SOURCE% -I%BREW_SDK%\inc
set BUILD_FLAGS=-cpu ARM7TDMI -apcs/ropi/interwork -littleend -zas1 -zas4 -fa -g -Ospace -O2 -Wy  -c
set COMPILE_ARGS=%BUILD_DEFINES% %BUILD_INCLUDES% %BUILD_FLAGS% -w

:: for each .cpp to compile
tcpp %COMPILE_ARGS% -oFILENAME.o -oDIR\TO\FILENAME.cpp
tcpp ...

armlink -o %GAME_NAME%.elf -ropi "%BREW_SDK%\compiled\AEEAppGen.o" "%BREW_SDK%\compiled\AEEModGen.o" FILENAME.o FILENAME1.o ... -first AEEMod_Load -map -list out.map -split -reloc

elf2mod %GAME_NAME%.elf %GAME_NAME%.mod

WEB: How to create htdigest auth files

Apparently this is the more basic login authentication version of .htpassword. Creation can be done in 2 ways:

#1. using Apache:

A. Open command prompt and goto \Apache\bin

B. htdigest -c trac.htdigest trac.localhost dyu (htdigest [filename] [realm] [username])

C. To add more users to the same digest file: do not use the -c option.

#2. using Python:

A. Paste the following into htdigest.py

from optparse import OptionParser
import md5

usage = "usage: %prog [options]"
parser = OptionParser(usage=usage)
parser.add_option("-u", "--username",action="store", dest="username", type = "string",
                  help="the username for whom to generate a password")
parser.add_option("-p", "--password",action="store", dest="password", type = "string",
                  help="the password to use")
(options, args) = parser.parse_args()

if (options.username is None) or (options.password is None):
   parser.error("You must supply both the username and password")

realm = 'trac'
kd = lambda x: md5.md5(':'.join(x)).hexdigest()
print ':'.join((options.username, realm, kd([options.username, realm, options.password])))

B. python.exe htdigest.py -u dyu -p 123456 >> C:\trac.htdigest


BREW: Notes on Brew

Apparently Visual Studios .NET 2005 does not like it when you pass in an enumeration as a parameter.

warning C4482: nonstandard extension used: enum 'MIDlet::CRITICAL_GAME_STATE' used in qualified name

The offending code would look something like this:

enum GAME_STATE
{
STATE_ON,
STATE_OFF,
};

void func(GAME_STATE gs);
void class::func(GAME_STATE gs) { }

Instead it would be wiser to manually convert the code into int, like so:

public:
const static int STATE_ON=0;
const static int STATE_OFF=1;

void func(int gs);
void class::func(int gs) { }

DOS: Run Unix Commands

In DOS type:

C:\some\random\dir> bash -c 'unixCommand unixCommandParam'

ie. bash -c '/usr/bin/python setup.py install'

The reverse of running DOS commands from Unix can be done by the following:

$ cygstart winCommand 'winCommandParam1' 'winCommandParam2' ... etc

ie. cygstart build.bat LG_VX7000 SMALL

TRAC: Installing Trac the Hard Way

Verdict: Don't bother trying to install Trac with Python 2.5... it's better to use Python 2.4.

Step 1: Download the following files:
A. clearsilver-0.9.14.win32-py2.4.exe
B. MySQL-python-1.2.2.win32-py2.4.exe
C. python-2.4.4.msi
D. svn-python-1.4.4.win32-py2.4.exe
E. trac-0.10.4.win32.exe

Step 1: Install Python 2.4 (python-2.4.4.msi) to C:\Konami\Python

Step 2: Install SVN Python 1.4.4 (svn-python-1.4.4.win32-py2.4.exe). Installer will determine installation directory.

Step 3: Install ClearSilver 0.9.14 (clearsilver-0.9.14.win32-py2.4.exe). Installer will determine installation directory.

Step 4: Install MySQL Python 1.2.2 (MySQL-python-1.2.2.win32-py2.4.exe). Installer will determine installation directory.

Step 5: Install Trac 0.10.4 (trac-0.10.4.win32.exe). Installer will determine installation directory.

Step 6. Alter the 1st line in:
C:\Konami\Python\Scripts\trac-admin
C:\Konami\Python\Scripts\tracd
to:
C:\Konami\Python\python.exe

Step 7: open mysql

Step 8: create database `trac` default character set utf8 collate utf8_bin;

Step 9: open cygwin

Step 10: cd "C:\Konami\Python\scripts"

Step 11: mkdir "C:\Konami\Web\Apache\htdocs\trac"

Step 12: ./trac-admin "C:\Konami\Web\Apache\htdocs\trac" initenv
A. Local SVN
B. mysql://root:123456@localhost:3306/trac
C. svn
D. C:/Konami/Web/Apache/htdocs/svn
E. C:/Konami/Python/share/trac/templates

Step 13: ./tracd --port 8000 "C:/Konami/Web/Apache/htdocs/trac"

Step 14: Open Firefox, goto http://localhost:8000/trac

EDIT (ADDITIONAL STEPS)

Step 15: Install SVN: TortoiseSVN-1.4.4.9706-win32-svn-1.4.4.msi

Step 16: Create repository in "C:/Konami/Web/Apache/htdocs/svn"
A. Manually create folder /svn
B. Right click INSIDE the folder
C. Tortoise SVN > Create repository here...

Step 17: Copy trac.ini into "C:/Konami/Web/Apache/htdocs/trac/conf"

Step 18: Create svn.auth for svn authentication
A. Goto Web\Apache\bin
B. htpasswd -c C:\Konami\Web\Apache\conf\svn.auth dyu
C. Enter password  x 2
D. Add the following line to "C:\WINDOWS\system32\drivers\etc\hosts"
127.0.0.2      svn.localhost
E. Add the following to "C:\Konami\Web\Apache\conf\extra\httpd-vhosts.conf
<VirtualHost 127.0.0.2>
    DocumentRoot "C:/Konami/Web/Apache/htdocs/svn"
    ServerName svn.localhost.com
    ServerAlias www.svn.localhost.com
    <Location />
        DAV svn
        SVNPath "C:/Konami/Web/Apache/htdocs/svn"
        AuthType Basic
        AuthName "Subversion Repository"
        AuthUserFile "C:\Konami\Web\Apache\conf\svn.auth"
        Require valid-user
    </Location>
</VirtualHost>

DOS: Commands

If a directory does not exist, do something:

[ -d "output/directory" ] || call dosomething.bat

If a file does not exist, do something:

[ -f "output/directory/file.name" ] || call dosomething.bat

Using DOS to clean solutions:

SET DEVENV="C:\\Program Files\\Microsoft Visual Studio 8\\Common7\\IDE\devenv.exe"
%DEVENV% "dir\to\SolutionName.sln" /clean "ConfigurationName|Win32" /project "ProjectName"

Using DOS to build solutions:

SET DEVENV="C:\\Program Files\\Microsoft Visual Studio 8\\Common7\\IDE\devenv.exe"
%DEVENV% "dir\to\SolutionName.sln" /build "ConfigurationName|Win32" /project "ProjectName"

J2ME: Installing the Motorola Launchpad 6.4

EDIT: THE REAL FIX IS THAT THE INSTALL DIRECTORY MUST BE 1 DIRECTORY BELOW C:\, (ie. C:\Motorola\<install here>)

Installing the Motorola Launchpad to "C:/Emulator/Motorola" results in the following command in the Command Line:

java -Djava.library.path=../lib
       -classpath ./Emulator.jar;./ConfigTool.jar com.mot.tools.j2me.emulator.Emulator
       -classpathC:/game.jad;../../demo;../lib;../lib/lwt.zip
       -deviceFile c:/Emulator/Motorola/Emulat~1.1/bin/Resour~1/A630~1.PRO
       javax.microedition.midlet.AppManager game.game -JSA 1 1

If you get this message, you've installed the Launchpad incorrectly. Surprisingly, the fix is install it in the default directory. You can later remove/move that installation elsewhere.

NOTE-1: After installing it in the default directory ONCE, the second installation will work correctly even if you specify where your own installation directory.

NOTE-2: If you find that your old links don't work still, you will have to alter the path of the launchpad.exe. The path must be exactly as you inputted during the installation process (case-sensitive).

J2ME: Building Projects in Sun's WTK

1.  Place  a  project  in  C:\...\WTK2X\apps

2.  You  should  have  the  following  directory  structure:
        a.  /bin  (throw  the  jad  in  here,  must  have  the  same  name  as  the  project  directory)
        b.  /res  (throw  any  resource  in  here)
        c.  /src  (throw  any  source  code  in  here)

3.  Run  C:\...\WTK2X\bin\ktoolbar.bat

4.  File  >  Open  Project

5.  Select  your  project

6.  Hit  Build

7.  Hit  Run

SVN: Setting Up Subversion Server

Install Subversion 1.4.4 (note: for Apache 2.2.4):
1. Download svn-win32-1.4.4.zip
2. Copy all contents into /Apache
3. Move mod_authz_svn.so & mod_dav_svn.so into /Apache/Modules
4. Make sure /Apache/bin is in the environment Path

Create Repository at /Apache/htdocs/svn by typing:
1. svnadmin create "C:\...\Apache\htdocs\svn"

Change the permission of the svn directory:
1. chmod -R 777 "C:\...\Apache\htdocs\svn"

Edit httpd.conf, add the following:
LoadModule dav_module modules/mod_dav.so
LoadModule dav_fs_module modules/mod_dav_fs.so
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so

Add the following to the httpd-vhosts.conf file:
<VirtualHost 127.0.0.2>
    DocumentRoot "C:/Konami/Web/Apache/htdocs/svn"
    ServerName svn.localhost.com
    ServerAlias www.svn.localhost.com
    <Location />
        DAV svn
        SVNPath "C:\...\Apache\htdocs\svn"
        AuthType Basic
        AuthName "Subversion Repository"
        AuthUserFile "C:\...\Apache\conf\svn.auth"
        Require valid-user
    </Location>
</VirtualHost>

Add user authentication file by typing:
htpasswd -c "C:\...\Apache\conf\svn.auth" username
Enter your username password twice

Restart Apache Server. Done!

SVN: Commands

checkout
svn co [src url] [dest dir]
ie. svn co http://svn.collab.net/repos/svn/trunk svn

WEB: Tutorial on Subdomains on Apache 2.2.x

Step 1: Uncomment the following in httpd.conf

#Include conf/extra/httpd-vhosts.conf

Step 2: Add the following to C:\windows\system32\drivers\etc\hosts file:

127.0.0.1 localhost
127.0.0.2 svn.localhost
127.0.0.3 mediawiki.localhost

Step 3: Add the following to the extra/httpd-vhosts.conf

NameVirtualHost *

<VirtualHost 127.0.0.1>
    DocumentRoot "C:/Konami/Web/Apache/htdocs"
    ServerName localhost.com
    ServerAlias www.localhost.com
</VirtualHost>

<VirtualHost 127.0.0.2>
    DocumentRoot "C:/Konami/Web/Apache/htdocs/svn"
    ServerName svn.localhost.com
    ServerAlias www.svn.localhost.com
</VirtualHost>

<VirtualHost 127.0.0.3>
    DocumentRoot "C:/Konami/Web/Apache/htdocs/mediawiki"
    ServerName mediawiki.localhost.com
    ServerAlias www.mediawiki.localhost.com
    <Directory "C:/Konami/Web/Apache/htdocs/mediawiki">
        Options Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
    <IfModule dir_module>
        DirectoryIndex index.php
    </IfModule>
</VirtualHost>

Step 4: You can now access the following subdomains:

http://svn.localhost
http://mediawiki.localhost

UNIX: Tutorial on chmod

In unix, you can get chmod information by typing: ls -la

This will give you a listing as such:
drwxr-xr-x 16 root root 1024 Oct 20 19:56 .
drwxr-xr-x 9 root root 1024 Sep 5 22:56 ..
drwxr-xr-x 9 foo user 1024 Sep 5 22:56 dir1
drwxr-xr-x 9 foo user 1024 Sep 5 22:56 dir2
drwxr-xr-x 9 foo user 1024 Sep 5 22:56 dir3
-rw-r--r-- 9 foo user 1024 Sep 5 22:56 file1

The drwxrxxx stuff to the left represents the item's permission, and are in groups of 3's, where:

r = read
w = write
x = execute

The group of 3 represents:

user
group
world

Since 2^3 = 8, permissions range from 000 to 777, where:

0 = No permissions
1 = Execute
2 = Write
3 = Execute & Write
4 = Read
5 = Execute & Read
6 = Read & Write
7 = Execute & Read & Write

chmod -R 755 dirname

will result in rwx r-x r-x (7-5-5) for the directory dirname

XP: Mapping Your Drives via Command Line

net use X: \\network\folder\subfolder /persistent:Yes

This will map \\network\folder\subfolder as your X drive. And this mapping will persist even after reboot.

If admin rights are required, use /USER:computer name

BREW: Debugging w/ Visual Studios

1. Compile with _DEBUG
2. Open project properties (right click, properties)
3. Go to Configuration Properties -> Linker -> Debugging

4. Set GENERATE DEBUG INFO to "Yes (/DEBUG)"

C#: Alerts (MessageBox)

MessageBox.Show("Alert String");

C#: Run external executables

Process commandLine = Process.Start(@"C:\...out.exe", @"arg1 arg2");

C#: Browsing for files

OpenFileDialog browseFileSystem = new OpenFileDialog();

browseFileSystem.InitialDirectory = @"C:\" ;
browseFileSystem.Filter = "JAD files (*.jad)|*.jad|DLL files (*.dll)|*.dll";
browseFileSystem.FilterIndex = 2 ;
browseFileSystem.RestoreDirectory = true;

if(browseFileSystem.ShowDialog() == DialogResult.OK)
{
        Selector_File.Text = browseFileSystem.FileName;
}

Re-post

I'm re-posting all of my Xanga entries here because Xanga has become impossible to navigate. Original posts will stay on Xanga in case Blogger fails. New posts will no longer be posted on Xanga... Enjoy.