Skip to content

Instantly share code, notes, and snippets.

View m1entus's full-sized avatar

Michał Zaborowski m1entus

View GitHub Profile
@m1entus
m1entus / gist:8d56b4d272fb0d13750e
Created March 11, 2016 10:00 — forked from justinHowlett/gist:4611988
Determine if a UIImage is generally dark or generally light
BOOL isDarkImage(UIImage* inputImage){
BOOL isDark = FALSE;
CFDataRef imageData = CGDataProviderCopyData(CGImageGetDataProvider(inputImage.CGImage));
const UInt8 *pixels = CFDataGetBytePtr(imageData);
int darkPixels = 0;
int length = CFDataGetLength(imageData);
public struct CoreDataContextObserverState : OptionSetType {
static public let Inserted: ContextWatcher.CoreDataContextObserverState
static public let Updated: ContextWatcher.CoreDataContextObserverState
static public let Deleted: ContextWatcher.CoreDataContextObserverState
static public let Refreshed: ContextWatcher.CoreDataContextObserverState
static public let All: CoreDataContextObserverState
}
public typealias CoreDataContextObserverCompletionBlock = (NSManagedObject, CoreDataContextObserverState) -> ()
public class CoreDataContextObserver {
@m1entus
m1entus / dateFormatter.swift
Created July 23, 2014 08:01
Swift NSDateFormatter singleton
class var userDateFormatter : NSDateFormatter {
struct Static {
static let instance: NSDateFormatter = {
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
return dateFormatter
}()
}
return Static.instance
}
//...
let configuration = SocialServiceBrowserConfigurator(client: SocialServiceBrowserDropboxClient(), selectionMode: .select)
let viewController = SocialServiceBrowserViewController(configuration: configuration, uiConfiguration: configuration)
viewController.delegate = self
present(UINavigationController(rootViewController: viewController), animated: true, completion: nil)
//...
extension ViewController: SocialServiceBrowserViewControllerDelegate {
public protocol SocialServiceBrowserClient {
var serviceName: String { get }
func requestRootNode(with completion: @escaping (SocialServiceBrowserResult<SocialServiceBrowerNodeListResponse, Error>) -> Void) -> SocialServiceBrowserOperationPerformable?
func requestChildren(`for` node: SocialServiceBrowerNode, withCompletion completion: @escaping (SocialServiceBrowserResult<SocialServiceBrowerNodeListResponse, Error>) -> Void) -> SocialServiceBrowserOperationPerformable?
func requestThumbnail(`for` node: SocialServiceBrowerNode, withCompletion: @escaping (SocialServiceBrowserResult<UIImage, Error>) -> Void) -> SocialServiceBrowserOperationPerformable?
func requestData(`for` node: SocialServiceBrowerNode, withCompletion: @escaping (SocialServiceBrowserResult<URL, Error>) -> Void) -> SocialServiceBrowserOperationPerformable?
}
extension Files.Metadata: SocialServiceBrowerNode {
public var nodeId: String? {
if let file = self as? Files.FileMetadata {
return file.id
}
if let folder = self as? Files.FolderMetadata {
return folder.id
}
return nil
}
class SocialServiceBrowserDropboxClient: SocialServiceBrowserClient {
var serviceName: String = "Dropbox"
var filter: SocialServiceBrowserFilterType = .none
private var client: DropboxClient? {
return DropboxClientsManager.authorizedClient
}
func requestRootNode(with completion: @escaping (SocialServiceBrowserResult<SocialServiceBrowerNodeListResponse, Error>) -> Void) -> SocialServiceBrowserOperationPerformable? {
return client?.files.listFolder(path: "").response(completionHandler: { [weak self] response, error in
@m1entus
m1entus / make_cert.sh
Last active March 12, 2018 19:36
Generating apple push notifications
#!/bin/sh
if [ "$#" != 3 ]; then
echo "Illegal number of parameters, usage: ./make_cert.sh apn_file key_file output_filename"
fi
eval "openssl x509 -in $1.cer -inform DER -out $1.pem -outform PEM"
eval "openssl pkcs12 -nodes -export -inkey $2.key -in $1.pem -out $1.p12"
eval "openssl pkcs12 -nodes -nocerts -out $2.pem -in $1.p12"
eval "cat $1.pem $2.pem > $3.pem"
// http://stackoverflow.com/questions/17535918/aes-gets-different-results-in-ios-and-java
- (NSData *)AES256EncryptWithKey:(NSString *)key {
// 'key' should be 32 bytes for AES256, will be null-padded otherwise
char keyPtr[kCCKeySizeAES256+1]; // room for terminator (unused)
bzero(keyPtr, sizeof(keyPtr)); // fill with zeroes (for padding)
// fetch key data
[key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
@m1entus
m1entus / CoreDataContextObserver.swift
Last active July 3, 2021 18:08
CoreDataContextObserver
//
// CoreDataContextWatcher.swift
// ContextWatcher
//
// Created by Michal Zaborowski on 10.05.2016.
// Copyright © 2016 Inspace Labs Sp z o. o. Spółka Komandytowa. All rights reserved.
//
import Foundation
import CoreData