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);
@m1entus
m1entus / gist:e52386c9b3d1ff7307d9
Last active December 3, 2015 09:54 — forked from zetachang/gist:4111314
Instruction on adding a Acknowledgements Settings.bundle
  • To add Settings.bundle in Xcode. Command N and in Resource, choose Settings Bundle .
  • Open Root.plist in source code, paste the code below to replace it,
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>PreferenceSpecifiers</key>
	
set -ex
[ "$ACTION" = build ] || exit 0
[ "$BUILD_VARIANTS" = "normal" ] || exit 0
[ "$CONFIGURATION" = "Release" ] || exit 0
dir="$TEMP_FILES_DIR/disk"
dmg="$HOME/Desktop/$PROJECT_NAME.dmg"
rm -rf "$dir"
@m1entus
m1entus / aes128.m
Created September 19, 2014 12:42
AES128 endryption
- (NSData *)AES128EncryptWithData:(NSData *)data {
NSUInteger dataLength = [self length];
//See the doc: For block ciphers, the output size will always be less than or
//equal to the input size plus the size of one block.
//That's why we need to add the size of one block here
size_t bufferSize = dataLength + kCCBlockSizeAES128;
void *buffer = malloc(bufferSize);
@m1entus
m1entus / objc_setAssociatedObject.swift
Last active August 29, 2015 14:04
objc_setAssociatedObject.swift
var imageRequestOperationKey = "imageRequestOperationPointer"
let imageRequestOperationPointer = UnsafePointer<String>(COpaquePointer(&imageRequestOperationKey))
extension UIImageView {
func bw_imageRequestOperation() -> AFHTTPRequestOperation {
return objc_getAssociatedObject(self, imageRequestOperationPointer) as AFHTTPRequestOperation
}
func bw_setImageRequestOperation(operation :AFHTTPRequestOperation?) {
@m1entus
m1entus / sortBtProperty.swift
Created July 23, 2014 10:00
Swift generic function sorting by object property
func sortByProperty<T: NSObject>(array: [T], property: String, ascending: Bool) -> [T] {
var sortedBooks = [T](array)
sortedBooks.sort { element1, element2 in
var value1: AnyObject! = ""
var value2: AnyObject! = ""
if element1.respondsToSelector(Selector(property)) {
value1 = element1.valueForKey(property)
@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
}
// 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];
@implementation NSDictionary (QuickLook)
- (id)debugQuickLookObject
{
NSData *data = [NSJSONSerialization dataWithJSONObject:self options:NSJSONWritingPrettyPrinted error:nil];
NSString *JSONString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSString *embedHTML = [NSString stringWithFormat:@"<html><head></head><body><pre>%@</pre></body></html>",JSONString];
@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"