Skip to content

Instantly share code, notes, and snippets.

@kylehowells
kylehowells / KHEventQueue.h
Created August 4, 2014 19:34
Event queue I wrote to make a block run after all conditions have been met. For example, removing a complex loading animation after the animation has finished and the data has loaded.
//
// KHEventQueue.h
//
// Created by Kyle Howells on 04/08/2014.
// Copyright (c) 2014 Kyle Howells. All rights reserved.
//
#import <Foundation/Foundation.h>
typedef void (^KHEventBlock)(void);
@kylehowells
kylehowells / gist:9aeb36ea211f65c823d7
Created August 6, 2014 03:35
My best understanding of how SpringBoard manages its SBGestureRecognizers
//SpringBoard
-(void)_reloadDemoAndDebuggingDefaultsAndCapabilities{
//..Blah blah, setting stuff up, etc.., etc...
// Control Centre gesture
SBOffscreenSwipeGestureRecognizer *gesture = [[SBOffscreenSwipeGestureRecognizer alloc] initForOffscreenEdge:0x4];
[gesture setTypes:0x40];
[gesture setShouldUseUIKitHeuristics:YES];
@kylehowells
kylehowells / Close_SBApplication_.mm
Last active August 29, 2015 14:05
How to correctly quit an application on iOS 7 (Correct = the same way the app switcher does)
// Function signature
void (*KH_BKSTerminateApplicationForReasonAndReportWithDescription)(NSString *app, int a, int b, NSString *description) = NULL;
// Find the Symbol.
if (KH_BKSTerminateApplicationForReasonAndReportWithDescription == NULL) {
// dlopen Handle
void* handle = dlopen(0,RTLD_NOW|RTLD_GLOBAL);
// Load the function to our pointer
KH_BKSTerminateApplicationForReasonAndReportWithDescription = dlsym(handle, "BKSTerminateApplicationForReasonAndReportWithDescription");
}
@kylehowells
kylehowells / gist:d911bc2bba9000a3f2aa
Created August 21, 2014 15:25
NSString for seconds. Turns a number of seconds, (i.e 3705), into a string with the format hh:mm:ss (i.e @"1:1:45").
-(NSString*)stringForTimeInSeconds:(NSInteger)time{
NSInteger seconds = time % 60;
NSInteger minutes = (time - seconds) / 60;
NSInteger hours = floorl(minutes / 60);
if (hours > 0) {
minutes -= (hours * 60);
return [NSString stringWithFormat:@"%ld:%ld:%.2ld", (long)hours, (long)minutes, (long)seconds];
}
return [NSString stringWithFormat:@"%ld:%.2ld", (long)minutes, (long)seconds];
@kylehowells
kylehowells / Show-Hide_Wallpaper.m
Created August 27, 2014 20:42
How to temporarily show and hide the wallpaper on iOS 7
[[SBWallpaperController sharedInstance] beginRequiringWithReason:@"Switcher Showing"];
[[SBWallpaperController sharedInstance] endRequiringWithReason:@"Switcher Showing"];
@kylehowells
kylehowells / gist:8ff379300eb2f088da24
Last active August 29, 2015 14:06
Send video to XBMC in Javascript
var string = "plugin://plugin.video.youtube/?action=play_video&videoid=WnlLQbAQSxQ"
var params = {
item : {
file : string
}
}
var data = { jsonrpc: "2.0", method: "Player.Open", id: 1 };
data.params = params;
@kylehowells
kylehowells / gist:97b256056dd0ef53e18d
Created September 5, 2014 20:08
A method to try and retrieve the Youtube video ID from a string. (designed to parse user input, hence the multiple accepted formats).
/// Accepts any of the following formats
//
// - The Youtube ID itself:
// 1. yj4OtpHl8EE
//
// - A youtu.be short URL:
// 2. http://youtu.be/yj4OtpHl8EE
//
// - A normal youtube.com URL:
// 3. http://www.youtube.com/watch?v=ZvmMzI0X7fE
@kylehowells
kylehowells / gist:ca314af0858844be9ff4
Created September 28, 2014 17:10
Resize a keyboard extension
-(void)viewDidAppear:(BOOL)animated{
CGFloat _expandedHeight = 500;
NSLayoutConstraint *_heightConstraint =
[NSLayoutConstraint constraintWithItem: self.view
attribute: NSLayoutAttributeHeight
relatedBy: NSLayoutRelationEqual
toItem: nil
attribute: NSLayoutAttributeNotAnAttribute
multiplier: 0.0 constant: _expandedHeight];
[self.view addConstraint: _heightConstraint];
on run {input, parameters}
tell application "System Events"
keystroke (the clipboard as text)
end tell
return input
end run
// Variables
kb = [UIKeyboardImpl sharedInstance]; l = [kb _layout]; inputDelegate = [kb inputDelegate];
// Some subclass of UITextRange (WKTextRange)
textRange = [inputDelegate selectedTextRange];
// Some subclass of UITextPosition (WKTextPosition)
//start = [textRange start];
//end = [textRange end];
begin = [inputDelegate beginningOfDocument];