Skip to content

Instantly share code, notes, and snippets.

@alemar11
alemar11 / osx-for-hackers.sh
Last active September 12, 2015 11:34 — 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...
#!/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 September 12, 2015 11:35 — forked from kylefox/color.m
Generate a random color (UIColor) in Objective-C
/*
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 September 18, 2015 19:41 — forked from plumhead/StringSize.swift
String extension to find the layout size of a String with specified attributes.
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)
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 October 27, 2015 22:08 — forked from CodaFi/Trees.swift
A small propositional logic proof tree generator and prover.
//: 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 October 27, 2015 23:29 — forked from zacharyclaysmith/HttpStatusCode.swift
Http Status Code enum for 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 October 29, 2015 12:09 — forked from DJBen/Emoji.swift
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}"
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 November 20, 2015 22:08 — forked from mluton/CachedDateFormatter.swift
Swift class that instantiates and caches NSDateFormatter objects
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
}
// 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