Skip to content

Instantly share code, notes, and snippets.

View shakemno's full-sized avatar

Manolis Pahlke shakemno

View GitHub Profile
@shakemno
shakemno / Withable.swift
Created October 22, 2022 19:26 — forked from nicklockwood/Withable.swift
Withable.swift
/// Withable is a simple protocol to make constructing
/// and modifying objects with multiple properties
/// more pleasant (functional, chainable, point-free)
public protocol Withable {
init()
}
public extension Withable {
/// Construct a new instance, setting an arbitrary subset of properties
init(with config: (inout Self) -> Void) {
@shakemno
shakemno / script-template.sh
Created December 5, 2021 02:51 — forked from m-radzikowski/script-template.sh
Minimal safe Bash script template - see the article with full description: https://betterdev.blog/minimal-safe-bash-script-template/
#!/usr/bin/env bash
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -p param_value arg1 [arg2...]
@shakemno
shakemno / StateMachine.swift
Created May 17, 2021 21:21 — forked from khanlou/StateMachine.swift
A state machine where invalid transitions can't compile
protocol State {}
struct Transition<From: State, To: State> {
let transition: () -> To
}
struct Machine<CurrentState: State> {
var state: CurrentState
@shakemno
shakemno / unidirectional.swift
Created May 5, 2021 18:25 — forked from atimca/unidirectional.swift
Tiny implementation of Unidirectional Architecture with Query based SideEffects.
import Combine
import Foundation
func loadNewsTitles() -> AnyPublisher<[String], Never> {
["title1", "title2"]
.publisher
.delay(for: .microseconds(500), scheduler: DispatchQueue.main)
.collect()
.eraseToAnyPublisher()
}
import Foundation
import XCPlayground
/*:
# Reflux
*/
//: Interfaces
protocol State {
init()
var userState: UserState {get}
@shakemno
shakemno / gist:8a48eb935c2e9cfc995ef0d7942e50e8
Created April 21, 2021 22:43 — forked from jessedc/gist:12a74aff88d06e669cf1c9999408c62c
xcodebuild --help ExportOptions.plist organised in a more logical way
ExportOptions.plist - Options in a better order
Xcodebuild manfile says the following
> **Distributing Archives**
> The -exportArchive option specifies that xcodebuild should distribute the archive specified by -archivePath using the options specified by
> -exportOptionsPlist. xcodebuild -help can print the full set of available inputs to -exportOptionsPlist. The product can either be uploaded to Apple or
> exported locally. The exported product will be placed at the path specified by -exportPath.
The following is the list of settings (as of Xcode 10.1) output by `xcodebuild --help` but in a more logical order.
@shakemno
shakemno / States-v3.md
Created April 3, 2021 00:02 — forked from andymatuschak/States-v3.md
A composable pattern for pure state machines with effects (draft v3)

A composable pattern for pure state machines with effects

State machines are everywhere in interactive systems, but they're rarely defined clearly and explicitly. Given some big blob of code including implicit state machines, which transitions are possible and under what conditions? What effects take place on what transitions?

There are existing design patterns for state machines, but all the patterns I've seen complect side effects with the structure of the state machine itself. Instances of these patterns are difficult to test without mocking, and they end up with more dependencies. Worse, the classic patterns compose poorly: hierarchical state machines are typically not straightforward extensions. The functional programming world has solutions, but they don't transpose neatly enough to be broadly usable in mainstream languages.

Here I present a composable pattern for pure state machiness with effects,

@shakemno
shakemno / parseflags.sh
Created March 28, 2021 18:13 — forked from bxparks/parseflags.sh
Simple Bash Shell Command Line Processing Template
#!/bin/bash
#
# Self-contained command line processing in bash that supports the
# minimal, lowest common denominator compatibility of flag parsing.
# -u: undefined variables is an error
# -e: exit shell on error
set -eu
function usage() {
@shakemno
shakemno / process.sh
Created March 28, 2021 16:44 — forked from krzysztofzablocki/process.sh
3rd party tooling processing script
#!/bin/zsh
cd "$(dirname "$0")/.."
if [[ -n "$CI" ]] || [[ $1 == "--fail-on-errors" ]] ; then
FAIL_ON_ERRORS=true
echo "Running in --fail-on-errors mode"
ERROR_START=""
COLOR_END=""
INFO_START=""
@shakemno
shakemno / xccov-to-sonarqube-generic.sh
Created March 28, 2021 14:11 — forked from z-turk3/xccov-to-sonarqube-generic.sh
Extension to the sonarqube script for converting xcode code coverage to generic report found at: https://github.com/SonarSource/sonar-scanning-examples/tree/master/swift-coverage
#!/usr/bin/env bash
set -euo pipefail
function convert_file {
local xccovarchive_file="$1"
local file_name="$2"
local xccov_options="$3"
echo " <file path=\"$file_name\">"
xcrun xccov view $xccov_options --file "$file_name" "$xccovarchive_file" | \
sed -n '