Skip to content

Instantly share code, notes, and snippets.

@codeswimmer
codeswimmer / ios_play_sound.m
Created January 2, 2013 19:57
iOS: How to play sounds
SystemSoundID soundID;
id sndpath = [[NSBundle mainBundle] pathForResource:@"mySound" ofType:@"mp3" inDirectory:@"/"];
CFURLRef baseURL = (CFURLRef) [[NSURL alloc] initFileURLWithPath:sndpath];
AudioServicesCreateSystemSoundID (baseURL, &soundID);
AudioServicesPlaySystemSound(soundID);
[baseURL release];
@codeswimmer
codeswimmer / ios_vibrate_with_sound.m
Created January 2, 2013 19:56
iOS: Add vibration on sound
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
@codeswimmer
codeswimmer / ios_anim_move.m
Created January 2, 2013 19:55
iOS: Animate an object to move
CABasicAnimation *myAnimation;
myAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
myAnimation.duration=1;
myAnimation.repeatCount=2;
myAnimation.autoreverses=YES;
myAnimation.fromValue=[NSNumber numberWithFloat:0];
myAnimation.toValue=[NSNumber numberWithFloat:-50];
[view.layer addAnimation:myAnimation forKey:@"animateLayer"];
@codeswimmer
codeswimmer / ios_image_anim.m
Created January 2, 2013 19:54
iOS: How to create an animation with a series of images
NSArray *myImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"1.png"],
[UIImage imageNamed:@"2.png"],
[UIImage imageNamed:@"3.jpg"],
[UIImage imageNamed:@"4.gif"], nil];
UIImageView *myAnimatedView = [UIImageView alloc];
[myAnimatedView initWithFrame:[self bounds]];
myAnimatedView.animationImages = myImages;
myAnimatedView.animationDuration = 0.25; // seconds
@codeswimmer
codeswimmer / ios_cur_loc_all_the_time.m
Created January 2, 2013 19:53
iOS: How to Use Core Location Services To Acquire A Current Location All The Time
If you need to acquire your current location all the time, you need to have a delegate method to receive this information and parse this location to acquire latitude and longitude value.
B sure to implement CLLocationManagerDelegate and create a property something like this in your .h file.
CLLocationManager *location_mgr;
And set properties.
@property (nonatomic, retain) CLLocationManager *location_mgr;
@codeswimmer
codeswimmer / ios_current_location.m
Created January 2, 2013 19:52
iOS: How to Use Core Location Services To Acquire A Current Location
-(void)acquireCurrentLocation
{
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
[locationManager startUpdatingLocation];
CLLocation *location = locationManager.location;
NSLog(@"Current Location: Latitude(%f), Longitude(%f)",location.coordinate.latitude, location.coordinate.longitude);
[locationManager release];
}
@codeswimmer
codeswimmer / ios_dynamic_font_loading.m
Created December 21, 2012 21:22
iOS/OSX: dynamic font loading
NSData *inData = /* your decrypted font-file data */;
CFErrorRef error;
CGDataProviderRef provider = CGDataProviderCreateWithCFData((CFDataRef)inData);
CGFontRef font = CGFontCreateWithDataProvider(provider);
if (! CTFontManagerRegisterGraphicsFont(font, &error)) {
CFStringRef errorDescription = CFErrorCopyDescription(error)
NSLog(@"Failed to load font: %@", errorDescription);
CFRelease(errorDescription);
}
CFRelease(font);
#!/usr/bin/env python
'''
optparse_testing.py
some recipes from http://www.alexonlinux.com/pythons-optparse-for-human-beings
'''
import optparse
parser = optparse.OptionParser()
# basics
@codeswimmer
codeswimmer / which_shell.sh
Created December 4, 2012 02:31
bash: How to tell which shell you're using
ps -p $$
@codeswimmer
codeswimmer / compute_position_for_widget.m
Created November 28, 2012 17:46
iOS: Compute Position for Widget that accounts for zoom scale
- (CGRect)computePositionForWidget:(UIView *)widgetView fromView:(UIScrollView *)scrollView
{
CGRect frame;
float scale;
scale = scrollView.zoomScale;
// compute the widget size based on the zoom scale
frame.size.width = widgetView.frame.size.width * scale;
frame.size.height = widgetView.frame.size.height * scale;