Skip to content

Instantly share code, notes, and snippets.

View DimaRU's full-sized avatar

Dmitriy Borovikov DimaRU

  • Lúnaturco, Dor Daedeloth
View GitHub Profile
@DimaRU
DimaRU / libdispatch-efficiency-tips.md
Created November 7, 2024 15:06 — 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

@DimaRU
DimaRU / libdispatch-efficiency-tips.md
Created November 7, 2024 15:06 — 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

$DOCC_BRANCH="docc"
git switch --orphan $DOCC_BRANCH
mkdir docs
touch docs/.nojekyll
git commit --allow-empty -m "docc initial commit"
git push -u origin $DOCC_BRANCH
@DimaRU
DimaRU / 00-docker-shorewall.md
Created January 5, 2024 17:06 — forked from lukasnellen/00-docker-shorewall.md
setup shorewall for docker networking beyond the default bridge network, e.g., for docker-compose

Docker(-compose) with shorewall

The shorewall documentation explains in http://shorewall.org/Docker.html how to configure shorewall for use with docker. The problem with the configuration is that it only allows connections from the host to the main bridge docker0. Connections to other networks on dynamically created bridges, with names starting by default with br-, is blocked. Instead of the recommended contents of /etc/shorewall/interfaces, use wild-card interface names as follows:

#ZONE	INTERFACE	OPTIONS
#dock	docker0		bridge     # disabled default recommendation
dock 	docker0		physical=docker+,routeback=1
dock 	br		physical=br-+,routeback=1
@DimaRU
DimaRU / UnsafePointer Converter.swift
Created November 19, 2023 17:30 — forked from codelynx/UnsafePointer Converter.swift
[swift] Unsafe Pointer conversion
//
// Swift UnsafePointer converter
// Kaz Yoshikawa
//
// These code demonstrates how to convert swift pointers to the other forms of pointers.
//
// Source:
// Swift の Array やら ArraySlice やらポインタの変換まとめ
// https://qiita.com/Satachito/items/4c39c9b06304e4d86660
//
func loadWebArchive(named name: String, into webView: WKWebView) {
let fileURL = self.webArchiveDirectoryURL.appendingPathComponent("\(name).webarchive")
do {
let archiveData = try Data(contentsOf: fileURL)
webView.load(archiveData, mimeType: "application/x-webarchive", characterEncodingName: "", baseURL: fileURL)
print("Web archive loaded from: \(fileURL.path)")
} catch {
print("Error loading web archive: \(error.localizedDescription)")
}
@DimaRU
DimaRU / example-clean.sh
Created May 8, 2022 08:58
Testing PackageBuildInfoExample
#!/bin/bash
set -x
git clone https://github.com/DimaRU/PackageBuildInfoExample
cd PackageBuildInfoExample
swift run
touch a
swift package clean
swift run
git add a
swift package clean
@DimaRU
DimaRU / Setup GCC and CLANG Toolchains.md
Created May 28, 2021 08:17 — forked from bhaskarvk/Setup GCC and CLANG Toolchains.md
Proper GCC (vers. 5/6/7) & LLVM/CLANG (vers. 4/5) Toolchain Setup on Ubuntu/Linux Mint

This approach uses update-alternatives to manage GCC and LLVM/CLANG C/C++ compiler toolchains. Although tested on Linux Mint 18.3, this approach should work on any Debian based distro or for that matter any Linux distro with update-alternatives support, provided the packages are installed correctly.

There are 3 files

  • gcc-alternatives.sh installs GCC versions 5/6/7 and sets up alternatives for gcc/g++/cpp/gfortran.
  • llvm-clang-alternatives.sh installs LLVM and CLANG versions 4/5 and sets up alternatives for various LLVM and CLANG programs including clang and clang++.
  • cc-alternatives.sh sets up alternatives for the cc, cxx, and the ld commands. This script can be used to change systemwide default compiler/linker combination to either GCC or CLANG.

Once these scripts are run you can change the system GCC/CLANG versions by running sudo update-alternatives --config gcc|clang. To change the default compiler/linker combo used by t

@DimaRU
DimaRU / Makefile
Created January 15, 2021 14:53
Универсальный Makefile для плагина VSCode Easy C++ Projects
CC := clang
CFLAGS := -Wall -Wextra -g
BIN := bin
SRC := src
INCLUDE := include
LIB := lib
LFLAGS :=
LIBRARIES :=
@DimaRU
DimaRU / Brewfile
Last active January 14, 2021 17:05
School21 environment prepare
# Powerful, clean, object-oriented scripting language
brew "ruby"
# Terminal-based visual file manager
brew "midnight-commander"
# Internet file retriever
brew "wget"
# VSCode
cask "visual-studio-code"
cask "tunnelblick"
cask "iterm2"