Skip to content

Instantly share code, notes, and snippets.

View gdavis's full-sized avatar

Grant Davis gdavis

View GitHub Profile
@gdavis
gdavis / GDILog.h
Last active August 29, 2015 14:05
GDILog - Replacement for NSLog
//
// GDILog.h
// GDILog
//
// Created by Grant Davis on 8/18/14.
// Copyright (c) 2014 Grant Davis Interactive, LLC. All rights reserved.
//
#ifdef DEBUG
#include <string.h>
@michaeldwan
michaeldwan / heroku_deploy.rake
Created July 4, 2010 02:08
Simple Rake task for customizing deployment to Heroku
# List of environments and their heroku git remotes
ENVIRONMENTS = {
:staging => 'myapp-staging',
:production => 'myapp-production'
}
namespace :deploy do
ENVIRONMENTS.keys.each do |env|
desc "Deploy to #{env}"
task env do
#!/bin/bash
function usage {
echo "Usage: $0 -c [CodeSign Directory] -p [Xcode Project File.xcodeproj]"
echo "If any arguments are not specified, defaults will be attempted. If defaults don't exist, script will exit."
echo "OPTIONS:"
echo " -c [CodeSign Directory]: Location of directory containing project's provisioning profiles."
echo " -p [Xcode Project File]: Path of Xcode project directory (the .xcodeproj, not .pbxproj)"
echo " -b: Use PlistBuddy command for UUID replacement instead of sed. (Better handling of a couple of edge cases, but makes diffs impossible to read.)"
echo " -v: Verbose logging."
@mminer
mminer / PreferencesViewController.swift
Last active February 5, 2021 19:43
NSTabViewController for preferences window that resizes itself to fit activated tab view.
import AppKit
class PreferencesViewController: NSTabViewController {
private lazy var tabViewSizes: [NSTabViewItem: NSSize] = [:]
override func tabView(_ tabView: NSTabView, didSelect tabViewItem: NSTabViewItem?) {
super.tabView(tabView, didSelect: tabViewItem)
if let tabViewItem = tabViewItem {
@mchambers
mchambers / reflect.swift
Last active March 5, 2021 09:20
Basic Reflection in Swift.
// Let's define a basic Swift class.
class Fruit {
var type=1
var name="Apple"
var delicious=true
}
// We can get at some info about an instance of an object using reflect(), which returns a Mirror.
reflect(Fruit()).count
reflect(Fruit())[1].0
@randomsequence
randomsequence / cocoa-drawing.swift
Created July 14, 2015 15:25
Drawing images with CGContext and NSGraphicsContext in Swift
//: Playground - noun: a place where people can play
import Cocoa
let bounds = CGRectMake(0, 0, 100, 100);
func DrawImageInCGContext(#size: CGSize, #drawFunc: (context: CGContextRef) -> ()) -> NSImage {
let colorSpace = CGColorSpaceCreateDeviceRGB()
let bitmapInfo = CGBitmapInfo(CGImageAlphaInfo.PremultipliedLast.rawValue)
let context = CGBitmapContextCreate(
@jtodaone
jtodaone / AudioBufferConversion.swift
Created August 10, 2019 14:38
AudioBuffer (or AVAudioPCMBuffer) to array of float / Float array to AudioBuffer (or AVAudioPCMBuffer)
import AVFoundation
extension AudioBuffer {
func array() -> [Float] {
return Array(UnsafeBufferPointer(self))
}
}
extension AVAudioPCMBuffer {
func array() -> [Float] {
@gdavis
gdavis / gist:2829437
Last active January 16, 2023 16:44
Xcode 4 Custom Key Commands - Add to IDETextKeyBindingsSet.plist
<key>GDI Commands</key>
<dict>
<key>GDI Duplicate Current Line</key>
<string>selectLine:, copy:, moveToEndOfLine:, insertNewLine:, moveToBeginningOfLine:, paste:, moveUp:, moveToEndOfLine:</string>
<key>GDI Delete Current Line</key>
<string>moveToEndOfLine:, deleteToBeginningOfLine:, deleteBackward:, moveDown:, moveToEndOfLine:</string>
<key>GDI Move Current Line Up</key>
<string>selectLine:, cut:, moveUp:, moveToBeginningOfLine:, insertNewLine:, paste:, moveBackward:</string>
<key>GDI Move Current Line Down</key>
<string>selectLine:, cut:, moveDown:, moveToBeginningOfLine:, insertNewLine:, paste:, moveBackward:</string>
@gdavis
gdavis / swift-concurrency.markdown
Last active November 20, 2023 01:51
Notes about usage of Swift Concurrency

Swift Concurrency

Video: Meet async/await in Swift

With Swift concurrency, functions, initializers, read-only properties, and for-loops can all be marked async. Property getters can also throw.

func fetchThumbnails() await throws -> [UIImage] {
}

extension UIImage {
@trcarden
trcarden / gist:3295935
Created August 8, 2012 15:28
Rails 3.2.7 SSL Localhost (no red warnings, no apache config)
# SSL self signed localhost for rails start to finish, no red warnings.
# 1) Create your private key (any password will do, we remove it below)
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key