Skip to content

Instantly share code, notes, and snippets.

//
// UIWebView+TrueHeight.h
// RAWebViewTrueHeight
//
// Created by Stephen Keep on 08/03/2013.
// Copyright (c) 2013 Stephen Keep. All rights reserved.
//
#import <Foundation/Foundation.h>
@stephenkeep
stephenkeep / viewController.m
Created March 11, 2013 11:48
Device Orientation Notification
- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object: nil];
}
-(void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"UIDeviceOrientationDidChangeNotification" object:nil];
}
#define DATA(str) [(NSString*)(str) dataUsingEncoding:NSUTF8StringEncoding]
- (NSData *)generateFormData:(NSDictionary *)dictionary boundary:(NSString *)boundary {
NSMutableData *data = [[NSMutableData alloc] init];
id key;
NSEnumerator *enumerator = [dictionary keyEnumerator];
while (key = [enumerator nextObject]) {
id value = [dictionary valueForKey:key];
[data appendData:DATA(([NSString stringWithFormat:@"--%@\r\n", boundary]))];
@stephenkeep
stephenkeep / @synchronized
Last active December 21, 2015 16:49
iOS Snips
-(void)AppendExisting:(NSString*)val
{
@synchronized (val) {
[oldValue stringByAppendingFormat:@"-%@",val];
}
}
@stephenkeep
stephenkeep / enum
Created September 19, 2013 08:39
enum
typedef enum: NSInteger {
NSOperationQueuePriorityNormal = 0;
NSOperationQueuePriorityHigh = 4;
} NSOperationQueuePriority;
//ios6
SString *UUID = [[NSUUID UUID] UUIDString];
//ios5
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSString *UUID = [[NSUserDefaults standardUserDefaults] objectForKey:kApplicationUUIDKey];
@stephenkeep
stephenkeep / Heroku CLI
Last active December 26, 2015 07:29
Heroku commands
//set environment variable
heroku config:set API_URL='<URL HERE>' --app <APP NAME>
//Database dump
heroku pgbackups:capture
curl -o latest.dump `heroku pgbackups:url`
//Restore locally
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U myuser -d mydb latest.dump
@stephenkeep
stephenkeep / README.md
Last active August 29, 2015 14:16 — forked from lobodin/README.md

#Generate cities data

  1. wget http://download.geonames.org/export/dump/cities15000.zip
  2. unzip cities15000.zip
  3. node geonames.js cities15000.txt

The result is json array of cities in the following format:

{

_id:

[{"id":"eb5f1784.14a0e8","type":"onthedot-connection","z":"4dc47816.b23b88","name":"Red Ant","api_url":"https://sbapi.onthedot.com/api/v1.0","api_key":"1dOHtajAxKpCP0kLnc6BKMI6ZeQa"},{"id":"4a99916a.b5667","type":"onthedot-delete-booking","z":"4dc47816.b23b88","creds":"eb5f1784.14a0e8","name":"","store_id":"","order_id":"","x":382.5,"y":456,"wires":[["c7e807ad.3817f8"]]},{"id":"d3c8273f.2c37d8","type":"inject","z":"4dc47816.b23b88","name":"","topic":"","payload":"{\"order_id\":\"17450353\",\"store_id\":\"RedAnt-01\"}","payloadType":"json","repeat":"","crontab":"","once":false,"x":92,"y":378,"wires":[["3fe83871.c017c8"]]},{"id":"c7e807ad.3817f8","type":"debug","z":"4dc47816.b23b88","name":"","active":true,"console":"false","complete":"false","x":563,"y":401,"wires":[]},{"id":"3fe83871.c017c8","type":"function","z":"4dc47816.b23b88","name":"","func":"msg.payload = {\n store_id: \"RedAnt-01\", \n order_id: \"17450353\"\n};\nreturn msg;","outputs":1,"noerr":0,"x":232.5,"y":381,"wires":[["4a99916a.b5667"]]}]