Skip to content

Instantly share code, notes, and snippets.

View mieko's full-sized avatar

Mike Owens mieko

View GitHub Profile
@mieko
mieko / state_machine_history_label.gd
Created January 15, 2026 10:07
See the current and previous states of an AnimationNodeStateMachine
# StateMachineHistoryLabel.gd
# Debug UI for AnimationNodeStateMachinePlayback
# Horizontal rolling history, arrows, newest entry pulse
class_name StateMachineHistoryLabel
extends Control
@export var animation_tree: AnimationTree
@export var state_machine_path: StringName
@export var max_entries: int = 8
@mieko
mieko / marching_squares.cc
Created September 29, 2014 05:07
Marching Squares in C++
#include "marching-squares.hh"
#include "point.hh"
#include "polygon.hh"
#include "douglas-peucker.hh"
#include <ps/canvas/canvas.hh>
#include <cstring>
#include <vector>
@mieko
mieko / MIT-LICENSE
Last active February 24, 2024 15:47
Douglas-Peucker Polyline simplification
Copyright 2016 Mike Owens
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
Software.
{
"$schema": "http://json-schema.org/draft-07/schema",
"title": "RuboCop configuration schema",
"description": "Schema for RuboCop configuration files (e.g. .rubocop.yml), intended for helping IDEs provide autocompletion and validation.",
"type": "object",
"additionalProperties": false,
"definitions": {
"inherit_mode": {
"type": "object",
"minProperties": 1,
@mieko
mieko / sanitized_flash.rb
Created October 14, 2020 03:03
Mixed HTML/Plaintext `flash` messages in Rails 4.1+ JSON cookie serializer
require "rack/utils"
# Rails < 4.1 serialized sessions with Marshal, which could distinguish "html_safe" flash strings
# from unsafe strings because it encoded actual ActiveSupport::SafeBuffer objects. So when the
# flash message came back from the client, its "safe" status was preserved, and it was rendered
# correctly under both circumstances.
#
# This same "magic" ability is also why Rails moved away from it: multiple CVEs due to arbitrary
# object creation. But regardless, that was a *really* nice trick.
#
@mieko
mieko / schema.rake
Created September 3, 2020 01:23
`rake schema FOR=Model` as an alternative to `annotate`
require "shellwords"
def terminal_width
%x(tput cols).chomp.to_i
rescue StandardError
80
end
def sql_table_command(model_class)
table_name = model_class.table_name
@mieko
mieko / try-binstubs-first.sh
Last active August 31, 2020 10:06
Shell functions that always remember to type `./bin/rails` when you type `rails`
# Tries to find a parent directory containing a file: "$1"
find-up() {
local path=$(pwd)
while [[ -n "$path" && ! -e "$path/$1" ]]; do
path=${path%/*}
done
echo "$path"
}
try-binstub() {
# Extracted from the following library
# http://facstaff.unca.edu/mcmcclur/GoogleMaps/EncodePolyline/
#--
# Utility for creating Google Maps Encoded GPolylines
# License: You may distribute this code under the same terms as Ruby itself
# Author: Joel Rosenberg
class DouglasPeucker
# The minimum distance from the line that a point must exceed to avoid
# elimination under the DP Algorithm.
@mieko
mieko / marching_squares.rb
Created September 29, 2014 05:09
Marching Squares in Ruby (with Inline C implementation)
class MarchingSquares
STATE = { "0000" => :r, "1100" => :r, "0011" => :l, "1110" => :r,
"0100" => :r, "1000" => :u, "1011" => :u, "1001" => :u,
"0101" => :d, "1010" => :u, "0111" => :l, "0110" => :l,
"0001" => :d, "0010" => :l, "1101" => :d, "1111" => :r }
def self.find_shape(grid, w, h)
edge_pos = grid.index('1')
return nil if edge_pos.nil?
@mieko
mieko / CCTableView.cpp
Created September 11, 2012 09:00
CCTableView with variable-size cells
/****************************************************************************
Copyright (c) 2012 cocos2d-x.org
Copyright (c) 2012 Mike Owens <mike@filespanker>
Copyright (c) 2010 Sangwoo Im
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights