Skip to content

Instantly share code, notes, and snippets.

View raphaeltraviss's full-sized avatar

Raphael Traviss raphaeltraviss

View GitHub Profile
@raphaeltraviss
raphaeltraviss / DateIntervalEnhanced.php
Created April 16, 2015 15:51
PHP Date interval class that can recalculate values for date components.
<?php
class DateIntervalEnhanced extends DateInterval {
/* Keep in mind that a year is seen in this class as 365 days, and a month is seen as 30 days.
It is not possible to calculate how many days are in a given year or month without a point of
reference in time.*/
public function to_seconds() {
return ($this->y * 365 * 24 * 60 * 60) +
($this->m * 30 * 24 * 60 * 60) +
($this->d * 24 * 60 * 60) +
@raphaeltraviss
raphaeltraviss / Hexagon Ripple.swift
Created November 20, 2017 16:38 — forked from d-ronnqvist/Hexagon Ripple.swift
Hexagon Ripple in a Swift Playground (Swift 4)
import AppKit
import QuartzCore
import PlaygroundSupport
// Parameters that define the style
let hexSideLength: CGFloat = 15.0
let hexLineWidth: CGFloat = 3.0
let colors = [NSColor.red, NSColor.cyan, NSColor.green, NSColor.yellow, NSColor.red].map { $0.cgColor }
@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.
@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 / 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 / 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,
}

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 / 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
@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)"})
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions