Skip to content

Instantly share code, notes, and snippets.

@mazbox
mazbox / xcode-music-pause.sh
Last active January 13, 2023 01:25
play/pause Music.app on Mac when running
#!/bin/zsh
musicAppOpen=`osascript -e 'tell application "System Events" to (name of processes) contains "Music"'`
rm -f "/tmp/xcode-itunes.txt"
if [ $musicAppOpen = 'true' ]; then
musicState=`osascript -e 'tell application "Music" to player state as string'`
if [ $musicState = 'playing' ]; then
echo 'play' > '/tmp/xcode-itunes.txt'
osascript -e 'tell application "Music" to pause'
@preble
preble / DispatchSyncThrows.swift
Created June 27, 2015 00:25
An overload of dispatch_sync that throws any error thrown by the closure. (Swift 2)
import Foundation
/// Call a throwing block synchronously.
func dispatch_sync(queue: dispatch_queue_t, block: () throws -> ()) throws {
var error: ErrorType?
dispatch_sync(queue) {
do {
try block()
} catch let caughtError {
error = caughtError
@juliensagot
juliensagot / NSBezierPath+cgPath.swift
Last active September 26, 2023 23:11
Convert NSBezierPath to CGPath (Swift 5.1, Xcode 11.3 (11C29))
extension NSBezierPath {
/// A `CGPath` object representing the current `NSBezierPath`.
var cgPath: CGPath {
let path = CGMutablePath()
let points = UnsafeMutablePointer<NSPoint>.allocate(capacity: 3)
if elementCount > 0 {
var didClosePath = true
//
// ViewController.m
// AVPlayerCaching
//
// Created by Anurag Mishra on 5/19/14.
// Sample code to demonstrate how to cache a remote audio file while streaming it with AVPlayer
//
#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
@warnergodfrey
warnergodfrey / gist:7512051
Last active September 21, 2018 03:20
Access the ATO Business Portal using AusKey Mac OS X Mountain Lion
  • Install the latest JRE from Oracle
  • In the Java Control Panel, go to the Security tab and make sure 'Enable Java Content' is checked
  • Open Safari
  • Go to the ATO Business portal site https://bp.ato.gov.au/BpStatics/homepage.htm
  • Click Login
  • A dialog will apear asking you 'Do you want to trust the website “authentication.business.gov.au” to use the “Java” plug-in?'
  • Click 'Trust'
  • Now you will be asked 'Do you want to run this application?'
  • Click 'Run'
  • Another dialog will appear asking you to 'Allow access to the following application from this website?'