Skip to content

Instantly share code, notes, and snippets.

View aaronpearce's full-sized avatar

Aaron Pearce aaronpearce

View GitHub Profile
NSString *string = @"Hannah";
NSMutableString *reversedStr;
int len = [string length];
reversedStr = [NSMutableString stringWithCapacity:len];
while (len > 0)
[reversedStr appendString:[NSString stringWithFormat:@"%C", [string characterAtIndex:--len]]];
if([[string lowercaseString] isEqualToString:[reversedStr lowercaseString]]) {
NSLog(@"Plaindrome");
} else {
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_HIGH, 0ul), ^{
// Do a taks in the background
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
[[storage cookies] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[storage deleteCookie:obj];
if(stop) {
NSArray *cookies = [NSKeyedUnarchiver unarchiveObjectWithData:[[self.array objectAtIndex:indexPath.row] objectAtIndex:1]];
[cookies enumerateObjectsUsingBlock:^(id obj2, NSUInteger idx, BOOL *stop2) {
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:obj2];
if(stop2) {
@aaronpearce
aaronpearce / gist:2865248
Created June 3, 2012 22:34
iPhotograph Thumber
<?php
/*
* Released under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 License, which allows you to copy, distribute, transmit, alter, transform,
* and build upon this work but not use it for commercial purposes, providing that you attribute me, photofroggy ([email protected]) for its creation.
*
*
* Here we have an example of a Contra extension!
* Every extension is a class, and the class has to be
* an extension of the extension class, or it won't work
@aaronpearce
aaronpearce / gist:2865319
Created June 3, 2012 22:56
iPhotograph Thumber
<?php
/*
* Released by Aaron Pearce (Pickley). All rights reserved. You may use this as you wish, just make sure to mention me.
*/
class Random extends extension {
public $name = 'Random'; // name - This is the name of the extension!
CookieSyncManager.createInstance(getApplicationContext());
CookieManager mgr = CookieManager.getInstance();
List<Cookie> cookies = ((AbstractHttpClient) httpClient).getCookieStore().getCookies();
if(cookies != null)
{
for(Cookie cookie : cookies)
{
String cookieString = cookie.getName() + "=" + cookie.getValue() + "; domain=" + cookie.getDomain();
mgr.setCookie(cookie.getDomain(), cookieString);
<?php
/*
Quick Script for testing bot
GPIO Pin Layout
17 = Right Motor Forwards
18 = Right Motor Backwards
22 = Left Motor Forwards
@aaronpearce
aaronpearce / PHP GPIO Lib for Raspberry Pi
Created July 10, 2012 00:45
PHP GPIO Lib for Raspberry Pi
<?php
class GPIO {
// Using BCM pin numbers.
private $pins = ['0', '1', '4', '7', '8', '9', '10', '11', '14', '15', '17', '18', '21', '22', '23', '24', '25'];
// exported pins for when we unexport all
private $exportedPins = array();
// Setup pin, takes pin number and direction (in or out)
self.tableView.backgroundView = nil;
self.tableView.backgroundColor = [UIColor colorWithRed:0.961 green:0.961 blue:0.961 alpha:1.000];
presetning this onto a normla view controller. Comes as a pagesheet everytime I think
NSString *storyboardName = @"MainStoryboard_iPhone";
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) storyboardName = @"MainStoryboard_iPad";
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];
UINavigationController *walkThrough = [storyBoard instantiateViewControllerWithIdentifier:@"walkthroughNav"];
walkThrough.modalPresentationStyle = UIModalPresentationFormSheet;
+(void)runCommand:(NSString *)command withParameters:(NSDictionary *)params {
// create class name
command = [[command componentsSeparatedByString:@" "] objectAtIndex:0];
command = [NSString stringWithFormat:@"SYEvent_%@", [command capitalizedString]]; // capitalize
Class class = NSClassFromString(command);
if([class respondsToSelector:@selector(run:)])
[class performSelector:@selector(run:) withObject:params];
}
// checks if class exists for command