Skip to content

Instantly share code, notes, and snippets.

Avatar
👨‍💻
typing...

Fedor Korotkov fkorotkov

👨‍💻
typing...
View GitHub Profile
@fkorotkov
fkorotkov / .cirrus.yml
Created Jul 10, 2020
Cache SwiftDoc binary on Cirrus CI
View .cirrus.yml
task:
name: Test Swift-Doc 🎉
osx_instance:
image: catalina-xcode
env:
SWIFT_DOC_VERSION: 1.0.0-beta.3
PATH: $PATH:$CIRRUS_WORKING_DIR/.cache/swift-doc-bin/
swiftdoc_install_cache:
folder: .cache/swift-doc-bin
@fkorotkov
fkorotkov / BatchLoaderStep1.kt
Last active May 12, 2020
Code sample for a blog post
View BatchLoaderStep1.kt
class BatchLoader<ID, T>(
/* ... */
) : Loader<ID, T> {
private val requests = Channel<LoadRequest<ID, T>>(Channel.UNLIMITED) // UNLIMITED allows to queue requests
override suspend fun loadByIds(ids: Set<ID>): Map<ID, T> {
val request = LoadRequest<ID, T>(ids) // create a request
requests.send(request) // queue the request
return request.result.await() // await for the request to be fulfilled
}
@fkorotkov
fkorotkov / Loader.kt
Created May 12, 2020
Loader code sample for a blog post
View Loader.kt
interface Loader<ID, T> {
suspend fun loadByIds(ids: Set<ID>): Map<ID, T>
}
@fkorotkov
fkorotkov / BatchLoaderFinal.kt
Created May 12, 2020
Code samples for a blog post
View BatchLoaderFinal.kt
class BatchLoader<ID, T>(
poolSize: Int = 8,
private val keyBatchSizeLimit: Int = 100,
private val delegateLoader: Loader<ID, T>
) : Loader<ID, T>, CoroutineScope {
override val coroutineContext: CoroutineContext = Executors.newFixedThreadPool(poolSize).asCoroutineDispatcher()
private val requests = Channel<LoadRequest<ID, T>>(Channel.UNLIMITED) // UNLIMITED allows to queue requests
private inner class RequestWorker {
View Loader.kt
interface Loader<ID, T> {
suspend fun loadByIds(ids: Set<ID>): Map<ID, T>
}
@fkorotkov
fkorotkov / .cirrus.yml
Created Jun 16, 2019
Cirrus CI for NodeJS on Windows
View .cirrus.yml
build_task:
windows_container:
image: cirrusci/windowsservercore:2019
os_version: 2019
node_modules_cache:
folder: node_modules
fingerprint_script: type yarn.lock
install_script: choco install -y nodejs yarn
build_script:
- refreshenv
View nanka.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>attributeSetting</key>
<integer>1</integer>
<key>choiceAttribute</key>
<string>selected</string>
<key>choiceIdentifier</key>
@fkorotkov
fkorotkov / chamber.sh
Last active Jun 8, 2021
Script to run a command in an isolation
View chamber.sh
#!/usr/bin/env bash
set -e
# list of Nix packages to install
NIX_PACKAGES="darwin.shell_cmds"
XCODE_DERIVED_DATA="$HOME/Library/Developer/Xcode/DerivedData"
WORKING_DIRECTORY=$PWD
@fkorotkov
fkorotkov / base-chamber.sb
Created Apr 10, 2018
Base security profile for sandboxing applications on Mac OS
View base-chamber.sb
(version 1)
(debug deny)
;; by default deny everything
(deny default)
;; allow sending signals to itself and processes in the same group
(allow signal (target same-sandbox))
;; allow outbound internet
@fkorotkov
fkorotkov / gcr_auth_example.sh
Created Feb 26, 2018
JSON key file to Google Container Registry's HTTP API
View gcr_auth_example.sh
#!/usr/bin/env bash
GCP_PROJECT_ID=...
MY_IMAGE=...
USERNAME=_json_key
PASSWORD=$(cat keyfile.json)
TOKEN=$(echo "$USERNAME:$PASSWORD" | base64)