Skip to content

Instantly share code, notes, and snippets.

View krzyzanowskim's full-sized avatar

Marcin Krzyzanowski krzyzanowskim

View GitHub Profile
@krzyzanowskim
krzyzanowskim / define_for_all_pods
Last active March 26, 2020 09:42
Disable NSLog with all CocoaPods with post_install hook.
post_install do | installer |
print "Updating #{installer.sandbox.target_support_files_root}/Pods/Pods-environment.h\n"
open("#{installer.sandbox.target_support_files_root}/Pods/Pods-environment.h","a") do |file|
file.puts <<EOF
// Disable logs
#ifndef DEBUG
#define NSLog(...)
#endif
EOF
end

Keybase proof

I hereby claim:

  • I am krzak on github.
  • I am krzyzanowskim (https://keybase.io/krzyzanowskim) on keybase.
  • I have a public key whose fingerprint is BA96 CBDD 1862 7D9A 6884 AA0A 979E 4B03 DFFE 30C6

To claim this, I am signing this object:

### Keybase proof
I hereby claim:
* I am krzyzanowskim on github.
* I am krzyzanowskim (https://keybase.io/krzyzanowskim) on keybase.
* I have a public key whose fingerprint is BA96 CBDD 1862 7D9A 6884 AA0A 979E 4B03 DFFE 30C6
To claim this, I am signing this object:
@krzyzanowskim
krzyzanowskim / C-function-pointer-invalid-in-swift
Last active August 29, 2015 14:03
Valid C function pointer declaration is invalid for Swift
// I found that when intagrate C API, something strange happending with function declarations
struct testswitf
{
int (*va_args)(int *I)
};
// end with strange error
// <unknown>:0: error: file.h:100: expected ')'
// <unknown>:0: note: file.h:100: to match this '('
import UIKit
import CoreText
extension UIFont {
typealias Feature = (type: Int, selector: Int)
struct Features {
static var ProportionalNumbers: Feature = (kNumberSpacingType, kProportionalNumbersSelector)
static var AlternatePunctuation: Feature = (kCharacterAlternativesType, 1) // Magic!
// Add more...
@krzyzanowskim
krzyzanowskim / shift_bits_with_truncation
Last active October 9, 2019 20:17
Bit shifting with overflow protection using overflow operator "&"
//
// IntExtension.swift
// CryptoSwift
//
// Created by Marcin Krzyzanowski on 12/08/14.
// Copyright (C) 2014 Marcin Krzyżanowski <marcin.krzyzanowski@gmail.com>
// This software is provided 'as-is', without any express or implied warranty.
//
// In no event will the authors be held liable for any damages arising from the use of this software.
//
@krzyzanowskim
krzyzanowskim / variable_with_class_constant_length
Last active August 29, 2015 14:06
How to use class constant to initialize variable - solution is use lazy variable
import Foundation
class Foo {
let length = 255
// !!! not like this because self.length can't be used here
// var arrayConstantLength = [Byte](count:self.length, repeatedValue:0)
// but like this (with lazy I can use self.length constant)
lazy var arrayConstantLength:[Byte] = {
@krzyzanowskim
krzyzanowskim / shift_left_generic
Last active August 29, 2015 14:06
Shift bits to the left - Generic version. This is the most advanced Generic function I ever wrote (req: extensions, protocol, funcs)
// Playground - noun: a place where people can play
import Foundation
/** Protocol and extensions for integerFromBitsArray. Bit hakish for me, but I can't do it in any other way */
protocol Initiable {
init(_ v: Int)
init(_ v: UInt)
}
@krzyzanowskim
krzyzanowskim / remove_duplicates_reduce
Last active August 29, 2015 14:06
Remove array duplicates with reduce()
let array = ["P","Q","R","S","T","P","R","A","T","B","C","P","P","P","P","P","C","P","P","J"]
let unique = array.reduce([String](), combine: { (array, value) -> [String] in
var result = array
if (!contains(array, value)) {
result.append(value)
}
return result
})
@krzyzanowskim
krzyzanowskim / aes128_commoncrypt
Last active August 29, 2015 14:13
AES128 category for NSData using CommonCrypto.
// Marcin Krzyżanowski
#import <CommonCrypto/CommonCryptor.h>
@interface NSData (AES)
- (NSData *)AES128EncryptWithKey:(NSString *)key iv:(NSString *)iv;
@end
@implementation NSData (AES)