Skip to content

Instantly share code, notes, and snippets.

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 / UIView+BorderViews.h
Created December 15, 2014 22:58
UIView+BorderViews - A simple way to add a throwaway border view to a particular edge of a UIView
//
// UIView+BorderViews.h
// Cluster
//
// Created by Rizwan Sattar on 4/1/14.
// Copyright (c) 2014 Cluster Labs, Inc. All rights reserved.
//
#import <UIKit/UIKit.h>
@rsattar
rsattar / CenteredTableView.m
Last active August 29, 2015 14:19
How to center the cells in a table view controller on iOS 7 (like Settings.app on iPad)
- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
// See: http://stackoverflow.com/a/18833311/9849
if (self.displayAsCenteredTableView) {
if (tableView == self.tableView) {
CGFloat cornerRadius = 7.f;
cell.backgroundColor = UIColor.clearColor;
CAShapeLayer *fillLayer = [[CAShapeLayer alloc] init];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
CGMutablePathRef pathRef = CGPathCreateMutable();
@rsattar
rsattar / Enum.m
Created April 29, 2015 21:30
Template for creating string <-> enum conversion
// In .h
typedef NS_ENUM(NSInteger, ClusterAPIClusterMediaKind) {
ClusterAPIClusterMediaKindPhoto = 1 << 1,
ClusterAPIClusterMediaKindVideo = 1 << 2,
ClusterAPIClusterMediaKindText = 1 << 3,
ClusterAPIClusterMediaKindFancyText = 1 << 4,
ClusterAPIClusterMediaKindLocation = 1 << 5,
};
@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;
@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: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 / LKConfigPreview.md
Last active November 11, 2015 01:18
A potential way to list LKConfig keys, with potential rules

autologin = TRUE

googleLogin = TRUE

  • When version > 3.5: FALSE

barName = Hello World!

foo = FALSE

@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: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);