Skip to content

Instantly share code, notes, and snippets.

View igrrik's full-sized avatar

igrrik

  • Global
  • London
View GitHub Profile
@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active October 25, 2025 06:01
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

@nathanfjohnson
nathanfjohnson / String+HTML.swift
Last active November 23, 2021 15:09 — forked from mwaterfall/StringExtensionHTML.swift
Decoding HTML Entities in Swift 4
// Swift 4
// Check out the history for contributions and acknowledgements.
extension String {
/// Returns a new string made by replacing all HTML character entity references with the corresponding character.
///
/// - Returns: decoded string
func decodingHTMLEntities() -> String {
var result = String()
var position = startIndex
@adamcichy
adamcichy / ImageDarkness.swift
Created March 15, 2017 15:28
Determine if a UIImage is generally dark or generally light in Swift 3
extension CGImage {
var isDark: Bool {
get {
guard let imageData = self.dataProvider?.data else { return false }
guard let ptr = CFDataGetBytePtr(imageData) else { return false }
let length = CFDataGetLength(imageData)
let threshold = Int(Double(self.width * self.height) * 0.45)
var darkPixels = 0
for i in stride(from: 0, to: length, by: 4) {
let r = ptr[i]
@morhekil
morhekil / ios-how-to-communicate-with-iframes.md
Last active January 24, 2018 14:58 — forked from wayne5540/ios-how-to-communicate-with-iframes.md
This article is to show how to inject JavaScript into iframs under iOS web view and so we can communicate with it.

[iOS - Swift] How to communicate with iFrames inside WebView

One of the core technologies at the heart of Onefill is its ability to auto-fill even the most complex form on a website with 100% precision, with a single tap. And the techology that built does allow us to do just that, but with one exception - iframes.

And while you might think that iframes are a thing of the past (who would use them these days, right?) - the reality is that they're often powering some of the most critical piece of functionality there is on online store - its payment

#import <Foundation/Foundation.h>
typedef void (^KeyboardVisabilityWillChange)(BOOL isVisible);
@interface DBO_KeyboardManager : NSObject
@property (assign, nonatomic, readonly) CGRect keyboardFrame;
@property (strong, nonatomic, readonly) NSNumber *animationDuration;
@property (nonatomic, copy) KeyboardVisabilityWillChange keyboardVisabilityChange;
@NinoScript
NinoScript / EnumNSCoding.swift
Last active December 2, 2019 10:47
NSCoding a Swift Enum
//: Playground - noun: a place where people can play
import Cocoa
enum Enum {
case SimpleCase
case AssociatedValue(String)
case AnotherAssociated(Int)
}
extension Enum {
@satoshin2071
satoshin2071 / PatternMatchingPart4.swift
Created May 24, 2016 08:37
Swift Pattern Matching, Part 4: if case, guard case, for case. Shakyo practice.
/*
From http://alisoftware.github.io/swift/pattern-matching/2016/05/16/pattern-matching-4/
Shakyo practice
Pattern Matching, Part 4: if case, guard case, for case
*/
import XCPlayground
@gonzalezreal
gonzalezreal / ios-cell-registration-swift.md
Last active March 5, 2025 02:07
iOS Cell Registration & Reusing with Swift Protocol Extensions and Generics

iOS Cell Registration & Reusing with Swift Protocol Extensions and Generics

A common task when developing iOS apps is to register custom cell subclasses for both UITableView and UICollectionView. Well, that is if you don’t use Storyboards, of course.

Both UITableView and UICollectionView offer a similar API to register custom cell classes:

public func registerClass(cellClass: AnyClass?, forCellWithReuseIdentifier identifier: String)
public func registerNib(nib: UINib?, forCellWithReuseIdentifier identifier: String)
@jwliechty
jwliechty / exampleWithFindExex.sh
Last active August 11, 2021 20:29
Example of how to use find exec calling a function.
#/bin/bash
export MY_EXPORTED_VAR="Boo Yeah!"
MY_NON_EXPORTED_VAR="You won't see this one!"
# This script was inspired by the answer to the question in
# http://unix.stackexchange.com/questions/50692/executing-user-defined-function-in-a-find-exec-call
runFindCommand(){
# 'myFunct "$@"' will call the function with the arguments passed into the shell
@arturlector
arturlector / ios-questions-interview.md
Last active March 3, 2025 15:02
Вопросы на собеседование iOS разработчика.

Вопросы на собеседование iOS разработчика (дополненное издание):

General:

  • Что такое полиморфизм?

  • Что такое *инкапсуляция? Что такое *нарушение инкапсуляции?

  • Чем абстрактный класс отличается от интерфейса?

  • Расскажите о паттерне MVC. Чем отличается пассивная модель от активной?