Skip to content

Instantly share code, notes, and snippets.

View bendodson's full-sized avatar

Ben Dodson bendodson

View GitHub Profile
@bendodson
bendodson / gist:d842769c2d6f29280e55231e3c0cc5f8
Created October 4, 2016 09:16
Example of playlist media query
func runMediaLibraryQuery() {
let query = MPMediaQuery.playlists()
if let playlists = query.collections {
for playlist in playlists {
if let playlistName = playlist.value(forKey: MPMediaPlaylistPropertyName) {
NSLog("Playlist: \(playlistName)")
if let item = playlist.items.first, let title = item.title {
NSLog("First track: \(title)")
}
}
@bendodson
bendodson / RandomColorWithSeed (Swift 3)
Last active January 25, 2024 17:05
Generate a random color with a seed string using Swift 3
import UIKit
func randomColor(seed: String) -> UIColor {
var total: Int = 0
for u in seed.unicodeScalars {
total += Int(UInt32(u))
}
@bendodson
bendodson / HKHealthStore-DeleteObjects.swift
Last active October 6, 2015 15:13
A fix for the broken implementation of HKHealhStore.deleteObjectsOfType in iOS 9.0 (see radar 22977320)
//
// HKHealthStore-DeleteObjects.swift
// HealthKitTest
//
// Created by Ben Dodson on 06/10/2015.
// Copyright © 2015 Dodo Apps. All rights reserved.
//
import Foundation
import HealthKit
@bendodson
bendodson / jQuery.consoleConfig.js
Created January 23, 2012 12:16
Basic jQuery plugin to allow console logging in browsers without JavaScript consoles
jQuery.consoleConfig = function(useConsole,useAlert)
{
if (arguments.length == 0) {
var useConsole = true;
var useAlert = true;
} else if (arguments.length == 1) {
var useAlert = true;
}
if (!window.console || !useConsole) {