Skip to content

Instantly share code, notes, and snippets.

@SeanMcTex
SeanMcTex / PinToSafeArea.cs
Last active March 2, 2024 07:27
Restrict Unity UI to an iPhone X or other Mobile Device's Safe Area
using UnityEngine;
/// <summary>
/// Resizes a UI element with a RectTransform to respect the safe areas of the current device.
/// This is particularly useful on an iPhone X, where we have to avoid the notch and the screen
/// corners.
///
/// The easiest way to use it is to create a root Canvas object, attach this script to a game object called "SafeAreaContainer"
/// that is the child of the root canvas, and then layout the UI elements within the SafeAreaContainer, which
/// will adjust size appropriately for the current device./// </summary>
@SeanMcTex
SeanMcTex / FilteredTextField.md
Created May 8, 2020 20:05
A pitfall to avoid when filtering SwiftUI TextFields

Today’s very hard-won lesson: be careful how you do TextField content filtering! We were filtering input to a text field (making sure the field only accepted numbers, etc.) like so:

@Binding var value: String
TextField( placeholder, text: $value )
    .onReceive( Just( value ), perform: { 
		self.value = self.contentType.filterCharacters( oldValue: $0 ) 
	})
@SeanMcTex
SeanMcTex / MeshMeasure.cs
Created January 24, 2019 23:43
Unity Utility to display bounds of mesh objects in world space
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
/// <summary>
/// In order to help gauge the size of mesh objects,
/// this script displays the dimensions in world space of a selected object
/// with a MeshRenderer attached whenever it's selected.
/// </summary>
@SeanMcTex
SeanMcTex / NuclearBodhran.ino
Created April 25, 2023 14:32
Code for sound-reactive bodhran (Irish drum), as per article at http://www.mcmains.net.
/* Sound-Reactive Drums for Adafruit Gemma/Trinket and NeoPixel LEDs.
Hardware requirements:
- Adafruit Gemma, Gemma M0, or 3V Trinket microcontroller.
Do NOT use a 5V Trinket; circuit DEPENDS on the 3V regulator!
- Adafruit Electret Microphone Amplifier (product ID: 1063)
- A length of NeoPixel LEDs, such as:
o Adafruit Flora RGB Smart Pixels (ID: 1260)
o Adafruit NeoPixel Digital LED strip (ID: 1138)
o Adafruit Neopixel Ring (ID: 1463)
@SeanMcTex
SeanMcTex / lights-camera-action.sh
Last active May 6, 2022 02:45
Script to turn on/off light for videoconferencing automatically. Requires a Mac, Oversight, and Shortcuts app.
#!/bin/bash
# To use this script:
# 1. Save it on your Mac hard drive somewhere convenient.
# 2. `chmod` its permissions to make it executable. E.g. `chmod 755 handle-camera.sh`.
# 3. In the Shortcuts app, create "Start Conference" and "End Conference" shortcuts that activate lights
# and do whatever else you want to happen when conferences start and end.
# 4. Download and install Oversight to watch for camera activation/deactivation:
# https://objective-see.com/products/oversight.html
# 5. Configure Oversight's "action" panel to run this script. Turn on the option that passes arguments.

Keybase proof

I hereby claim:

  • I am seanmctex on github.
  • I am seanmctex (https://keybase.io/seanmctex) on keybase.
  • I have a public key ASDT7FKVZ32O8_2qtx6d_Yi7qB9RMudVa81HwX8lLC3QhQo

To claim this, I am signing this object:

@SeanMcTex
SeanMcTex / README-Template.md
Created March 7, 2019 15:01 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@SeanMcTex
SeanMcTex / gist:6318927
Last active December 21, 2015 14:19
Unit Tests That Write Themselves: Part Two

Unit Tests That Write Themselves: Part Two

In the first article in this series, we set up an abstract parent class for our view controller tests and used Objective C's runtime library to create dynamically named tests for all of its concrete subclasses. This technique can save a lot of time, but we still have to remember to create a new test case for each view controller class.

Is it possible to make unit tests even more automatic? By gazing deep into the occult mysteries of the runtime system, we will answer this question and, if we're lucky, discover a little bit about love along the way. (Editor's Note: We will not actually discover anything about love.)

If you'd like to follow along with some functional code, you can download the sample project from GitHub.

The Case for Automated Test Creation

@SeanMcTex
SeanMcTex / gist:6308966
Last active December 21, 2015 12:58
Unit Tests That Write Themselves: Part One

Unit Tests That Write Themselves: Part One

Unit tests are fantastic. They make code more robust, refactoring less scary, help developers design programs well, and allow machines do more of the monkey work involved in creating a robust app.

But let's face it: unit tests aren’t always the most fun to write. Worse yet, if developers are trying to achieve high code coverage or adhere to Test Driven Development, they will often end up with a lot of repetitive tests.

This is a state of affairs that wouldn't stand for a minute in application code, but which often passes without a second thought in test code. But if we're serious about testing, this should bother us. We should strive to keep our tests as [^1]DRY as we keep our app.

How do we achieve this? In this article, we'll implement a superclass for test suites with common elements, and see how to use the Objective-C runtime to make sure those tests are named meaningfully. (Teaser: in the followup article, we'll see a technique that delves deeper into r

WWDC 2015 Wish List & Predictions, the Developer's Perspective

Mutual Mobile has been very lucky this year to have a number of our devs awarded tickets to attend WWDC. As the time grows close, speculation about what we'll be seeing this year is reaching a fever pitch. As developers, we have a lot of stake in what Apple reveals in a couple of short weeks, and we've had some great discussions about what we expect to see and what we are hoping for. Here are a number of the things we're wishing for and estimates of how likely we think it is that our dreams will come true.

New Apple TV

The last time Apple mentioned the Apple TV, they lowered the price: "starting at $69". The "starting at" makes it a near certainty that there's an updated Apple TV in the works, and rumors seem to indicate that an SDK for doing development for the updated box is a very likely as well. An SDK would allow video providers to create new apps to share video content from a variety of new sources, and to enrich that video content w