Skip to content

Instantly share code, notes, and snippets.

View krzyzanowskim's full-sized avatar

Marcin Krzyzanowski krzyzanowskim

View GitHub Profile

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 '('
@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)
@krzyzanowskim
krzyzanowskim / NumberOfBits.swift
Last active August 29, 2015 14:14
Calculate number of bits for Big Integer
// Playground - noun: a place where people can play
import Foundation
func numberOfBits(bytes:[Byte]) -> Int {
if (bytes.count == 0) {
return 0;
}
var toRemove = 0;
@krzyzanowskim
krzyzanowskim / switf_neste_function_self
Created February 25, 2015 14:26
Swift nested function and variable reference
class Foo {
var some:String = "string"
func One() {
func Nested(weakSelf:Foo) {
if (weakSelf.some == "integer") { // no error
}
}
@krzyzanowskim
krzyzanowskim / swift_crash
Last active August 29, 2015 14:16
Swift crash. Initializer on protocol.
// Version 6.3 (6D532l)
protocol Proto {
init()
}
struct S1: Proto {
init() {}
}