Skip to content

Instantly share code, notes, and snippets.

View svenmuennich's full-sized avatar

Sven Münnich svenmuennich

View GitHub Profile
@svenmuennich
svenmuennich / Foo.swift
Created April 23, 2021 15:22
A Swift `Codable` type for representing nested data structures
internal class Foo: Codable {
internal struct CodingKey: Swift.CodingKey {
internal let stringValue: String
internal let intValue: Int?
internal init?(stringValue: String) {
self.stringValue = stringValue
self.intValue = Int(stringValue)
}
@svenmuennich
svenmuennich / install_shopware
Last active November 3, 2021 21:20
Install Shopware 5 without Ant/Java
#!/bin/bash
# Make sure to have a valid config.php ready before running this script!!!
# Check parameters
if [[ $# -ne 1 ]]; then
echo " Usage: $0 <app path>"
exit 1
fi
app_path=$1
import Foundation
import UIKit
struct ViewStyle<T> {
let style: (T) -> Void
}
let filled = ViewStyle<UIButton> {
$0.setTitleColor(.white, for: .normal)
$0.backgroundColor = .red
@svenmuennich
svenmuennich / run.sh
Created October 10, 2018 22:54
Fix whitespace
#!/bin/bash
# Convert tabs to spaces (https://stackoverflow.com/a/11094620/981846)
find . \( -name '*.m' -o -name '*.h' -o -name '*.swift' -o -name '*.pch' \) ! -type d -exec bash -c 'expand -t 4 "$0" > /tmp/e && mv /tmp/e "$0"' {} \;
# Trim trailing whitespace (https://stackoverflow.com/a/10711226/981846)
find . \( -name '*.m' -o -name '*.h' -o -name '*.swift' -o -name '*.pch' \) ! -type d -exec bash -c 'sed "s/[[:space:]]\{1,\}$//" "$0" > /tmp/e && mv /tmp/e "$0"' {} \;
@svenmuennich
svenmuennich / gist:b080220b3595ab1e3c2de115a04fd6cb
Created August 14, 2018 20:00
How to create a public and private key pair for RSA encryption
# 1. Generate a new RSA key pair (public and private key) with a 4096 bit long modulus.
# You can optionally pass e.g. '-aes256' to encrypt the key pair with a passphrase. The key
# pair will be saved as 'private.pem' ('pem' is just a container file format,
# see https://serverfault.com/questions/9708/what-is-a-pem-file-and-how-does-it-differ-from-other-openssl-generated-key-file).
openssl genrsa -out private.pem 4096
# 2. Extract the public key from the RSA key pair ('private.pem').
# The result is again saved in a 'pem' file, this time named 'public.pem'.
openssl rsa -in private.pem -outform PEM -pubout -out public.pem
@svenmuennich
svenmuennich / clear-purgeable-space.sh
Last active June 25, 2021 09:30
Clearing "purgeable" space on macOS High Sierra (e.g. before installing Windows 10 using BootCamp)
# 1. Check for any local time machine snapshots
tmutil listlocalsnapshots /
# 2. Ask time machine to free 100 GBs of local snapshots. Third parameter '4' probably means high priority (https://apple.stackexchange.com/a/398356)
tmutil thinlocalsnapshots / $((100 * 1024 * 1204 * 1024)) 4
# 3. Make sure that only a `(dataless)` snapshot exists
tmutil listlocalsnapshots /
# 4. List all mounted volumes and find the one mounted on '/' (probably '/dev/disk1s1')
@svenmuennich
svenmuennich / .profile
Last active November 22, 2018 08:53
A plan for setting up a new Mac for development
# Load NVM
export NVM_DIR="$HOME/.nvm"
. "/usr/local/opt/nvm/nvm.sh"
# ls coloring etc.
alias ls='ls -Ga'
# Fix Perl locale
export LC_CTYPE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
<?php
$referencingTableName = 's_plugin_viison_address_label_dispatch_configuration';
$referencingColumnName = 'dispatchId';
$prefix = 'fk';
$maxSize = 30;
$hash = implode('', array_map(function ($column) {
return dechex(crc32($column));
@svenmuennich
svenmuennich / dev_deps
Last active November 3, 2021 21:21
Toggles between composer installed and symlinked shared dependencies of Shopware 5 plugin.
#!/bin/bash
# Check parameters
if [[ $# -ne 2 ]]; then
echo " Usage: $0 <dev|prod> <plugin_path>"
exit 1
fi
mode=$1
plugin_path=$(cd $2 && pwd)
@svenmuennich
svenmuennich / UIViewController+Deselection.swift
Created June 4, 2016 03:10 — forked from ZevEisenberg/LICENSE
Smoothly deselect table and collection view cells on dismissal, including interactive dismiss and interactively-partially-dismiss-then-cancel-then-dismiss-again
extension UIViewController {
func rz_smoothlyDeselectRows(tableView tableView: UITableView?) {
let selectedIndexPaths = tableView?.indexPathsForSelectedRows ?? []
if let coordinator = transitionCoordinator() {
coordinator.animateAlongsideTransitionInView(parentViewController?.view, animation: { context in
selectedIndexPaths.forEach {
tableView?.deselectRowAtIndexPath($0, animated: context.isAnimated())
}