Skip to content

Instantly share code, notes, and snippets.

@hishma
hishma / ViewAperturePhotoOnFlickr.applescript
Created July 13, 2011 15:16
View an Aperture photo on flickr
-- View an Aperture photo on flickr
-- Assumes a custom metadata field in Aperture named "Flickr URL" exists.
tell application "Aperture"
-- selection always returns image versions
set selectedImages to (get selection)
if (count of items in selectedImages) > 0 then
repeat with i from 1 to count of selectedImages
tell library 1
set img to item i of selectedImages
@hishma
hishma / random word
Created October 27, 2011 16:55
Copy a random word to the clipboard
sed `perl -e "print $RANDOM"`"q;d" /usr/share/dict/words | tr -d '\n' | pbcopy
@hishma
hishma / just_another_afternoon_spec.rb
Created July 31, 2012 23:53
just another afternoon spec
describe "just another afternoon” do
jeff = Factory.create(:loser)
artie = Cat.new(:name => "Artie", :size => "long", :color => "black”)
helpeless_victim = Victim.new(:type => ['Mouse, 'Bird', 'Mole', 'Rat'].sample)
artie.catch(helpless_victim)
while helpeless_victim.is_alive?
artie.torture(victim)
sleep 10
@hishma
hishma / logPretty.swift
Created December 17, 2015 00:08
Debug like a caveman in swift
func logPretty(message: String? = nil, file: String = __FILE__, line: UInt = __LINE__, function: StaticString = __FUNCTION__) {
var pretty = "\((file as NSString).lastPathComponent)(\(line)) : \(function)"
if let message = message where !message.isEmpty {
pretty += " ☞ \(message)"
}
print(pretty)
}
@hishma
hishma / CLLocation+Hishma.swift
Created January 16, 2019 23:54
Handy CorelLocation extension. Or so I think.
extension CLLocation {
/// Compass bearing from a known location
///
/// Shamelessly stolenfrom // https://stackoverflow.com/questions/26998029/calculating-bearing-between-two-cllocation-points-in-swift
///
/// - Parameter location: The `CLocation` to calculate the bearing from.
/// - Returns: The `CLLocationDirection` representing the compass bearing.
func bearing(from location: CLLocation) -> CLLocationDirection {
func degreesToRadians(degrees: CLLocationDirection) -> CLLocationDirection { return degrees * .pi / 180.0 }
@hishma
hishma / Bundle+Hishma.swift
Created January 16, 2019 23:59
Provides convenience accesors to some info dictionary keys
/// Provides convenience accesors to some info dictionary keys
extension Bundle {
var identifier: String? {
return string(forInfoDictionaryKey: "CFBundleIdentifier")
}
var displayName: String? {
return string(forInfoDictionaryKey: "CFBundleDisplayName")
}
@hishma
hishma / NSPersonNameComponents.swift
Created May 5, 2016 14:02
Swift extension to NSPersonNameComponents for Prince & friends.
//
// NSPersonNameComponents.swift
//
import Foundation
extension NSPersonNameComponents {
// Because the web is generally xenophobic…
var xenophobicName: (firstName: String, lastName: String)? {
@hishma
hishma / String+Hishma.swift
Last active January 23, 2019 22:41
String extensions to make my life more convenient. When I remember them…
extension String {
/// Replace all instances of characters in a character set.
///
/// - Parameters:
/// - characterSet: The `CharacterSet` containing the characters to replace in the string.
/// - replacementString: The `String` to replace the matched characters with.
/// - Returns: A new `String` with all characters in the character set replaced by the replacement string.
func replacingCharacters(in characterSet: CharacterSet, with replacementString: String = "") -> String {
return self.components(separatedBy: characterSet).joined(separator: replacementString)
}
extension Locale {
/// The calling code or "country dial in code" of the locale.
/// See https://en.wikipedia.org/wiki/List_of_country_calling_codes#Alphabetical_listing_by_country_or_region
var countryCallingCode: String? {
return isdCode
}
/// The international subscriber dialling (ISD) code of the locale.
var isdCode: String? {
guard let regionCode = self.regionCode else { return nil }
extension Locale {
/// An emoji representation of the locale's region.
var emoji: String? {
return regionalIndicatorSymbol
}
/// The regional indicator symbols are a set of 26 alphabetic Unicode characters (A–Z) intended to be used to encode
/// ISO 3166-1 alpha-2 two-letter country codes in a way that allows optional special treatment.
///
/// These were defined as part of the Unicode 6.0 support for emoji, as an alternative to encoding separate characters for each