ANDROID: Install apk on emulator

You can view a list of emulators via:
android list avd

Start the emulator with:
emulator -avd [emu name]

Place the apk into the android/tools directory, and install it with:
adb install [apk name].apk

Resubmit the previous command if you get this message:
* daemon not running. starting it now *
* daemon started successfully *
error: device offline

BASH: Running bash script from dos

Lets say you have something that ONLY runs in cygwin... ie. the Android NDK makefile

usually you'd call this with cygwin like so:
make APP=[app name]

instead, you could create a bash script (we'll call it _build) file that contains the following:
#!/bin/bash
make APP=$1 $2;

then call this bash script with the following:
bash _build [app name] [-B]

oh, to make sure this works, you'll have to set windows env. 'path' to include c:\cygwin\bin directory.

Android: adb shell

To manually kill a process that is running:

adb shell


In the shell, type:

ps


This will produce something like the following:

app_23 --- 19333 --- 19283 --- 840 --- 312 --- ffffffff --- com.sample.app


Kill the process with the PID:

kill 19333

Android: Dirty build JNI

*EDIT
actually the problem was the JNI shared libraries in eclipse were out of sync with the actual. To solve this issue, simply do a refresh on the entire tree.
*EDIT

I ran into a weird dirty-build bug. Where even after I rebuilt the JNI shared library, it wouldn't load my new library onto the phone.

To solve:

- delete the application from the handset (settings > applications > manage...)
- delete the bin directory
- while you're at it delete the gen directory
- close the project
- delete the project
- import the project as new

at this point you will probably see a very annoying error that states:

"gen directory is missing" fix missing paths before continuing...

- build the application
- if android glitches and doesn't remove the error messages, make sure gen/bin were created by the previous step
- close the project
- delete the project
- import the project as new (AGAIN)

this time the error message should be gone.

Regex: Eclipse Search & Replace

to convert #defines into java final vars...

#define DEFINE_VARIABLE 0x12AB

Search and replace:
#define -> public static final int
(0x[\dA-F]{4}) -> = \1;

Result:
public static final int DEFINE_VARIABLE = 0x12AB;

JNI: Getting Started

Write something simple in a java class such as below:
package com.sample;

class HelloWorld {
public native void print();
public static void main(String[] args) {
new HelloWorld().print();
}
static {
System.loadLibrary("HelloWorld");
}
}


Compile the java class

javac HelloWorld

Use javah to spit out the JNI header file

javah -jni -classpath "(path.to.src)" com.sample.HelloWorld

ANDROID: Pulling libraries from the android device

adb pull (file) (local)

for example, I pulled the system/lib to my local c:\libs

adb pull system/lib c:\libs

UNIX: Debugging the contents of a Shared Object file

If you just wanted to see basic header info (not even that preceise), then you could use the following unix command to look into a shared object ((filename).so) file.

nm (directory)\(filename).so

If this is still not working. Try appending -C -D at the end like so:

nm (directory)\(filename).so -C -D

I found this info on some google forum:
http://www.mail-archive.com/.../msg00935.html

The guy also mentioned using the following configurations:
arm-none-linux-gnueabi-nm
arm-none-linux-gnueabi-objdump

ANDROID: Starting the Android emulator

here's how to start your android emulator via command prompt:

1. if you haven't already, create an AVD (android virtual device)
android create avd -n (name) -t (targetID) [-(option) (value)]
where the target id (ie. 4 for android 1.6) can be obtained via:

android list targets

2. list available AVDs

(android.tools.directory)\android list avds

3. starting your AVD

(android.tools.directory)\emulator -avd

for more information goto:

http://developer.android.com/.../tools/avd.html

ANDROID: Installation errors

This is a part 2 to the previous post on installation.

During installation I received the following failure:

Failure [INSTALL_FAILED_INSUFFICIENT_STORAGE]

You can turn on Logcat to debug the installation failure:

adb logcat

My Logcat yielded the following errors:

E/PackageParser( 74): Package com.website.mclass has no certificates at entry assets/; ignoring!

To solve this issue, you need to sign the apk file before installing. Here's how:

jarsigner -verbose -keystore
(directory)\debug.keystore (directory)\(filename).apk androiddebugkey

The default passphrase is android

To verify the certification, you can again use jarsigner:

jarsigner -verify -verbose -certs (directory)\(filename).apk

The last command line printout should now read:

jar verified.

ANDROID: Installing application

There are 2 ways to install a pre-built applications:

1. command prompt

adb install (directory)\(filename).apk

2. SD card

A. install the apk to the phone SD card
B. insert SD card to phone
C. goto Android Marketplace, search for Apps Installer application
D. open and click Install
E. open Apps Installer
F. select the application you want to install
G. click on install

ANDROID: adb shell commands

For the times you want to log onto the unix command prompt of the device itself, you want to use the following command:

adb shell

this will convert the prompt into:

#

now you can start using unix commands as usual:

ps = list all processes
kill = kill specific process

OpenGL + OpenVG

Here's my findings on the 2 technologies:

Imagination Technologies:
--------------------------------------------
| OpenVG emulator | OpenGL ES 2.0 emulator |
--------------------------------------------
The two technologies are individually packaged, so there is no support for combining these 2 technologies at this time by imgtec.

AMD:
--------------------------
| OpenGL ES 2.0 emulator |
--------------------------
AMD does not have a OpenVG emulator


So... Theoretically the 2 technologies can only be combined if the following is satisfied: A single emulator/device, that supports BOTH OpenVG and OpenGL, sharing the same EGL libraries. In other words, the EGL must have support for BOTH OpenVG and OpenGL ES 2.0. The EGL is the key.

-----------------------------------
| GL ES 2.0 | VG |
| ----------- |
| | | |
| | E G L | |
-----------------------------------

OpenGL: What is EGL

Taken from Khronos: http://www.khronos.org/egl/

EGL™ is an interface between Khronos rendering APIs such as OpenGL ES or OpenVG and the underlying native platform window system. It handles graphics context management, surface/buffer binding, and rendering synchronization and enables high-performance, accelerated, mixed-mode 2D and 3D rendering using other Khronos APIs.

OpenGL: Toggling the DepthMask

glDepthMask(GL_TRUE/GL_FALSE);

Sometimes in blending, you will want to inter-mix opaque & translucent objects.

Here's the 2 obvious scenarios:
1. If the opaque object is in front of translucent object, we don't need to blend
2. If the translucent object is in front of the opaque object, we need to blend

There's a easy way to ensure the blending always works as expected. This is to render the opaque object FIRST with the writable depth buffer. And then render the translucent object with a read-only depth buffer. This can be done by using glDepthMask.

This way the renderer will automatically compare the translucent object's depth position with that of the read-only opaque object depth position. Blending is done only when needed, and buffer remains unchanged.

OpenGL: Blending Formula

Taken from the Red Book:

Let the source and destination blending factors be (Sr, Sg, Sb, Sa) and (Dr, Dg, Db, Da), respectively, and the RGBA values of the source and destination be indicated with a subscript of s or d. Then the final, blended RGBA values are given by

(RsSr+RdDr, GsSg+GdDg, BsSb+BdDb, AsSa+AdDa)


Expanded:

red = Red(src)*Red(srcBlendFactor) +
Red(dest)*Red(destBlendFactor)
green = Green(src)*Green(srcBlendFactor) +
Green(dest)*Green(destBlendFactor)
blue = Blue(src)*Blue(srcBlendFactor) +
Blue(dest)*Blue(destBlendFactor)
alpha = Alpha(src)*Alpha(srcBlendFactor) +
Alpha(dest)*Alpha(destBlendFactor)

OpenGL: Rendering Pipelines

Here's 2 flow-charts explaining the 2 types of rendering pipelines.



Here are some typical uses for the programmable function pipeline:

Done within the Vertex stage:
- vertex displacement mapping
- morphing
- particle systems

Done within the Pixel stage:
- per pixel lighting
- toon shading (I'm guessing this is cell-shading)
- parallax mapping
- bump mapping
- custom texture filtering
- color kernel applications

OpenGL: Blending

Here's are 2 tabular guides on blending effects:



Win32: Setting up OpenVG

I'm completely new to the OpenVG sphere, so this is the very basic of basics. How to run the openVG RI from Khronos site...

First, I downloaded the RI from the site at: http://www.khronos.org/files/openvg_1_0_ri

Unzip the package, and attempt to run the bin\wind32\tiger.exe file

If you got a MSVCRTD.dll is missing, this is because you aren't using Visual Studio 6 (or some other prehistoric version).

I don't recommend this, but you CAN find MSVCRTD.dll online, and throw it into your System32 directory. I found the dll inside some symbian directory... threw it in my System32 directory, and the tiger popped up like a charm... after 2 minutes of loading...

The second, and preferred method, is to recompile the project using your version of Visual Studio (mine is V9). Well I got stumped again when I tried compiling. The application couldn't find GL\glext.h

To solve this download the glext.h from: http://www.opengl.org/resources/faq/technical/extensions.htm

Throw this file inside the VC/include/GL folder (create the GL directory if it doesn't already exist).

The full path of said directory is at (for Visual Studio V9):
C:\Program Files\Microsoft Visual Studio 9.0\VC\include\GL

Inside this directory I now have the following:
- glut.h
- glext.h
- glxext.h
- wglext.h

If you also need glut.h, you should refer to an earlier post I wrote about setting up GLUT on your system.

3D: Shaders

did some research on shaders:

FROM: http://en.wikipedia.org/wiki/Shader
A shader is a set of software instructions, which is used to calculate rendering effects on GPU. Shaders can program the GPU's programmable rendering pipeline (as opposed to Fixed Function Pipeline, or FFP). Shaders replaces the FFP.

Shaders help determine the traits of a vertex or pixel. There are 3 types of shaders:
1. Vertex shaders: these are run once per vertex. manipulates position, color and tex-coordinates of vertices.
2. Geometry shaders: can add or remove vertices from a mesh (caused by plane-clipping, etc).
3. Pixel/fragment shaders: determines trait of a single pixel (color, z, alpha). typically used in scene lighting, bump-mapping, color toning.

Programming shaders can be done in the following 3D languages: OpenGL, DirectX.
1. DirectX for ATI uses HLSL (high level shader language)
2. DirectX for NVidia uses Cg (C for graphics, very similar to HLSL)
3. OpenGL uses GLSL (OpenGL Shading Language)

IPHONE: User-defined constructor/destructor

This is actually the second time I've come across this issue. Unfortunately I did not post the solution last time, so I had to go look it up again...

The WARNING:
type 'SomeClassType' has a user-defined constructor
tyep 'SomeClassType' has a user-defined destructor

The SOLUTION:
convert object declarations into pointer declarations. for example:
@interface myclass {
@private
SomeClassType myInstance;
}

change to:
@interface myclass {
@private
SomeClassType* myInstancePtr;
}

Of course, this also means you will have to manually control the instantiation & destruction of the object with new & free.

ANDROID: logcat on device

Here's another gripe. When you have both the emulator & device running, the adb logcat doesn't know which to listen to, and as a result outputs NOTHING.

to solve you'd simply close the emulator or device, whichever you aren't currently using.

also, as an added bonus, I found out how to cue up logcat via command prompt:

adb logcat -s DEVICE_NAME

ANDROID: Cannot create linked resource...

Here's the second error today. While attempting to import the Android project, or attempting to create a new Android project, I kept getting the error:

Cannot create linked resource '/.org.eclipse.jdt.core.external.folders/.link0'. The parent resource is not accessible.

Solution:
Unfortunately, this means it's time to ditch your workspace and create a new one... save your preferences (esp your key bindings), and move your Eclipse workspace to a new location. This should fix the issue.

Other solutions I've found online:
- Reinstalling Eclipse (overkill)
- Reinstalling Android SDK (probably won't help)
- eclipse.exe -clean (doesn't clean the workspace)

Nevertheless, you should try the -clean method, just in case it works for you.


ANDROID: Could not find *.apk!

SEVERAL very annoying errors popped up today as I was dev-ing for Android. This post describes & solves the first of these errors.

Description of Error:
While attempting to build the android project the following message will pop up in the Console

[2009-11-02 16:28:51 - AndroidGL]Android Launch!
[2009-11-02 16:28:51 - AndroidGL]adb is running normally.
[2009-11-02 16:28:51 - AndroidGL]Could not find ********.apk!

Solution:
Make sure your project imported the Android 1.6 library correctly. That is, under your project, you should see 'Android 1.6', which expands and displays 'android.jar'.

If it says Referenced Libraries > android.jar, you will need to fix this by manually altering the .classpath for the project.

Open .classpath for the project and type the following:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<kind="src" path="src">
<kind="src" path="gen">
<kind="con" path="com.android.ide.eclipse.adt.
ANDROID_FRAMEWORK">
<kind="output" path="bin">
</classpath>

The important line is the 3rd classpathentry, which is the actual link to the Android SDK libraries.

glFrustum vs PerspectiveFovRH

I was a bit stumped when I stumbled into PowerVR's iPhone SDK for OGL ES 1.1. namely, I wasn't sure what PerspectiveFovRH was for... I messed around with the numbers a little, and discovered the relationship between PerspectiveFovRH and the usual glFrustum method:

glFrustum(frustumLeft, frustumRight, frustumBottom, frustumTop, frustumNear, frustumFar)

is the same as:

float fovy = 2 * atanf( (frustumTop - frustumBottom) / (2 * frustumNear) );
PerspectiveFovRH(fovy, 320/480, frustumNear, frustumFar, OGL, false);

COCOA: OpenGL View

I tried to render a box in OpenGL, and for some strange reason, the depth test wasn't working at all. Finally I googled the problem, and found out it was caused by the Interface Builder... this is why I avoid IB when developing...

Here's what the screen-capture looked like, even though I had enabled GL_DEPTH_TEST



basically you have to set the depth bit of the OpenGLView to be > 0 bit (which is default!?). While I was at it, I also changed the color to 32bit.

Win32: Setting up OpenGL's GLUT

it's been a very long time since my previous posts. i had to recently install opengl on my windows xp environment, and found there were actually very little documentation on this subject. so here's a tutorial to getting things started in opengl & glut.

CHECK FOR OpenGL:

1. when you install visual studios, you should already have the following libraries and DLLs:
- OpenGL32.lib (in C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib, etc)
- GLU32.lib (in C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib, etc)
2. make sure you see the following dll's in C:\Windows\System32
- OpenGL32.dll
- GLU32.dll

BUILD & INSTALL GLUT:

1. goto http://www.opengl.org/resources/libraries/glut/glut_downloads.php
- i downloaded 3.7.6 from http://www.xmission.com/~nate/glut.html
- download glut-3.7.6-src.zip
2. unzip glut-3.7.6/ directory onto the desktop
3. open glut.dsw
4. build the glut32 project

if you have visual studios 6, you should be fine. however, if you have visual studio 9.0 like me, you'll end up with an error during file copy, so you have to do some manual copying and pasting...

1. inside the [[DESKTOP]]/glut-3.7.6/ directory navigate to:
- [[DESKTOP]]/glut-3.7.6/lib/glut/Debug
2. copy glut32.dll into C:\Windows\System32
3. Copy glut32.lib into C:\Program Files\Microsoft Visual Studio 9.0\VC\lib
4. Copy [[DESKTOP]]/glut-3.7.6/include/GL/glut.h to C:\Program Files\Microsoft Visual Studio 9.0\VC\include\GL\glut.h

after this you should be able to start compiling the samples from the OpenGL red book.

WINDOWS: Registry

To add something to the RIGHT CLICK context menu, we can change the registry.

In my particular instance, I am looking to add a QUICK COMMAND that will run the JAD file in MPowerPlayer.

1. Goto: My Computer > HKEY_CLASSES_ROOT > jadfile
2. Expand jadfile > shell, and add a key "Run with MPowerPlayer"
3. Add a key under "Run with MPowerPlayer" called "command"
4. On the right, double click (Default), add the following data: java -jar C:\\mpowerplayer\\player.jar "%1"

That's all. Now right click on the JAD file and you should see your new command "Run with MPowerPlayer.

NOTE: you will want to change the directory location of mpowerplayer\player.jar to match your own.

Here's the entire structure after you are done (added 'Edit' command for comparison):

My Computer
----L HKEY_CLASSES_ROOT
---------L jadfile
--------------L shell
------------------L Run with MPowerPlayer
-----------------------L command = java -jar ... (see above)
------------------L Edit
-----------------------L command = notepad.exe "%1"

IPHONE: Saving data on exit

Totatlly forgot how to do this, so I had to look it up...

Use the following methods to catch application exit notifications:
- (void)applicationWillTerminate:(UIApplication *)application

Use this method to catch application interrupt notification:
- (void)applicationWillResignActive:(UIApplication *)application

Use this method to catch application resume notification:
- (void)applicationDidBecomeActive:(UIApplication *)application

Grep recursive search

find . | xargs grep -s "text to grep"

POSTGRESQL: Removing POSTGRESQL

The following manual uninstallation guide was grabbed from 2 separate sites. One is for removing 8.3, and the other for removing 8.4.

In Mac OSX: (Assuming Default Locations)

Via uninstaller:

1) In the installation directory, there will be a uninstall-postgresql.app file will be there, executing (double clicking) that will uninstall the postgresql installation.

Manual Uninstallation:

1) Stop the server
sudo /sbin/SystemStarter stop postgresql-8.3

sudo launchctl unload /Library/LaunchDaemons/com.edb.launchd.postgresql-
8.4.plist

2) Remove menu shortcuts
sudo rm -rf /Applications/PostgreSQL/8.3
sudo rm -rf /Applications/PostgreSQL/8.4

3) Remove the ini file
sudo rm -rf /etc/postgres-reg.ini
sudo rm -f /etc/postgres-reg.ini

4) Removing startup items
sudo rm -rf /Library/StartupItems/postgresql-8.3
sudo rm -f /Library/LaunchDaemons/com.edb.launchd.postgresql-8.4.plist

5) Remove the data and installed files
sudo rm -rf /Library/PostgreSQL/8.3
sudo rm -rf /Library/PostgreSQL/8.4

6) Delete the user postgres
sudo dscl . delete /Users/postgres

SYMBIAN: NewLC vs. NewL

It all has to do with the way you implement NewLC and NewL, but the STANDARD difference between NewLC and NewL is whether or not you have to CleanupStack->pop the object created.

Let's first start with the typical implementation of NewL and NewLC

static CObject* newL();
CObject* CObject::NewL() {
----CObject* self = NewLC();
----CleanupStack::Pop(self);
----return self;
}

static CObject* newLC();
CObject* CObject::NewLC() {
----CObject* self = new (ELeave)CObject();
----CleanupStack::PushL(self);
----self->Construct();
----return self;
}


As such, you would instantiate a CObject by using either of the following:

CObject* obj = CObject::NewL();


or

CObject* obj = CObject::NewLC();
// do something with obj that may require cleanup ie. cptrArray->AppendL(obj);
CleanupStack::Pop(obj);


If you do not pop the object, the stack will be messed up and you'll have a very difficult time figuring out why that is.

C++: CONST CAST

Spent about 20 minutes trying to figure out why this wasn't compiling.

void CImageLoader::LoadImageL(const TDesC& filename) {
----TDesC* tmp = &filename; // COMPILER ERROR
}


It's because filename is CONST. So we'll have to 'unconst' it for this line to work:

TDesC* tmp = &(const_cast(filename));

OPENGL ES: Basics

Here's how I usually set up my quads:

Coordinates
D C
A B

Vertices
A B
D C

Here's are the coordinates:
vertices = {-1, 1, 1, 1, 1, 1, 1, -1, 1, -1, 1, 1};
coords = {TEX(0, 0), TEX(255, 0), TEX(255, 255), TEX(0, 255)}; // assumes 256x256 texture image
normal = {0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1};
triangles = {1, 0, 3, 1, 3, 2};

Where TEX(u,v) is defined as (GLbyte)( (u) - 128 ) , (GLbyte)( (v) - 128 )

Draw code

glMatrixMode(GL_MODELVIEW);

glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_BYTE, 0, vertices);

glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_BYTE, 0, coordinates);

glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_BYTE, 0, normals);

glBindTexture(GL_TEXTURE_2D, textureID);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glDrawElements(GL_TRIANGLES, 2 * 3, GL_UNSIGNED_BYTE, triangles);

OS X: Splitting & Joining large files

Took me a VERY long time to figure this out, but...

Problem: Files over 4GB cannot be dragged onto your external HDD if the external HDD is using FAT32 file-system.

Solution: Split the file up using terminal into chunks smaller than 4GB and transfer as usual. You can use terminal to join the file up again at a later time.

To split the file up into 1GB chunks:
split -b 1024m filename.file PREFIX_

To join the file from the separated chunks:
cat sub1 sub2 sub3 sub4 > output.file

I read somewhere the older macs cannot handle splits larger than 2047mb. This is not true on my mac because I just made chunks that are 3gb FTW.

MYSQL: Installing MySQL 4.1.22 on OS X 10.5

1. to remove MySQL 5.0, see previous post.
2. download the MySQL 4.1.22 installer from MySQL website.
3. install mysql-standard-4.1.22...i686.pkg
4. install mysqlStartupItem.pkg
5. set up MySQL config. In command prompt type:
sudo pico /etc/my.cnf

6. paste the following 4 lines into pico:
[mysqld]
default-character-set=utf8
[client]
default-character-set=utf8

7. exit pico & save file (ctrl+x, Yes for save)
8. now we can start the MySQL server using sudo:
sudo /Library/StartupItems/MySQLCOM/MySQLCOM start

9. open up command prompt, and enter mysql by typing:
/usr/local/mysql/bin/mysql -u root



EDIT: Getting it to work with OSX's installation of PHP...
Only follow the following instructions if you are having problems with the @mysql_connect method in PHP.

1. create a info.php file that calls the phpinfo(); method
----- NOTE: my version of PHP is 5.2.8
----- scroll down to the mysql section, and look for the value for key: MYSQL_SOCKET
----- MYSQL_SOCKET = /var/mysql/mysql.sock
----- goto /var/mysql and make sure mysql.sock... if the directory is missing or file is missing, you have the same problem I did. Your mysql.sock is probably inside /private/tmp...

2. in command prompt, type the following:
sudo mkdir /var/mysql
sudo chown _mysql /var/mysql

3. (OPTIONAL) in command prompt, type the following:
cp /private/tmp/mysql.sock /var/mysql/mysql.sock

4. edit the my.cnf file again, this time make sure its whole contents are the following 6 lines:
[client]
default-character-set=utf8
socket = /var/mysql/mysql.sock
[mysqld]
default-character-set=utf8
socket = /var/mysql/mysql.sock

5. restart the apache service through System Preferences > Sharing > Web Sharing

6. restart the MySQL service by typing the following 2 lines (one at a time) into command prompt:
sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop
sudo /Library/StartupItems/MySQLCOM/MySQLCOM start

At this point the mysql_connect() php method should work as expected...

MYSQL: Removing MYSQL from a mac

Do the following in the terminal:

1. sudo rm /usr/local/mysql
2. sudo rm -rf /usr/local/mysql*
3. sudo rm -rf /Library/StartupItems/MySQLCOM
4. sudo rm -rf /Library/PerformancePanes/My*
5. (Edit /etc/hostconfig) sudo vi /etc/hostconfig (Remove line MYSQLCOM=-YES)
6. sudo rm -rf /Library/Reciepts/mysql*
7. sudo rm -rf /Library/Reciepts/MySQL*

SQL: MySQL + USERS + MAC

when installing mysql for the very first time, you will need to create a root password in order to enter the mysql database:

mysqladmin -u ROOT_USER_NAME -p ROOT_PASSWORD

sign into mysql using the following command:

mysql --user=ROOT_USER_NAME --password=ROOT_PASSWORD

once in, you want to first navigate to the mysql database:

use mysql;

you can now insert more users to your liking by using the following commands:

create user 'SUB_USER_NAME'@'LOCALHOST';

set that person's password by using:

set password for 'SUB_USER_NAME'@'LOCALHOST' = PASSWORD('SUB_USER_PASSWORD');

now to give all permissions for the new user...

grant all privileges on *.* to 'SUB_USER_NAME'@'LOCALHOST' IDENTIFIED BY 'SUB_USER_PASSWORD' WITH GRANT OPTION;

or if you want to just grant certain privileges (in this case, SELECT):

grant SELECT on *.* to 'SUB_USER_NAME'@'LOCALHOST' IDENTIFIED BY 'SUB_USER_PASSWORD';

if you made a mistake, you can revoke the privileges by doing this:

revoke all privileges, grant option from 'SUB_USER_NAME'@'LOCALHOST';

NOTE:
1. *.* means you are granting permission to SELECT on all databases. Alternatively you could also specify a specific database, ie. mysql.user
2. GRANT OPTION is a special command that allows the SUB_USER to grant that same permission to other users

IPHONE: NSXMLParser leak NSPlaceholderString

This is probably the most annoying leak I've every faced. With the NSXMLParser, I was getting these crazy 16 byte NSCFString leaks. The leaks traced back to [NSXMLParser parse], caused by NSPlaceholderString initWithBytes/initWithString.

I believe this is caused by the [parser:foundcharacters] method. Generally, the xml document being parsed has a bunch of \t and \n characters. It would appear these are the culprit. I got rid of the parse leaks by doing the following:

- (void)parser:(NSXMLParser*)parser foundCharacters:(NSString*)cdata {
NSString* tmp = [cdata stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if(curr && tmp && [tmp length] > 0) {
curr.content:tmp;
}
}

Where curr is the variable saving the cdata 'found characters'.

Eclipse: Eclipse bin and .svn directories

Eclipse tends to like picking up .svn folders and throwing them into the /bin directory. For me, this defeats the purpose of doing a svn-ignore on the /bin directory. To prevent this from happening:

Configure Build Path > Source tab, under each SOURCE (or resource) directory, set the following excludes:

.svn
**/.svn/**

Clean & rebuild

XP: Map local directory as a drive

type in command prompt:

subst :

example:
subst e: c:\mpowerplayer\hdd

you should now see a e:\ volume in windows explorer.

UNIX: Find command

Common uses for the FIND command.

1. find all hidden .svn folders and delete them

find /path/to/search -name '.svn' -type d -exec rm -rf '{}' \;

2. find all hidden .svn folders and print them

find /path/to/search -name '.svn' -type d -print

SVN: Subversion Server + MAC

This tutorial assumes that you have already installed the SVN binaries, and modified your PATH to the svn/bin.

Step 1: Creating a local repo

svnadmin create /path/to/repo

Step 2: Change the default configurations, svnserve.conf

[general]
anon-access = none
auth-access = write
authz-db = authz
password-db = passwd
realm = Subversion Server

Step 3: Edit the authz file

[groups]
admin = alex, bob, cathy
engineers = donny, emily
producers = frank
visitors = greg

[/]
* =
@admin = rw
@engineers = rw
@producers = rw
@visitors = r

Step 4: Edit the passwd file

[users]
alex = pw1
bob = pw2
cathy = pw3 (... and so forth)

Step 5: Chmod the entire repo directory

cd /path/to
find repo -exec chmod 777 '{}' \;

Step 6: Start the svn server

svnserve -d -r /path/to/repo

Step 7: Do a sample checkout

svn co svn://localhost /download/path --username bob --password pw2

Hopefully it works :) Oh yea, and to restart the server, you can use the command killall svnserve

MySQL on OS X

Download MySQL at: http://dev.mysql.com/downloads/ (More Specific) & install the DMG

1. Open up Terminal

2. Add /usr/local/mysql/bin to PATH
- cd ~
- emacs .profile
- export PATH="$PATH:/usr/local/mysql/bin"

3. Restart Terminal

4. Create new user for login
- mysqladmin -u USERNAME -p -password PASSWORD

5. Log in to MySQL with new user created
- mysql --user=USERNAME --password=PASSWORD

You should be in MySQL now

SERVER: FSB vs. RAM

Taken from: http://www.directron.com/fsbguide.html

Front Side Bus (FSB)
- The Front Side Bus is the most important bus to consider when you are talking about the performance of a computer. The FSB connects the processor (CPU) in your computer to the system memory. The faster the FSB is, the faster you can get data to your processor.

S
ystem clock - The actual speed of your FSB with out any enhancements (such as double pumping, or quad pumping) on it.
An often-misunderstood property of the system clock is its effect on processor speed. You see, a thing called a "CPU Multiplier" determines the speed of a processor in MHz. If you take the CPU Multiplier and multiply it by the System Clock speed you get the speed of your processor.

DDR2 -
DDR2 memory has a different approach to design at the chip level than DDR. The simplest way to understand how it works would be to think that at the low level it had two chips of half the stated memory speed working in tandem together to achieve the full speed stated. So for DDR2 400 it would be something like 2 chips of DDR200 working together to achieve the full 400 speed. Notice that I say "chips" not sticks of memory. All this happens on 1 stick of memory. In other words, when calculating in tandem in respect to the FSB, just divide the given speed by 2.

Example:
Assume my quad-core, quad-pumped FSB = 1066MHz.
This means my System Clock is 1066/4 = 266MHz.
My CPU is clocked at 1.6GHz = 266MHz * CPU MULTIPLIER.
This means my CPU MULTIPLIER must be 1600/266 = 6.

Now here are my options for DDR2:
(A) 533MHz/2 = 266MHz. This is an EXACT MATCH to my System Clock.
(B) 667MHz/2 = 333MHz. This is the next highest speed available.
(C) 800MHz/2 = 400MHz. This is pure overkill since the System Clock is capped at 266MHz.

In these stated cases, (B) is actually preferred. (A) is an exact match which means sometimes its lag can adversely affect the CPU bus speed. As stated, option (C) is overkill.

WEB: How to set up web-server w/ FiOS

Since Verizon blocks port 80, this is listed online as the only workaround. It entails targeting a different port (like 8015), and then using the Verizon FiOS router to re-route the request to the correct web server machine.

Furthermore, people used no-ip.com's dynamic dns service to automatically forward the url name requests like www.happy.com to www.happy.com:8015, thereby eliminating the ugliness of forcing your customers to specify the ports.

* Prior to following the steps in this guide to hosting your web server, make sure you read the Verizon ToS, which states the following:

You also may not exceed the bandwidth usage limitations that Verizon may establish from time to time for the Service, or use the Service to host any type of server. Violation of this section may result in bandwidth restrictions on your Service or suspension or termination of your Service.

That said, be careful and charging on :)

STEP 1: Goto URL http://192.168.1.1
STEP 2: By default, username = admin, password = password (or password1)



STEP 3: On the top navi-bar, select Firewall Settings



STEP 4: Click yes to proceed



STEP 5: Click on Port Forwarding on the left navi-bar



STEP 6: From that table list, click Add at the bottom



STEP 7: Fill out the following table...
STEP 7a: Networked Computer/Device = danny (actual device name works best, since IPs can be dynamic)



STEP 8: Add new protocol



STEP 9: WAN Connection Type: All Broadband Devices
STEP 10: Forward to Port: Specify - 80
STEP 11: When should this rule occur: Always

STEP 12: Click Apply to get out of the Edit Port Forwarding Rule page
STEP 13: Click Apply to get out of the Port Forwarding page

STEP 14: From an external computer, type http://YOUR.IP:8015/, should direct you to the web server.

APACHE: Enabling Apache + PHP on OSX

Step 1. Menu Bar > Go > Go to Folder... > /private/etc/apache2

Step 2. Open httpd.conf with TextEditor

Step 3. Uncomment this line:
#LoadModule php5_module libexec/apache2/libphp5.so

Step 4. Save this file onto the desktop as "httpd.conf"

Step 5. Drag the "httpd.conf" file you just created into /private/etc/apache2

Step 6. Authenticate your privileges: enter your password

Step 7. Make a copy of /etc/php.ini.default onto your desktop

Step 8. Rename php.ini.default to php.ini (the copy on your desktop)

Step 9. Drag the "php.ini.default" file you just created into /private/etc

Step 10. Authenticate your privileges: enter your password

Step 11. Open System Preferences > Sharing > Web Sharing: ON (check this option)

To Test:

Step 12. Create info.php with the content:

Step 13. Save it to /Library/WebServer/Documents

Step 14. Goto http://localhost/info.php

To Publish using your HOME/Sites directory

Step 15. Create info.php with content:

Step 16. Save it to /Users/$MYNAME/Sites

Step 17. Goto http://$COMPUTERNAME.home/~$MYNAME/info.php

IPHONE: MySQL on iPhone

Before we go on, I'm going to assume you already know that the simplest way to achieve MySQL data connection is by writing a short scriptlet in PHP/JSP, etc. While simpler, it's security is somewhat problematic, since sniffers may be able to pick up the URL requests.

After hours of research I found what seems like the only solution: Cocoa-MySQL + MySQL C-API

According to this blog, all you seem to need is Cocoa-MySQL, but no matter what I tried, I just couldn't seem to get the binaries to link correctly. Not to mention, Apple has a pretty strict limitation on private frameworks, and this solution probably goes against one of their 20 NDAs.

This is where MySQL C-API comes in handy. I downloaded Mac OS X 10.5 (TAR package) for my x86 Intel system. Extract the zip and grab the /lib and /include folders and throw them into some local directory (NOT IN YOUR XCODEPROJ, see steps 4, 5 below).

From the Cocoa-MySQL site, download MCPKit_src_XXX.dmg, and grab the contents of /MCPFoundationKit and throw it into your XCODEPROJ. These are great wrapper classes that help facilitate the connection & query processes.

If you tried to build the app right now, you'd get errors stating missing headers and mysql_xxx_xxx functions. That's because we haven't set up the project settings yet.

1. In Xcode, goto Project > Edit Project Settings.
2. Select the Build tab.
3. Under Linking > Other Linking FLags, add the following flags: -lmysqlclient_r, -lmysqld, -lmysqlclient, -lm, -lz
4. Under Search Paths > Header Search Paths:
5. Under Search Paths > Library Search Paths:
6. Add #import "MCPKit_bundled.h" to the header of any class accessing MySQL
7. Edit MCPKit_bundled.h by changing all #import to #import "XXX.h"

Now you should be able to build, and use the sample code from the blog previously mentioned to directly connect to a remote MySQL server.

IPHONE: IBAction and IBOutlet

Sometimes when all you need is a simple UI application that doesn't require too much customization or skinning, you can try building the application in Interface Builder.

Step 1: Create a New Project (Apple+Shift+N) > View-Based Application, name the application IBTest



Step 2: Edit the default IBTestViewController.h & .m files. Add the following lines in the appropriate places:

IBOutlet UIButton* button; IBOutlet UILabel* label; - (IBAction)userPressedButton:(id)sender;



Step 3: Open MainWindow.xib w/ Interface Builder

Step 4: Double-Click Test View Controller and a window will pop up



Step 5a: Add a View (from the library: APPLE+L) to Test View Controller
Step 5b: Add a Rounded Rect Button to the View you just added
Step 5c: Add a Label to the View you just added


Step 6: Link your UIButton & UILabel to the button and label you just added. You can do this by Apple+Right-Clicking the Rounded Rect Button & drag your mouse onto the Test View Controller



Step 7: Select userPressedButton in the popup


Done... your code is now hooked up through the interface builder. When users click the button, your userPressedButtons method will fire, as expected.

IPHONE: Removing the GLOSS from the app icon

Edit the Info.plist file...

UIPrerenderedIcon = true

In plain text:

UIPrerenderedIcon

IPHONE: Changing the Product Name

If your single source produces multiple 'products', ie. *.app's, it may be necessary to differentiate the 2 by designating the product names.

To create 2 products from 1 source:
- Create a new target by making a copy of the first.
- Modify this target by changing its Info.plist (by default will be Info Copy.plist)
- Modify its displayed name by changing its Infoplist.strings
- Optionally you can add a PREPROCCESSOR MACRO to differentiate the 2 targets (see previous post)

But when you compile the 2 targets, they always have the same .app name. This could be problematic for multiple reasons...
- If your bundle identifier is com.xxx.Application, your Product name should be 'Application'
- If you want to differentiate the 2 builds, it'd be easier if the 2 did not have the same app name

To do so:
- Highlight the Targets > Application 1
- Right click > Get Info
- Build tab
- Packaging > Product Name = New Application name

IPHONE: Environment Variables & #define directives

To use Configuration-defined #defines

Step 1: Right click on the project/target and select Get Info.

Step 2: Under the Build tab, select the Configuration you want to associate the #define with (ie. Debug/Release)

Step 3: Under User-Defined (Setting) all the way at the bottom, find a field that's called

GCC_PREPROCESSOR_DEFINITIONS

Step 4: If a field doesn't already exist, create it by clicking on the Gear on the bottom left & selecting Add User-Defined Setting.

Step 5: For the VALUE, input your #define variable. (ie. TEST_DEFINES)

Step 6: Now in code you can use

#ifdef TEST_DEFINES
... do something
#else
... do something
#endif