Skip to content

Instantly share code, notes, and snippets.

View MartinP7r's full-sized avatar
📱

Martin Pfundmair MartinP7r

📱
View GitHub Profile
@MartinP7r
MartinP7r / libdispatch-efficiency-tips.md
Created September 17, 2020 15:28 — 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

@MartinP7r
MartinP7r / GoogleSignInService.swift
Last active June 24, 2018 06:16
medium_post_05
class GoogleSignInService: NSObject, SignInService, GIDSignInDelegate, GIDSignInUIDelegate {
// intermediary closure to be called when sign-in finishes
var signedIn: ((String) -> Void)?
func setup() { /* (...) */ }
func signIn(_ completion: @escaping (String) -> Void) {
// hand own completion block to intermediary closure
@MartinP7r
MartinP7r / GIDSignIn.h
Created June 24, 2018 00:20
medium_post_04
// Starts the sign-in process. The delegate will be called at the end of this process.
// (...)
- (void)signIn;
// The sign-in flow has finished and was successful if |error| is |nil|.
- (void)signIn:(GIDSignIn *)signIn
didSignInForUser:(GIDGoogleUser *)user
withError:(NSError *)error;
@MartinP7r
MartinP7r / Authenticator.swift
Last active June 24, 2018 06:17
medium_post_03
class Authenticator {
let userDataService = UserDataService()
func auth(using signInService: SignInService,
_ completion: @escaping (_ user: User?) -> Void) {
signInService.signIn { token in
userDataService.load(forToken: token) { user in
completion(user) // note: error handling omitted for brevity
@MartinP7r
MartinP7r / SomeSignInService.swift
Last active June 23, 2018 12:36
medium_post_002
class SomeSignInService: SignInService {
init() {
// do whatever the provider needs to be set up
}
func signIn(_ completion: @escaping (String?) -> Void) {
// call the sign in service and receive a token
completion(token)
}
@MartinP7r
MartinP7r / SignInService.swift
Last active June 23, 2018 23:03
medium_post
protocol SignInService {
func signIn(_ completion: @escaping (_ id: String?) -> Void)
func signOut()
}
{"lastUpload":"2021-10-30T05:17:01.742Z","extensionVersion":"v3.4.3"}
@MartinP7r
MartinP7r / createShortcuts.vbs
Last active August 29, 2015 14:02
creates shortcuts in ShortcutFolder for all Application files (*.exe) in all level-1 subfolders of the specified target folders
'+-------------------------------------+
'| @author: Martin Pfundmair |
'| @version: 1.0 |
'| @date: 2014-05-31 |
'| |
'| $cript: |
'| creates shortcuts in ShortcutFolder |
'| for all Application files (*.exe) |
'| in all level-1 subfolders of the |
'| specified target folders |
@MartinP7r
MartinP7r / IsLetter.bas
Created May 26, 2014 10:25
checks if the String consists only of letters (A-Z, a-z) or not
'source: http://techniclee.wordpress.com/2010/07/21/isletter-function-for-vba/
Function IsLetter(strValue As String) As Boolean
Dim intPos As Integer
For intPos = 1 To Len(strValue)
Select Case Asc(Mid(strValue, intPos, 1))
Case 65 To 90, 97 To 122
IsLetter = True
Case Else
IsLetter = False
Exit For
@MartinP7r
MartinP7r / ERParser.java
Last active August 29, 2015 14:01
Parses ECB €-exchange rates feed into objects arraylist-list <EuroExchangeRate> "ratesList"
package exchangeRateApp;
import java.io.InputStream;
import java.math.BigDecimal;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import javax.swing.text.html.HTMLDocument.HTMLReader.IsindexAction;
import javax.xml.parsers.DocumentBuilder;