Skip to content

Instantly share code, notes, and snippets.

@bobgodwinx
bobgodwinx / libdispatch-efficiency-tips.md
Created December 22, 2023 10:47 — forked from tclementdev/libdispatch-efficiency-tips.md
Making efficient use of the libdispatch (GCD)

libdispatch efficiency tips

The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).

My take-aways are:

  • You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.

  • Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse

@bobgodwinx
bobgodwinx / EncryptAESWithPHP
Last active April 30, 2018 15:51 — forked from krzyzanowskim/EncryptAESWithPHP
How to encrypt data with padding usign AES cipher, complatible with CryptoSwift defaults.
// Marcin Krzyżanwski
// Code for https://github.com/krzyzanowskim/CryptoSwift/issues/20
// PHP
///Please refer to issue: https://github.com/krzyzanowskim/CryptoSwift/issues/20
function encrypt($plaintext, $key, $iv) {
$ciphertext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $plaintext, MCRYPT_MODE_CBC, $iv);
return base64_encode($ciphertext);
}
@bobgodwinx
bobgodwinx / swift-compatible-php-aes-encryption-using-mcrypt.php
Created April 30, 2018 15:48 — forked from tlarevo/swift-compatible-php-aes-encryption-using-mcrypt.php
Swift compatible AES Encryption and Decryption with PHP and mcrypt
<?php
// Credit should be given to;
// https://gist.github.com/bradbernard/7789c2dd8d17c2d8304b#file-php-encyrption
// https://gist.github.com/krzyzanowskim/043be69ab3ba9fd5ba58#file-encryptaeswithphp
$data = '{"verification_code":"123456"}';
$key = '1234567890123456';
function aesEncrypt($data, $key) {
$data = addPadding($data);
@bobgodwinx
bobgodwinx / php-compatible-swift-aes-encryption-using-cryptoswift.swift
Last active April 30, 2018 15:47 — forked from tlarevo/php-compatible-swift-aes-encryption-using-cryptoswift.swift
PHP compatible AES Encryption and Decryption with Swift and CryptoSwift
// Credit should be given to;
// https://gist.github.com/yutelin/f4f66e0c78474db1de51#file-string-aes-swift
// https://gist.github.com/bradbernard/2a7af4c2200cb3794768#file-swift-encryption
// And most importantly to https://github.com/krzyzanowskim/CryptoSwift
import Foundation
import CryptoSwift
extension String {
@bobgodwinx
bobgodwinx / NSData+AES.h
Created December 31, 2015 08:23 — forked from matsuda/NSData+AES.h
Objective-C code for encrypt and decrypt by AES-128 encryption.
/**
http://mythosil.hatenablog.com/entry/20111017/1318873155
http://blog.dealforest.net/2012/03/ios-android-per-aes-crypt-connection/
*/
@interface NSData (AES)
- (NSData *)AES128EncryptedDataWithKey:(NSString *)key;
- (NSData *)AES128DecryptedDataWithKey:(NSString *)key;
- (NSData *)AES128EncryptedDataWithKey:(NSString *)key iv:(NSString *)iv;