Skip to content

Instantly share code, notes, and snippets.

View raphaeltraviss's full-sized avatar

Raphael Traviss raphaeltraviss

View GitHub Profile
@raphaeltraviss
raphaeltraviss / gist:8923e568e3db1a3dc6afe370c8f22aa1
Created October 24, 2023 15:30
Hammerspoon Four Sides Tiling
hs.hotkey.bind({"ctrl", "shift", "cmd"}, "Left", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x
f.y = max.y
f.w = max.w / 2
f.h = max.h
@raphaeltraviss
raphaeltraviss / pbresize
Created June 28, 2023 16:00
macOS command to resize a hi-res image in the pasteboard to a normal size image, for pasting into applications that don't handle HPDI
#!/bin/bash
# Usage:
# copy image to pasteboard via CMD-C
# then call pbresize on command line
# or call with a custom scale e.g. pbresize 0.7
SCALE_FACTOR=${1:-0.5}
pngpaste /tmp/ss.png
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@raphaeltraviss
raphaeltraviss / .zshrc
Last active January 18, 2021 18:06
Zsh completion for tmuxinator projects that take a file path as their first argument
# add command and project completion to tmuxinator
# add custom file path completion to your specific “my_project” project
# use this inside a ~/.tmuxinator/my_project.yml via <%= @args[0] %>
# e.g. set the root project path via ```root: <%= @args[0] %>```
#compdef _tmuxinator tmuxinator
_tmuxinator() {
local commands projects
commands=(${(f)"$(tmuxinator commands zsh)"})
@raphaeltraviss
raphaeltraviss / machine.js
Last active March 4, 2021 22:48
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions

Keybase proof

I hereby claim:

  • I am raphaeltraviss on github.
  • I am rtraviss (https://keybase.io/rtraviss) on keybase.
  • I have a public key ASCJ-rgURfxuDoJ4XXWn006b4ADRsqLOkbyQBspwcSHWeQo

To claim this, I am signing this object:

@raphaeltraviss
raphaeltraviss / inputsampler_component.ts
Last active November 7, 2020 20:20
Basic XState model for moving/striking with "looking at" vector in PhaserJS
import { assign, interpret, Machine, Interpreter, EventObject } from 'xstate';
// Phaser implicitly available
interface PawnContext {
moveTowards?: Phaser.Math.Vector2,
}
@raphaeltraviss
raphaeltraviss / UIImageColors+Haneke.swift
Created July 10, 2018 16:28
UIImageColors extension to make them cacheable with Haneke
import Foundation
import UIImageColors
import Haneke
extension UIImageColors : DataConvertible, DataRepresentable {
public typealias Result = UIImageColors
public static func convertFromData(_ data: Data) -> Result? {
let representation = NSKeyedUnarchiver.unarchiveObject(with: data) as? [String: Data]
guard let colorData = representation else { return nil }
@raphaeltraviss
raphaeltraviss / nsoutline_delegate.swift
Last active May 21, 2018 20:27
Generic NSOutlineView delegate in Swift. Allows the delegate to be destroyed and re-created cleanly on every state change.
import AppKit
// This class will manufacture a delegate object for use with NSOutlineView,
// given the following:
// - A setup function, that will take an NSTableViewCell or subclass of the
// given type, and fill in its views.
// - A cell identifier from the storyboard, associated to the outline view.
// - A function that is called when a selection is made...
// Since the selection handler doesn't actually provide the selected node,
// you need to seal a reference to your outline view inside your Selection
@raphaeltraviss
raphaeltraviss / nsoutline_datasource.swift
Last active May 21, 2018 20:31
Generic DataSource class for NSOutlineView with drag n drop support in Swift. For use in reactive programming models, where you destroy and re-create the datasource on each relevant state change.
import AppKit
// This class will manufacture a datasource object for use with NSOutlineView,
// given the following:
// - A type, specifying what type of object the datasource will provide.
// - A root object, which contains the heirarchy of its children
// - A function that can be called on the object type, to return its children.
// - A function that can be called on the object type, to return its identity.
// - A pasteboard type that can be used for drag and drop.
// - Side effects for insert and move actions.