Skip to content

Instantly share code, notes, and snippets.

// 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];
@kylehowells
kylehowells / YoutubeThumbnail.swift
Last active April 14, 2019 07:26
Easily get the url of a YouTube video's different thumbnails
/**
What size and quailty youtube thumbnail you want.
- Zero: Player Background: (480x360 pixels) (same as High)
- One: Start: (120x90 pixels)
- Two: Middle: (120x90 pixels)
- Three: End: (120x90 pixels)
- Default: Normal: (120x90 pixels)
- Medium: Medium: (320x180 pixels)
- High: High: (480x360 pixels) (same as 0)
@kylehowells
kylehowells / gist:f7df6f9863af9f89e555
Last active August 29, 2015 14:09
Cleans up mostly correct URL strings so that NSURL will accept them (example: google.com -> http://google.com)
// scheme://domain:port/path?query_string#fragment_id
func cleanupURLString(urlString: String) -> String {
var urlSubstring = urlString
var protocolString:String?
var userString:String?
var passString:String?
var hostString:String
var portString:String?
var pathString:String?
@kylehowells
kylehowells / NSURL+QueryDictionary.swift
Created November 17, 2014 02:21
Turns an NSURL's -query string into a dictionary. Sadly URL's allow keys to be declared multiple times, so it is a dictionary of String of the keys and arrays of Strings as the objects. [String: [String]]
extension NSURL
{
@objc var queryDictionary:[String: [String]]? {
get {
if let query = self.query {
var dictionary = [String: [String]]()
for keyValueString in query.componentsSeparatedByString("&") {
var parts = keyValueString.componentsSeparatedByString("=")
if parts.count < 2 { continue; }
@kylehowells
kylehowells / JSON-RPC API of XBMC.json
Created November 26, 2014 03:10
The prettified result of the XBMC JSON api's introspection method. http://kodi.wiki/view/JSON-RPC_API/v6#JSONRPC.Introspect
{
"id":"1",
"jsonrpc":"2.0",
"result":{
"description":"JSON-RPC API of XBMC",
"id":"http://xbmc.org/jsonrpc/ServiceDescription.json",
"methods":{
"Addons.ExecuteAddon":{
"description":"Executes the given addon with the given parameters (if possible)",
"params":[
@kylehowells
kylehowells / gist:36b6f7e3f584590d0943
Created December 4, 2014 01:18
MRMediaRemoteGetNowPlayingInfo Keys
MRMediaRemoteGetNowPlayingInfo(dispatch_get_main_queue(), ^(CFDictionaryRef information) {});
/* [information allKeys]
(
kMRMediaRemoteNowPlayingInfoTotalDiscCount,
kMRMediaRemoteNowPlayingInfoShuffleMode,
kMRMediaRemoteNowPlayingInfoTrackNumber,
kMRMediaRemoteNowPlayingInfoDuration,
kMRMediaRemoteNowPlayingInfoRepeatMode,
kMRMediaRemoteNowPlayingInfoTitle,
@kylehowells
kylehowells / gist:33cd1dbce045ec3e289e
Created December 20, 2014 00:24
SBActivationSettings descriptions
cy# settings = [[SBActivationSettings alloc] init]
#"<SBActivationSettings:0x17420c8a0> -> {}"
cy# settings
#"<SBActivationSettings:0x17420c8a0> -> {}"
cy# [settings keyDescriptionForSetting:0]
@"notASetting"
cy# [settings keyDescriptionForSetting:1]
@"noAnimate"
cy# [settings keyDescriptionForSetting:2]
@"animationDurationForOthersSuspension"
#!/bin/sh
find . \( -iname "*.[chm]" -o -iname "*.swift" -o -iname "*.cpp" -o -iname "*.mm" -o -iname "*.xm" \) -print0 | xargs -0 cat | wc -l
@kylehowells
kylehowells / gist:46389fc58d21cb2f6f75
Created February 27, 2015 02:09
Get an uint16_t that was stored in an uint8_t* array.
// uint8_t *buffer [1] & [2] contain the uint16_t bytes.
uint16_t duration;
uint8_t* p = (uint8_t*)(void*)&duration;
*p = buffer[1]; // 2e
*(p+1) = buffer[2]; // e5
//duration now contains 2ee5
printf("duration: %d", duration);
@kylehowells
kylehowells / gist:7851161d83a33e03107d
Created June 3, 2015 02:01
HomeKit UDID Name mapping
// HomeKit UDID Name mapping
cy# [HAKUUID nameMapping]
@{ "00000014":"Identify",
"FED0":"Lock Mechanism",
"0000002F":"Saturation",
"0000000B":"Camera Tilt",
"00000017":"IP Camera Stop Session",
"00000040":"Fan",
"0000000E":"Current Door State",