Skip to content

Instantly share code, notes, and snippets.

@alemar11
alemar11 / osx-for-hackers.sh
Last active Sep 12, 2015 — forked from brandonb927/osx-for-hackers.sh
OSX for Hackers: Yosemite Edition. This script tries not to be *too* opinionated and any major changes to your system require a prompt. You've been warned. Also, please don't email me about this script, my poor inbox...
View osx-for-hackers.sh
#!/bin/sh
# Alot of these configs have been taken from the various places
# on the web, most from here
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
# Set the colours you can use
black='\033[0;30m'
white='\033[0;37m'
red='\033[0;31m'
@alemar11
alemar11 / color.m
Last active Sep 12, 2015 — forked from kylefox/color.m
Generate a random color (UIColor) in Objective-C
View color.m
/*
Distributed under The MIT License:
http://opensource.org/licenses/mit-license.php
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
@alemar11
alemar11 / StringSize.swift
Last active Sep 18, 2015 — forked from plumhead/StringSize.swift
String extension to find the layout size of a String with specified attributes.
View StringSize.swift
extension String {
func size(withAttributes attrs: [String:AnyObject], constrainedTo box: NSSize) -> NSRect {
let storage = NSTextStorage(string: self)
let container = NSTextContainer(containerSize: NSSize(width: box.width, height: box.height))
let layout = NSLayoutManager()
layout.addTextContainer(container)
storage.addLayoutManager(layout)
storage.addAttributes(attrs, range: NSMakeRange(0, storage.length))
container.lineFragmentPadding = 0.0
let _ = layout.glyphRangeForTextContainer(container)
View context errors.swift
public struct Error: ErrorType {
let source: String; let reason: String
public init(_ source: String = __FILE__, _ reason: String) {
self.reason = reason; self.source = source
}
}
protocol Contextualizable {}
extension Contextualizable {
func functionContext(function : String = __FUNCTION__) -> String {
@alemar11
alemar11 / Trees.swift
Created Oct 27, 2015 — forked from CodaFi/Trees.swift
A small propositional logic proof tree generator and prover.
View Trees.swift
//: Playground - noun: a place where people can play
//: Prop 'til you Drop
indirect enum Formula : CustomStringConvertible {
case Var(String)
case Or(Formula, Formula)
case And(Formula, Formula)
case Imply(Formula, Formula)
case BiImply(Formula, Formula)
case Negate(Formula)
@alemar11
alemar11 / HttpStatusCode.swift
Created Oct 27, 2015 — forked from zacharyclaysmith/HttpStatusCode.swift
Http Status Code enum for Swift.
View HttpStatusCode.swift
//
// HttpStatusCode.swift
//
// Created by Zachary Smith on 5/1/15.
// Copyright (c) 2015 Zachary Smith. All rights reserved.
//
import Foundation
/**
@alemar11
alemar11 / Emoji.swift
Created Oct 29, 2015 — forked from DJBen/Emoji.swift
Emoji-Swift
View Emoji.swift
enum Emoji: String {
case Copyright = "\u{00A9}"
case Registered = "\u{00AE}"
case Bangbang = "\u{203C}"
case Interrobang = "\u{2049}"
case Tm = "\u{2122}"
case InformationSource = "\u{2139}"
case LeftRightArrow = "\u{2194}"
case ArrowUpDown = "\u{2195}"
case ArrowUpperLeft = "\u{2196}"
View where-where.swift
import Cocoa
// for-in
func checkForIn(array: [Int], dict: [Int: String]) {
for num in array where dict[num] != nil {
num
}
}
checkForIn([1,2,3,4], dict: [1:"one", 2:"two"])
@alemar11
alemar11 / CachedDateFormatter.swift
Created Nov 20, 2015 — forked from mluton/CachedDateFormatter.swift
Swift class that instantiates and caches NSDateFormatter objects
View CachedDateFormatter.swift
class CachedDateFormatter {
static let sharedInstance = CachedDateFormatter()
var cachedDateFormatters = [String: NSDateFormatter]()
func formatterWith(#format: String, timeZone: NSTimeZone = NSTimeZone.localTimeZone(), locale: NSLocale = NSLocale(localeIdentifier: "en_US")) -> NSDateFormatter {
let key = "\(format.hashValue)\(timeZone.hashValue)\(locale.hashValue)"
if let cachedDateFormatter = cachedDateFormatters[key] {
return cachedDateFormatter
}
View ChunkSequence.swift
// http://blog.krzyzanowskim.com
import Cocoa
struct ChunkSequence<Element>: SequenceType {
let chunkSize: Array<Element>.Index
let collection: Array<Element>
func generate() -> AnyGenerator<ArraySlice<Element>> {
var offset:Array<Element>.Index = collection.startIndex