This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Turn a string like "1 1/2" into 1.5. If there is no fractional | |
* part, then the whole number is returned. If the number is not | |
* well formatted, then nil is returned. | |
*/ | |
+ (NSNumber *)numberFromFractionalString:(NSString *)string | |
{ | |
if (string == nil) { | |
return nil; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
{ | |
NSURL *db = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"TestDB.sqlite"]; | |
[[NSFileManager defaultManager] removeItemAtURL:db error:nil]; | |
NSManagedObjectContext *moc = [self managedObjectContext]; | |
NSLog(@"Creating Entities"); | |
for (int i=0; i<10000; i++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (NSDictionary *)downloadableFonts | |
{ | |
CTFontDescriptorRef desc = CTFontDescriptorCreateWithAttributes((CFDictionaryRef)@{(id)kCTFontDownloadableAttribute : (id)kCFBooleanTrue}); | |
CFArrayRef matchedDescs = CTFontDescriptorCreateMatchingFontDescriptors(desc, NULL); | |
NSArray *array = (__bridge NSArray *)matchedDescs; | |
NSMutableDictionary *families = [NSMutableDictionary dictionary]; | |
for (UIFontDescriptor *fontDescriptor in array) { | |
NSString *familyName = fontDescriptor.fontAttributes[UIFontDescriptorFamilyAttribute]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
return $http({ | |
method: "POST", | |
url: "/2/projects?accessToken=" + $userService.accessToken, | |
// The undefined Content-Type is intentional; with that, the browser will genearate | |
// the MIME boundaries and set the content type later. | |
headers: {'Content-Type': undefined }, | |
transformRequest: function (data) { | |
var formData = new FormData(); | |
formData.append("project", angular.toJson(postVars)); | |
return formData; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Auto layout in a Swift Playground (for iOS). | |
import UIKit | |
var v = UIView() | |
v.frame = CGRectMake(0, 0, 200, 200) | |
var b1 = UIButton() | |
b1.setTitle("Click Me", forState:UIControlState.Normal) | |
b1.setTitleColor(UIColor.blueColor(), forState: UIControlState.Normal) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// arr1 is the current list | |
// arr2 is the new list | |
// the insert and delete callbacks will be called - pass these | |
// through to WKInterfaceTable to perform a delta update | |
func diff<T: Comparable>(arr1: Array<T>, var arr2: Array<T>, insertFunc: (index: Int, item: T) -> Void, deleteFunc: (Int) -> Void) { | |
var idx1 = 0 | |
var idx2 = 0 | |
while (idx1 < arr1.count) { | |
// identical items; step to next one | |
if (idx2 < arr2.count && arr1[idx1] == arr2[idx2]) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// (string) $message - message to be passed to Slack | |
// (string) $room - room in which to write the message, too | |
// (string) $icon - You can set up custom emoji icons to use with each message | |
function slack($message, $room = "general", $icon = ":bell:") { | |
$room = ($room) ? $room : "general"; | |
$data = "payload=" . json_encode(array( | |
"channel" => "#{$room}", | |
"text" => $message, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(lldb) p types | |
([String]) $R0 = 56 values { | |
[0] = "video/mp4" | |
[1] = "video/x-m4v" | |
[2] = "video/mpg" | |
[3] = "audio/x-m4r" | |
[4] = "audio/AMR" | |
[5] = "video/x-mpg" | |
[6] = "video/3gpp2" | |
[7] = "video/mp2p" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/swift | |
// Swift script to search for Bonjour services on the local network. | |
// Found services are printed to the console. | |
import Foundation | |
import CoreFoundation | |
// Inner search, finds services of a particular type |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#include "libavcodec/avcodec.h" | |
#include "libavformat/avformat.h" | |
#include "libswscale/swscale.h" | |
#include <libavutil/imgutils.h> | |
uint64_t getNanoseconds(void); |
OlderNewer