Skip to content

Instantly share code, notes, and snippets.

Avatar

Marcin Krzyzanowski krzyzanowskim

View GitHub Profile
View keybase.md

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:

View gist:9f4ee16db9d45eab0128
### 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 Aug 29, 2015
Valid C function pointer declaration is invalid for Swift
View C-function-pointer-invalid-in-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 Aug 29, 2015
How to use class constant to initialize variable - solution is use lazy variable
View variable_with_class_constant_length
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 Aug 29, 2015
Shift bits to the left - Generic version. This is the most advanced Generic function I ever wrote (req: extensions, protocol, funcs)
View shift_left_generic
// 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 Aug 29, 2015
Remove array duplicates with reduce()
View remove_duplicates_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 Aug 29, 2015
AES128 category for NSData using CommonCrypto.
View aes128_commoncrypt
// 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 Aug 29, 2015
Calculate number of bits for Big Integer
View NumberOfBits.swift
// 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 Feb 25, 2015
Swift nested function and variable reference
View switf_neste_function_self
class Foo {
var some:String = "string"
func One() {
func Nested(weakSelf:Foo) {
if (weakSelf.some == "integer") { // no error
}
}
@krzyzanowskim
krzyzanowskim / swift_crash
Last active Aug 29, 2015
Swift crash. Initializer on protocol.
View swift_crash
// Version 6.3 (6D532l)
protocol Proto {
init()
}
struct S1: Proto {
init() {}
}