Skip to content

Instantly share code, notes, and snippets.

View soffes's full-sized avatar

Sam Soffes soffes

View GitHub Profile
@soffes
soffes / Decoders+JSON.swift
Last active January 8, 2021 12:51 — forked from loudmouth/Decode Array<Any> and Dictionary<String, Any> Swift
Decode Array<Any> and Dictionary<String, Any> Swift
import Foundation
// Inspired by https://gist.github.com/loudmouth/332e8d89d8de2c1eaf81875cfcd22e24
private struct JSONCodingKeys: CodingKey {
var stringValue: String
init?(stringValue: String) {
self.stringValue = stringValue
}
@soffes
soffes / highlight.swift
Last active November 16, 2021 07:34 — forked from orta/highlight.swift
Swift implementation to highlight Cocoa UI elements (http://stackoverflow.com/a/25984748/316803)
// Taken from:
// https://gist.github.com/joelcox/28de2f0cb21ea47bd789
NSColor.selectedMenuItemColor.set()
NSBezierPath(rect: rect).fill()
if rect.height > 1 {
let currentControlTint = NSColor.currentControlTint
let startingAlpha: CGFloat = currentControlTint == .blueControlTint ? 0.16 : 0.09
@soffes
soffes / Readme.markdown
Created July 3, 2018 23:25 — forked from calebd/Readme.markdown
Run Loop Source

CFRunLoopSource is cool. It lets you build behavior similar to the mechanisms that drive setNeedsLayout and setNeedsDisplay in UIKit.

I found myself in need of something like this a couple of times. It's great to know that no matter how many times I say I need to update something, I will get a single callback at the end of the run loop that gives me a chance to perform my work.

Here is a little Swift wrapper that makes the API easier to deal with.


Updated for Swift 4

@soffes
soffes / UIColorExtension.swift
Created July 21, 2015 15:48 — forked from asarode/UIColorExtension.swift
Swift extension to get luma value of a UIColor
import UIKit
extension UIColor {
var luminance: CGFloat {
var red: CGFloat = 0
var green: CGFloat = 0
var blue: CGFloat = 0
getRed(&red, green: &green, blue: &blue, alpha: nil)
@soffes
soffes / html5_template.html
Created December 7, 2011 01:48 — forked from nathansmith/html5_template.html
Simple HTML5 Template
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>untitled</title>
<link rel="stylesheet" href="">
</head>
<body>
</body>
POST /book/:id/notes
note[content]
selection[spine_item_id] or selection[spine_item_play_order]
selection[chunk_offset]
selection[character_offset]
selection[character_length]
//
// roommateappAppDelegate.m
// roommateapp
//
// Created by Court Simas on 4/4/10.
// Copyright Court Simas 2010. All rights reserved.
//
#import "roommateappAppDelegate.h"
#import "RootViewController.h"
class RenderDirectly < ActionController::Base
include ActionController::Rendering
include AbstractController::Layouts
append_view_path Rails.root.join("app", "views").to_s
layout "application"
def index
render *env["generic_views.render_args"]
end
// TinyMCE Settings.
tinyMCE.init({
extended_valid_elements: 'style',
mode: 'exact',
elements: 'id_name',
theme: 'advanced',
theme_advanced_toolbar_location: 'top',
theme_advanced_toolbar_align: 'left',
plugins: 'safari, style, table, paste, media',
theme_advanced_buttons1: 'bold, italic, underline, justifyleft, justifycenter, justifyright, justifyfull, formatselect, fontselect, fontsizeselect',
#!/bin/sh
# Install ImageMagick on Snow Leopard: by kain, improved by mislav and samsoffes
# http://www.icoretech.org/2009/08/install-imagemagick-in-leopard-snow-leopard/
# Work with 64bit kernel mode
set -e
PREFIX=/usr/local
# Passenger users: amend your Apache global configuration with the following directive
# SetEnv PATH /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin