Skip to content

Instantly share code, notes, and snippets.

View CraigSiemens's full-sized avatar

Craig Siemens CraigSiemens

View GitHub Profile
@CraigSiemens
CraigSiemens / gist:3821519
Created October 2, 2012 17:41
Pointillize Image
- (UIImage *)pointillizedImageFromImage:(UIImage *)image withPointDiameter:(CGFloat)diameter
{
CGFloat width = image.size.width;
CGFloat height = image.size.height;
CGImageRef inImage = [image CGImage];
CFDataRef m_dataRef = CGDataProviderCopyData(CGImageGetDataProvider(inImage));
UInt8* m_pixelBuf = (UInt8*)CFDataGetBytePtr(m_dataRef);
UIGraphicsBeginImageContextWithOptions(image.size, YES, 0);
@CraigSiemens
CraigSiemens / iflet.m
Last active May 2, 2021 02:09 — forked from jspahrsummers/iflet.m
if-let and guard macros for Objective C
#import <Foundation/Foundation.h>
// VARIABLE must be a variable declaration (NSString *foo)
// VALUE is what you are checking is not nil
// WHERE is an additional BOOL condition
#define iflet(VARIABLE, VALUE) \
ifletwhere(VARIABLE, VALUE, YES)
#define ifletwhere(VARIABLE, VALUE, WHERE) \
@CraigSiemens
CraigSiemens / xc.sh
Created June 17, 2020 18:01
Quickly the Xcode workspace, project, or package in the current directory, or specify files to open in Xcode.
function xc {
xcodePath=`xcode-select --print-path | grep ".*\.app" -o`
if (( $# == 0 ))
then
xcworkspace=`ls -1 | grep *.xcworkspace | wc -l`
xcproject=`ls -1 | grep *.xcodeproj | wc -l`
package=`ls -1 | grep Package.swift | wc -l`
if (( $xcworkspace > 0 ))
@CraigSiemens
CraigSiemens / AirplaneView.swift
Last active February 18, 2021 09:44
Modified version if AirplaneView that tries to more closely match the behaviour in AutoLayout. https://talk.objc.io/episodes/S01E241-swiftui-layout-challenge-1
//
// ContentView.swift
// Airplane
//
// Created by Chris Eidhof on 08.02.21.
//
import SwiftUI
struct ContentView: View {
@CraigSiemens
CraigSiemens / ArrayBuilder.swift
Last active September 15, 2022 01:55
An simple example of using resultBuilder to create an Array.
@resultBuilder
struct ArrayBuilder<Element> {
static func buildBlock(_ components: [Element]...) -> [Element] {
components.flatMap { $0 }
}
static func buildExpression(_ expression: Element) -> [Element] {
[expression]
}
@CraigSiemens
CraigSiemens / zoom-screenshot.sh
Created March 25, 2023 18:54
Takes a screenshot of each page in the current zoom window.
#!/bin/bash
###################################################################################################
# USAGE
###################################################################################################
print_usage() {
echo -e "Takes screenshots of the pages in the current zoom window"
echo -e "\nUsage:"
echo -e " ./zoom-screenshots.sh [-d DELAY_BETWEEN_SCREENSHOTS] [-o OUTPUT_DIR]"
echo -e "\nFlags (optional):"
@CraigSiemens
CraigSiemens / pretty-description.swift
Last active April 25, 2023 16:41
Takes a string from the default implementation of `String(describing:)` and reformats it to be on multiple lines with indented properties. Useful when looking at logs or crash reports that generates strings from types using `String(describing:)`.
#!/usr/bin/swift
import Darwin
import Foundation
var inputString = CommandLine.arguments.dropFirst().joined(separator: " ")
if inputString.isEmpty {
while let line = readLine(strippingNewline: false) {
inputString += line
}