March 6, 2013, 7:10 pm
Some basic iOS copy/paste sample code:
#import "UIPasteboard.h"
void iphone_copy(char *text) {
UIPasteboard *pb = [UIPasteboard generalPasteboard];
NSString *nstext = [NSString stringWithCString:text encoding:NSUTF8StringEncoding];
[pb setValue:nstext forPasteboardType:@"public.plain-text"];
}
const char *iphone_paste() {
UIPasteboard *pb = [UIPasteboard generalPasteboard];
NSString *nstext = [pb valueForPasteboardType:@"public.utf8-plain-text"];
return [nstext cStringUsingEncoding:NSUTF8StringEncoding];
}
March 4, 2013, 2:32 pm
I’m using AWS (EC2) for a lot of my work at the moment, I generally run things out of a microinstance, however sometimes I need to scaleup to a larger system to run something computationally intensive. I’m using debian, and this is the script I’m currently using to do this. You’ll need to setup euca-tools, and have .eucarc files for the regions you want to use, but this might help point you in the right direction:
#!/bin/bash
# Region select
REGION=EU
echo $REGION
#for new regions you need to:
#euca-add-keypair keypair_for_regular_debian_machine > keypair_private_$REGION.asc_complete
#chmod 0600 keypair_private_$REGION.asc_complete
cd ~
cp .eucarc_eu .eucarc
# start instance
if [ "$REGION" == "EU" ]
then
euca-run-instances --instance-type m1.xlarge ami-8992a5fd -k keypair_for_regular_debian_machine
fi
if [ "$REGION" == "JP" ]
then
echo "JP"
euca-run-instances --instance-type m1.xlarge ami-22a80223 -k keypair_for_regular_debian_machine
fi
sleep 30
# setup remote system
export NEWSERVER=`euca-describe-instances | tail -n 1 | awk '{print $4}'`
ssh -oStrictHostKeyChecking=no -i keypair_private_$REGION.asc_complete root@$NEWSERVER useradd --shell /bin/bash new
ssh -oStrictHostKeyChecking=no -i keypair_private_$REGION.asc_complete root@$NEWSERVER mkdir /home/new
ssh -oStrictHostKeyChecking=no -i keypair_private_$REGION.asc_complete root@$NEWSERVER chowan new:users /home/new
ssh -oStrictHostKeyChecking=no -i keypair_private_$REGION.asc_complete root@$NEWSERVER chmod 777 /home/new
ssh -oStrictHostKeyChecking=no -i keypair_private_$REGION.asc_complete root@$NEWSERVER apt-get update
ssh -oStrictHostKeyChecking=no -i keypair_private_$REGION.asc_complete root@$NEWSERVER apt-get -y install make g++ vim gnuplot unison
scp -oStrictHostKeyChecking=no -r -i keypair_private_$REGION.asc_complete /home/new root@$NEWSERVER:/home/new
February 17, 2013, 7:21 pm
I was having an issue with SDL on iOS (6). Whenever I rotated the screen rather than changing the orientation the rendering area seemed to stay where it was. This manifested itself as the origin appearing offset to the left of (-100 odd pixels) and below (+100 odd pixels) from the true origin.
This turned out to be an issue with the Rendering context. When the screen is rotated the UIKit SDL interface creates a new OpenGL rendering context, and this is what you should write to… However, turns out you can happily keep writing to your old context and it well be renderered, just in the wrong orientation. So this is what you have to do in your event loop:
if (event->type == SDL_WINDOWEVENT && (event->window.event == SDL_WINDOWEVENT_RESIZED) || (event->window.event == SDL_WINDOWEVENT_RESTORED)) {
SDL_GetWindowSize(screen,&display_width,&display_height);
SDL_DestroyRenderer(renderer);
renderer = SDL_CreateRenderer(screen, -1, SDL_RENDERER_ACCELERATED);
function_to_trash_all_SDL_Textures();
SDL_StartTextInput();
SDL_RaiseWindow(screen); // probably not required.
}
As you can see in addition to trashing the Renderer you will need to re-enable TextInput if you’re using it. All textures you’ve previously created will also be invalidated, you therefore need to delete and reinitialise them. I’m guess this means rotating the screen and be a significant overhead.
UPDATE: You also need to check for SDL_WINDOWEVENT_RESTORED this is used when the app wakes up from going into the background the renderer context can also become invalid in these situations.
February 7, 2013, 6:26 am
I was having a couple of issues with the SDL keyboard on the iPhone. The first was that the keyboard disappears when you press enter, I didn’t want this. So I made the following change to SDL_uikitview.m:
/* Terminates the editing session */
- (BOOL)textFieldShouldReturn:(UITextField*)_textField
{
SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_RETURN);
SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RETURN);
//SDL_StopTextInput();
return YES;
}
However once I did this I was /sometimes/ getting the return key misregistering as either p or l. I found changing the keyboard for U.S. English to another language and then back again fixed the issue for the rest of the apps execution. The hack round this I finally put in place was to restart the TextInput in this method as follows:
/* Terminates the editing session */
- (BOOL)textFieldShouldReturn:(UITextField*)_textField
{
SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_RETURN);
SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RETURN);
SDL_StopTextInput();
SDL_StartTextInput();
return YES;
}