Skip to content

Instantly share code, notes, and snippets.

@rsattar
rsattar / gist:b06060df7ea293b398d1
Last active September 24, 2017 22:54
Convert CLLocation and CLHeading into GPS metadata
// Inspired by: http://stackoverflow.com/a/5314634/9849
// Simplified if-statements
// Updated to "modern" syntax
// Support optional CLHeading
// Support degree-of-precision
//
// This dictionary should then be added to the normal
// metadata using the kCGImagePropertyGPSDictionary key
- (NSDictionary *)GPSDictionaryForLocation:(CLLocation *)location heading:(CLHeading *)heading
{

Keybase proof

I hereby claim:

  • I am rsattar on github.
  • I am riz (https://keybase.io/riz) on keybase.
  • I have a public key whose fingerprint is 8D35 6F48 F552 DB52 8CAC 0B3E 3819 B5B4 9E06 49AF

To claim this, I am signing this object:

@rsattar
rsattar / gist:4998533
Created February 20, 2013 19:30
Generating an X-AvoSig string for signing API requests for Avocado
// Requires Security.framework on Cocoa and Cocoa-Touch
#import <CommonCrypto/CommonDigest.h>
- (NSString *)avoSigFromUserEmailHash:(NSString *)userEmailHash developerKey:(NSString *)developerKey developerId:(NSString *)developerId
{
NSString *combo = [userEmailHash stringByAppendingString:developerKey];
unsigned char result[CC_SHA256_DIGEST_LENGTH];
const char *combined = [combo UTF8String];
CC_SHA256(combined, [combo lengthOfBytesUsingEncoding:NSUTF8StringEncoding], result);
@rsattar
rsattar / gist:4480663
Created January 8, 2013 02:51
How to parse a Socket.IO payload (== packets bunched together), so that we can parse them as individual packets.
// Sometimes Socket.IO "batches" up messages in one packet,
// so we have to split them.
//
- (NSArray *)packetsFromPayload:(NSString *)payload
{
// "Batched" format is:
// �[packet_0 length]�[packet_0]�[packet_1 length]�[packet_1]�[packet_n length]�[packet_n]
@rsattar
rsattar / gist:1896546
Created February 24, 2012 01:28
RegexKitLite's arrayOfCaptureComponentsMatchedByRegex: written using NSRegularExpression
// I had a need to replace the use of RegexKitLite's arrayOfCaptureComponentsMatchedByRegex with
// the built-in NSRegularExpression in iOS 5+, and didn't find an existing example, so I wrote one:
- (NSArray *) arrayOfCaptureComponentsOfString:(NSString *)data matchedByRegex:(NSString *)regex
{
NSError *error = NULL;
NSRegularExpression *regExpression = [NSRegularExpression regularExpressionWithPattern:regex options:NSRegularExpressionCaseInsensitive error:&error];
NSMutableArray *test = [NSMutableArray array];
@rsattar
rsattar / launchIOSAppFromJS.js
Created November 1, 2011 21:20
How to launch an iOS url-protocol-aware app via JS, but do something different if the app isn't installed
com.foo.MyApp.prototype.launchIOSAppOrITunesLink = function() {
// Listen for the Safari window to be deactivated
goog.events.listen(window, goog.events.EventType.BLUR, this.onMobileAppDetected, false, this);
// Launch the mobile app protocol and *ALSO* launch a timer
// that checks if the app was launched (it would have deactivated the mobile browser)
goog.Timer.callOnce(this.launchMobileApp, 100, this);
goog.Timer.callOnce(this.checkAppState, 600, this);
};
@rsattar
rsattar / gist:1266104
Created October 5, 2011 23:59
How to check if the Adobe security panel is closed
// This code checks one time if the security panel is closed.
// When you open the security panel, you should run this test
// repeatedly with a timer (every 500ms seems to work well).
// If the security panel is closed, you can then clean up your timers
protected function securityPanelIsClosed():Boolean
{
// Why not just wait for an event from the SettingsPanel to know that it's closed?  Because there isn't one.
// See http://bugs.adobe.com/jira/browse/FP-41
var closed:Boolean = true;