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
func takeScreenshot(view: UIView) -> UIImageView { | |
UIGraphicsBeginImageContext(view.frame.size) | |
view.layer.renderInContext(UIGraphicsGetCurrentContext()) | |
let image = UIGraphicsGetImageFromCurrentImageContext() | |
UIGraphicsEndImageContext() | |
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil) | |
return UIImageView(image: image) | |
} |
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
let max = 1024*1024*200 | |
var data = NSMutableData(capacity: max) | |
for var i=0; i<max/4; ++i { | |
var random = arc4random() | |
data?.appendBytes(&random, length: 4) | |
} |
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
//: Playground - noun: a place where people can play | |
import UIKit | |
var str = "Hello, playground" | |
class Hello { | |
var id: String | |
init(id: String) { |
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
OperationQueue( | |
SerialOperation("S1", | |
SampleOp("op1", timeout: 1), | |
SampleOp("op2", timeout: 1) | |
), | |
ConcurrentOperation("C1", | |
SampleOp("op3", timeout: 1), | |
SampleOp("op4", timeout: 1), | |
ConcurrentOperation("C2", | |
SampleOp("op5", timeout: 1), |
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
oq( | |
TakeInventoryAndDiffAgainstServer(model: self), | |
GetInventoryFromServer(model: self), | |
SaveInventory(model: self), | |
bo { op in | |
return true | |
} | |
).start() |
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 | |
class SampleOp : Operation { | |
private var timeout: Double | |
init(timeout: Double) { | |
self.timeout = timeout | |
super.init() | |
} |
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
extension NSManagedObject { | |
class func createEntity<T: NSManagedObject>(context: NSManagedObjectContext) -> T { | |
return NSEntityDescription.insertNewObjectForEntityForName(NSStringFromClass(T), inManagedObjectContext: context) as! T | |
} | |
} | |
class Customer: NSManagedObject { | |
@NSManaged var id: NSNumber | |
} |
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/perl | |
#use strict; | |
use warnings; | |
use Switch; | |
use Data::Printer; | |
my ($choice, $times, $key, $value); | |
my @array = (1, 2, 3, 4, 5, 6, 7, 8, 9); | |
#my %hash_0 = map { $_ => $_ * 0 } @array; |
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
func drawOnPDF(path: String) { | |
// Get existing Pdf reference | |
let pdf = CGPDFDocumentCreateWithURL(NSURL(fileURLWithPath: path)) | |
// Get page count of pdf, so we can loop through pages and draw them accordingly | |
let pageCount = CGPDFDocumentGetNumberOfPages(pdf); | |
// Write to file | |
UIGraphicsBeginPDFContextToFile(path, CGRectZero, 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
#!/usr/bin/env perl | |
use Mojolicious::Lite; | |
use POSIX 'strftime'; | |
my $ua = Mojo::UserAgent->new; | |
get '/' => sub { | |
my $c = shift; | |
$c->delay( |