Skip to content

Instantly share code, notes, and snippets.

Craig Hockenberry chockenberry

Block or report user

Report or block chockenberry

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View UIFont+CharacterWidth.m
// UIFont+CharacterWidth.m
- (CGFloat)characterWidth
{
CGFloat characterWidth = 0.0;
// get the width of a character by doing a layout with two spaces and measuring the position of the second glyph
NSAttributedString *measureAttributedString = [[NSAttributedString alloc] initWithString:@" " attributes:@{ NSFontAttributeName: self }];
CTLineRef lineRef = CTLineCreateWithAttributedString((CFAttributedStringRef)measureAttributedString);
CFArrayRef arrayRef = CTLineGetGlyphRuns(lineRef);
@chockenberry
chockenberry / ScreenRecordingDetection.m
Created Nov 21, 2019
Detecting Screen Recording Permission in macOS Catalina
View ScreenRecordingDetection.m
BOOL canRecordScreen = YES;
if (@available(macOS 10.15, *)) {
canRecordScreen = NO;
NSRunningApplication *runningApplication = NSRunningApplication.currentApplication;
NSNumber *ourProcessIdentifier = [NSNumber numberWithInteger:runningApplication.processIdentifier];
CFArrayRef windowList = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID);
NSUInteger numberOfWindows = CFArrayGetCount(windowList);
for (int index = 0; index < numberOfWindows; index++) {
// get information for each window
@chockenberry
chockenberry / Slack Formatting Bar Feedback.txt
Last active Nov 20, 2019
Slack Formatting Bar Feedback
View Slack Formatting Bar Feedback.txt
There are a couple of problems with the new formatting bar:
1) The icon to turn it on/off doesn't make sense. It's a toolbar, and the "Aa" doesn't get that concept across. It's in a strange place, next to "@" and ":-)", icons that cause an element to come up over the text field without changing it. A lot of smart folks aren't figuring this out (and let's face it, no one reads the fricken' manual.) Don't believe me, check out the replies to this tweet:
https://twitter.com/chockenberry/status/1196992017143779328
2) Once you have the epiphany to turn it off, it doesn't turn off the functionality. I've been using Markdown since it was just a glint in John Gruber's eye, and it's actually easier for me to _read_ text *like this* even when it contains `code`.
If I opt out of the formatting bar, it feels like I should be opting out the fancy completion stuff, too.
@chockenberry
chockenberry / Debug.swift
Last active Jan 9, 2020
Debug and release logging in Swift that's reminiscent of NSLog()
View Debug.swift
//
// Debug.swift
//
// Created by Craig Hockenberry on 3/15/17.
//
// Usage:
// debugLog("reticulating splines") prints "2019-10-04 11:52:28 SplineReticulationManager: reticulationFunction reticulating splines"
// debugLog() prints "2019-10-04 11:52:28 SplineReticulationManager: reticulationFunction called"
//
// Add "DEBUG" to project or target's "Active Compilation Conditions" for Debug builds.
View UIColor+RGB.m
// Created by Sean Heber on 4/12/12.
#import <UIKit/UIKit.h>
// If you work with a designer who specifies color in sRGB using 102,0,204, this category makes it simpler to instantiate
// a color with that specification: [UIColor colorWithRGB:102:0:204 alpha:1.0];
@interface UIColor (RGB)
// NOTE: If you're using the extended sRGB color space, you'll want to use something other than UInt8 :-)
+ (UIColor *)colorWithRGB:(UInt8)r :(UInt8)g :(UInt8)b alpha:(CGFloat)alpha;
@chockenberry
chockenberry / finder_icons.sh
Last active Jun 6, 2018
A simple shell script to turn the Finders desktop icons on and off
View finder_icons.sh
#!/bin/sh
defaults read com.apple.finder CreateDesktop > /dev/null 2>&1
enabled=$?
if [ "$1" = "off" ]; then
if [ $enabled -eq 1 ]; then
defaults write com.apple.finder CreateDesktop false
osascript -e 'tell application "Finder" to quit'
open -a Finder
View GPU Statistics for iPulse
In the next version of iPulse, I'd like to show GPU statistics. Unfortunately, the format
for these statistics is vendor specfic (see the "Performance Statistics" dictionary below.)
In order to cover as many devices as possible, I'd like you to run the following commands
from your Terminal:
$ sysctl hw.model
$ ioreg -r -d 1 -w 0 -c "IOAccelerator"
You can help me read the results by putting them in a code block (triple backticks).
@chockenberry
chockenberry / signature.txt
Last active Aug 29, 2015
El Cap code signing
View signature.txt
$ spctl --verbose=4 --assess --type execute xScope.app
xScope.app: rejected
source=obsolete resource envelope
$ codesign --verify --verbose=4 xScope.app
--prepared:/Users/craig/Downloads/xScope.app/Contents/Frameworks/Sparkle.framework/Versions/Current/.
--validated:/Users/craig/Downloads/xScope.app/Contents/Frameworks/Sparkle.framework/Versions/Current/.
--prepared:/Users/craig/Downloads/xScope.app/Contents/Frameworks/YAML.framework/Versions/Current/.
--validated:/Users/craig/Downloads/xScope.app/Contents/Frameworks/YAML.framework/Versions/Current/.
@chockenberry
chockenberry / elcap.html
Created Jul 7, 2015
San Francisco not available as CSS?
View elcap.html
<!DOCTYPE html>
<head>
<title>El Capitan</title>
<style>
body {
font-size: 2em;
}
h1 {
font-family: "System Font Black", HelveticaNeue-CondensedBlack, ComicSansMS;
@chockenberry
chockenberry / Hosts.txt
Created Jan 22, 2015
Host headers from China
View Hosts.txt
1.gravatar.com
127.0.0.1:9010
2003---el-oro-de-moscu-xvid-avi.foldforper7.appspot.com
a.tracker.thepiratebay.org
a2.l3-images.myspacecdn.com
a248.e.akamai.net
acyd-karpathicus.deviantart.com
ads.exoclick.com
agentoftrickery.deviantart.com
airinya.deviantart.com
You can’t perform that action at this time.