Skip to content

Instantly share code, notes, and snippets.

View vknabel's full-sized avatar

Valentin Knabel vknabel

View GitHub Profile
@vknabel
vknabel / p10k metal.zsh
Last active May 27, 2024 06:05
powerlevel10k prompts for metal, metalctl and cloudctl contexts
function prompt_metal_ctx() {
p10k segment -f white -t "$(metal ctx show-current)"
}
function prompt_metalctl_ctx() {
p10k segment -f white -t "$(metalctl ctx short)"
}
function prompt_cloudctl_ctx() {
p10k segment -f white -t "$(cloudctl ctx short)"
}
@vknabel
vknabel / bubbletea-nav-page.go
Last active June 3, 2022 10:37
A stack navigation model for bubbletea
package nav
import tea "github.com/charmbracelet/bubbletea"
type NavPage struct {
windowSize *tea.WindowSizeMsg
previous tea.Model
current tea.Model
}
function psqlhere() {
local CURRENT_BASENAME=$(basename "$PWD")
echo -e "\e[1;32mDATABASE_URL postgres://$CURRENT_BASENAME:$CURRENT_BASENAME@localhost/$CURRENT_BASENAME\e[0m";
docker run --rm \
--env POSTGRES_USER=$CURRENT_BASENAME \
--env POSTGRES_DB=$CURRENT_BASENAME \
--env POSTGRES_PASSWORD=$CURRENT_BASENAME \
--publish 5432:5432 \
--name "psql-$CURRENT_BASENAME" \
--tty --interactive \
@vknabel
vknabel / Marathonfile
Last active March 23, 2017 21:35
Marathon Script handling paths. MIT License
https://github.com/JohnSundell/Files.git
@vknabel
vknabel / RxBlockingResult.swift
Last active January 11, 2017 17:47
Wraps RxBlocking for Result
import RxBlocking
import RxSwift
import Result
/// `BlockingResultObservables` provide convenience methods for gaining a `Result` out of `Observables`.
///
/// It may be useful for testing purposes
/// or for preventing CLIs to be terminated too early,
/// but usually you should not use it in production code.
///
@vknabel
vknabel / rock-install.sh
Last active January 10, 2017 11:40
Installs rock for CI usage
#!/bin/bash
export ROCK_PATH="$HOME/.rock" # default
export PATH="$PATH:./.rock/bin:$ROCK_PATH/bin"
if [ -f "$ROCK_PATH/sources/rock" ]; then
cd $ROCK_PATH/sources/rock
git pull
else
git clone --depth 1 https://github.com/vknabel/rock $ROCK_PATH/sources/rock
@vknabel
vknabel / AnyHashable+Custom.swift
Created November 11, 2016 19:44
Allows you to use any hash function in Sets/Dictionaries (Swift 3.0)
public extension AnyHashable {
public init(value: V, compare: @escaping (V, V) -> Bool, hash: @escaping (V) -> Int) {
self.init(CustomHashable(value: value, compare: compare, hash: hash))
}
}
import UIKit
public extension UIImage {
public func imageWithColor(color: UIColor) -> UIImage {
UIGraphicsBeginImageContextWithOptions(self.size, false, self.scale)
let context: CGContextRef = UIGraphicsGetCurrentContext()
CGContextTranslateCTM(context, 0, self.size.height)
CGContextScaleCTM(context, 1.0, -1.0)
import CoreData
/**
* This is a generic source for all CoreData based sources. Subclass to focus on essentials.
*/
public class CoreDataSource {
let modelURL: NSURL
let storeURL: NSURL
import UIKit
import AVFoundation
public extension AVCaptureVideoOrientation {
public init(interfaceOrientation: UIInterfaceOrientation) {
switch interfaceOrientation {
case .Unknown:
self = .LandscapeLeft
case .Portrait: