InnoDB status, altering table by dropping foreign key column

So if you have a table, say Kinerja, that has a foreign key column, say NIP. And you need to alter that table by dropping the column, you can't just do:

alter table Kinerja drop column NIP;

It will spit errno 150 at ya.

You need to first drop the foreign key constraint pertinent to the said column, such as:

alter table Kinerja drop foreign key the_constraint_of_NIP_column_here;

After that is done, you can do:

alter table Kinerja drop column NIP;

But how to get the constraint? Well, just do:

alter table Kinerja drop column NIP;

first to get error. And then, look up the innoDB log by issuing:

show engine innoDB status;

In the log, find this paragraph:


------------------------
LATEST FOREIGN KEY ERROR
------------------------
121211  0:16:23 Error in foreign key constraint of table penilaian/kinerja:
there is no index in the table which would contain
the columns as the first columns, or the data types in the
table do not match the ones in the referenced table
or one of the ON ... SET NULL columns is declared NOT NULL. Constraint:
,
  CONSTRAINT "kinerja_ibfk_2" FOREIGN KEY ("NIP") REFERENCES "dosen" ("NIP")


There, you have the constraint! :p

Then, do delete the constraint and then the column.

Playing video with cocos2d


  1. Download cocos2d extension from: https://github.com/cocos2d/cocos2d-iphone-extensions
  2. Unzip, navigate into the directory: extensions -> CCVideoPlayer.
  3. Copy file CCVideoPlayer.h and CCVideoPlayer.m and the folder iOS. 
  4. Insert them anywhere in the project.
  5. In CCVideoPlayer.m, comment out the line #import "CCVideoPlayerImplMac.h"
  6. Done! To play video, simply do: [CCVideoPlayer playMovieWithFile:@"filename.mp4"]
  7. You can set a delegate to the CCVideoPlayer by implementing protocol: <CCVideoPlayerDelegate>
  8. The protocol will call method: 
    -(void) movieStartsPlaying
    when the movie starts
    and
    -(void) moviePlaybackFinished
    when the movie finishes.

Find the total force when two fixtures collide

contact->GetManifold().localPoint.Length()

Remove CCNode from parent after a sequence of actions

P.S:
Well, P here stands for Pre instead of Post, I guess. The following cocos2d discussion was started 3 years ago. Now I realize that there is a method: [CCNode removeFromParent]

So a useful post from cocos2d forum: http://www.cocos2d-iphone.org/forum/topic/981



I have some sprites and labels on the Layer. Before removing them they must do some actions (fade out for example). But after that I need to remove them from the layer with using [self removeChild:child cleanup:YES]. For that I create classes AutoCleaningSprite and AutoCleaningLabel which inherit Sprite and Label class and have new method:
- (void) removeFromParent{
CocosNode *parent=self.parent;
[parent removeChild:self cleanup:YES];
}
So for removing this objects after animation I used next actions:
[someAutoCleaningSprite runAction:
[Sequence actions:[FadeOut actionWithDuration:0.5],
[CallFunc actionWithTarget:someAutoCleaningSprite selector:@selector(removeFromParent)],nil]];
Is it correct method? Or may be there is something more simple way for removing CocosNode objects from the parent Object?
And I have another question - is it need to invoke [sprite release]; after [self removeChild:sprite cleanup:YES];?
Thanks..
Answer:


re:
(void) removeFromParent{
CocosNode *parent=self.parent;
[parent removeChild:self cleanup:YES];
}
This strategy will work and I've found it very useful on my projects but one thing anyone who tries it needs to be aware of is a really really really evil memory bug that gets caused unless your careful. First off, the solution:
CocosNode *parent=self.parent;
[self retain];
[parent removeChild:self cleanup:YES];
[self autorelease];
Huge hack I know, and there are cleaner ways to do this but what happens if you don't is total heisenbuggery. Background:
- The NSInvocation object associated with the CallFunc action wants to write a 'return value' to an address in the NSInvocation object ... even if your function doesn't return anything.
- When you call removeChild:self cleanup:YES your sprites ref count goes down by one
- If your sprites ref count just hit zero (as it probably will), instead of being released 'at some time in the future' its going to get deallocated NOW. Thank apple for that little bit of magic they do when removing objects from NSArrays
- That deallocation cascades to the Action and then the NSInvocation all before your function returns.
If you've got anything else going on (other threads for instance that may be allocating something ... I'm looking at you OpenFeint) the NSInvocation return is about to write on some memory that no longer belongs to it ... and you will likely not find out about it until way past too late ;)

Check whether a string contains substring.

Turns out that the Foundation Framework does not have this nifty little utility to check whether a string contains a substring. But this can be easily done manually:


-(BOOL)string:(NSString*)string1 containsString:(NSString*)string2{
    NSRange rangeValue = [string1 rangeOfString:string2 options:NSCaseInsensitiveSearch];
    if (rangeValue.length > 0){
        return TRUE;
    }
    else {
        return FALSE;
    }
}

Manual OpenGL draw on CCNode

Every point must be multiplied by     CC_CONTENT_SCALE_FACTOR();

Otherwise, the drawing will not be correctly placed on the screen!