Skip to content

Instantly share code, notes, and snippets.

View chrismanderson's full-sized avatar

Chris Anderson chrismanderson

View GitHub Profile
//
// UIView+RSKeyboardLayoutGuide.swift
// RSTouchUIKit
//
// Created by Daniel Jalkut on 12/23/18.
//
import UIKit
// Extends UIView to expose a keyboardLayoutGuide property that can be used to tie a view controller's content
@koop
koop / ensure-cert-macos.sh
Created November 28, 2017 20:27
Ensures a certificate is in the macOS system keychain.
#!/bin/bash
# Usage
# $ ./install-cert-macos.sh "/path/to/cert"
CERT_PATH="$1"
# First, grab the SHA-1 from the provided SSL cert.
CERT_SHA1=$(openssl x509 -in "$CERT_PATH" -sha1 -noout -fingerprint | cut -d "=" -f2 | sed "s/://g")
# Next, grab the SHA-1s of any standard.dev certs in the keychain.
# Don't return an error code if nothing is found.
@dannymcc
dannymcc / install_ruby_rpi.sh
Created March 14, 2017 16:06 — forked from blacktm/install_ruby_rpi.sh
A Bash script to install Ruby 2.4 on the Raspberry Pi (Raspbian)
#!/bin/bash
# --------------------------------------------------------------------------------------------
# Installs Ruby 2.4 using rbenv/ruby-build on the Raspberry Pi (Raspbian)
#
# Run from the web:
# bash <(curl -s https://gist.githubusercontent.com/blacktm/8302741/raw/install_ruby_rpi.sh)
# --------------------------------------------------------------------------------------------
# Welcome message
@siemensikkema
siemensikkema / objcio S01E06 Multiple Cell Types.swift
Last active April 21, 2023 17:13
Multiple Cell Types example based on episode 6 of talk.objc.io in response to question in episode 9
import UIKit
import XCPlayground
struct Episode {
var title: String
}
struct Season {
var number: Int
@andymatuschak
andymatuschak / States-v3.md
Last active May 1, 2024 12:32
A composable pattern for pure state machines with effects (draft v3)

A composable pattern for pure state machines with effects

State machines are everywhere in interactive systems, but they're rarely defined clearly and explicitly. Given some big blob of code including implicit state machines, which transitions are possible and under what conditions? What effects take place on what transitions?

There are existing design patterns for state machines, but all the patterns I've seen complect side effects with the structure of the state machine itself. Instances of these patterns are difficult to test without mocking, and they end up with more dependencies. Worse, the classic patterns compose poorly: hierarchical state machines are typically not straightforward extensions. The functional programming world has solutions, but they don't transpose neatly enough to be broadly usable in mainstream languages.

Here I present a composable pattern for pure state machiness with effects,

@sebboh
sebboh / gist:f1dfe4f096746c45f3e9ea06a09743a0
Last active February 27, 2024 17:10 — forked from masonforest/gist:4048732
Installing a Gem on Heroku from a Private GitHub Repo

Installing a Gem on Heroku from a Private GitHub Repo

Sometimes you want to use a gem on Heroku that is in a private repository on GitHub.

Using git over http you can authenticate to GitHub using basic authentication. However, we don't want to embed usernames and passwords in Gemfiles. Instead, we can use authentication tokens.

This method does not add your OAuth token to Gemfile.lock. It uses bundle config to store your credentials, and allows you to configure Heroku to use environment variables when deploying.

  1. Generate an OAuth token from GitHub
// Stolen from Tumblr
#define PTH_INVALID_INITIALIZER(initDeclaration) \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wobjc-designated-initializers\"") \
- (instancetype)initDeclaration { \
@throw [[NSException alloc] initWithName:@"Invalid initializer" reason:[NSString stringWithFormat:@"The initializer %s is not available.", __PRETTY_FUNCTION__] userInfo:nil]; \
return nil; \
} \
_Pragma("clang diagnostic pop")
@gvaughn
gvaughn / copr.md
Last active January 30, 2024 16:11
git copr alias

I'd like to share some git aliases that you might find useful if you handle pull requests from others.

Add these to your ~/.gitconfig in the [alias] section:

copr = "!f() { git fetch -fu origin refs/pull/$1/head:pr-$1; git checkout pr-$1; } ; f"
prunepr = "!git for-each-ref refs/heads/pr-* --format='%(refname:short)' | while read ref ; do git branch -D $ref ; done"

Now you can "git copr #{pr_number}" (check out pull request is the mnemonic) and it will pull down the PR in a local branch of pr-#{pr_number} and check it out for you. To do it right, you must pronounce it "Copper" with a James Cagney gangster accent.

Snow in canvas land

Other people's code is awful, and your own code from months previous counts as someone else's. With this and the festive spirit in mind, I dug up a canvas snow demo I made two years ago to see how bad my code really was.

Turns out the performance landscape has changed quite a bit, but after applying a couple of workarounds, best practices, and memory management, I got the demo running smoother than it ever did.

Ugh, I can't believe I just wrote "performance landscape". Anyway...

How does the demo work?

@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this: