Skip to content

Instantly share code, notes, and snippets.

root@743f9944e259:/VaporTest# /usr/bin/swift-build-tool -f /VaporTest/.build/debug.yaml -v
/usr/bin/swiftc -target armv7-unknown-linux-gnueabihf -sdk / -g -L /VaporTest/.build/armv7-unknown-linux-gnueabihf/debug -o /VaporTest/.build/armv7-unknown-linux-gnueabihf/debug/Run -module-name Run -emit-executable -Xlinker '-rpath=$ORIGIN' /VaporTest/.build/armv7-unknown-linux-gnueabihf/debug/App.build/app.swift.o /VaporTest/.build/armv7-unknown-linux-gnueabihf/debug/App.build/boot.swift.o /VaporTest/.build/armv7-unknown-linux-gnueabihf/debug/App.build/configure.swift.o /VaporTest/.build/armv7-unknown-linux-gnueabihf/debug/App.build/Controllers/TodoController.swift.o /VaporTest/.build/armv7-unknown-linux-gnueabihf/debug/App.build/Models/Todo.swift.o /VaporTest/.build/armv7-unknown-linux-gnueabihf/debug/App.build/Routes.swift.o /VaporTest/.build/armv7-unknown-linux-gnueabihf/debug/Async.build/Async+NIO.swift.o /VaporTest/.build/armv7-unknown-linux-gnueabihf/debug/Async.build/AsyncError.swift.o /VaporTest/.build/armv7-u
let pointSize: CGFloat = 60
let systemFontDesc = UIFont.systemFont(ofSize: pointSize, weight: UIFont.Weight.light).fontDescriptor
let smallCapsFontDesc = systemFontDesc.addingAttributes(
[
UIFontDescriptor.AttributeName.featureSettings:
[
[
kCTFontFeatureTypeIdentifierKey: kLowerCaseType,
kCTFontFeatureSelectorIdentifierKey: kLowerCaseSmallCapsSelector
]
struct PdfFile {
var filepath: String?
var file: PDFDocument?
private var cacheImages = NSCache<NSString, UIImage>()
var numberOfPages: Int {
return file?.pdfDocument?.numberOfPages ?? 0
}
init(filepath path: String?) {
@emarashliev
emarashliev / ApolloSetup.swift
Last active March 6, 2018 17:26
Apollo with SQLite
import Apollo
let path = NSSearchPathForDirectoriesInDomains( .documentDirectory, .userDomainMask, true).first!
let url = URL(string: "http://localhost:3000/graphql")!
let cache = try! SQLiteNormalizedCache(fileURL: URL(string: "\(path)/db.sqlite3")!)
let apollo = ApolloClient(networkTransport: HTTPNetworkTransport(url: url), store: ApolloStore(cache: cache))
apollo.fetch(query: AllReceiptsQuery()){ (result, error) in
print(result?.data?.receipts?.first)
Observable<Int>.interval(1, scheduler: ConcurrentDispatchQueueScheduler.init(qos: DispatchQoS.background)).subscribe { _ in
URLSession.shared.rx.json(url: url).subscribe(onNext: { json in
print(json)
})
}
@emarashliev
emarashliev / TryCatch.m
Last active July 5, 2017 18:44
Catch NSException in Swift
@implementation TryCatch
+ (void)try:(void(^_Nonnull)())try
catch:(nullable void(^)(NSException* _Nullable exception))catch
finally:(nullable void(^)())finally {
@try {
try ? try() : nil;
}
@catch (NSException *exception) {
@implementation UIImageView (Asynchronous)
+ (instancetype _Nonnull)imageViewWithURL:(NSString * _Nonnull )url {
return [self imageViewWithURL:url completionHandler:nil];
}
+ (instancetype _Nonnull)imageViewWithURL:(NSString * _Nonnull )url
completionHandler:(completionHandler _Nullable)block {
UIImageView *imageView = [UIImageView new];
[imageView loadImageWithURL:url completionHandler:block];
@implementation UIImage (AverageColor)
- (UIColor * _Nonnull)averageColor {
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
unsigned char rgba[4];
CGContextRef context = CGBitmapContextCreate(rgba, 1, 1, 8, 4, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGContextDrawImage(context, CGRectMake(0, 0, 1, 1), self.CGImage);
CGColorSpaceRelease(colorSpace);
CGContextRelease(context);
@emarashliev
emarashliev / gist:1cd7336f2f6f54a0775c
Last active August 29, 2015 14:14
Change commit messages of past Git commits
git rebase -i [COMMIT BEFORE THE FIRST YOU WANT TO EDIT]
# Mark all messages to be changed with "edit".
# Git will start the rebasing and stop at every marked commit.
git commit -amend -m "new message"
git rebase -continue
class Array2D<T> {
let columns: Int
let rows: Int
var array: Array<T?>
init(columns: Int, rows: Int) {
self.columns = columns
self.rows = rows
array = Array<T?>(count: rows * columns, repeatedValue: nil)
}