Skip to content

Instantly share code, notes, and snippets.

View alexbosworth's full-sized avatar

Alex Bosworth alexbosworth

View GitHub Profile
@alexbosworth
alexbosworth / gist:2410117298c22dc971e3
Created February 13, 2015 05:39
UIAutomation, delay until network activity indicator is missing
/** Delay execution until status bar Network Activity is completed
{}
*/
automation.afterNetworkActivityEnds = function(args, cbk) {
var statusBar = target.frontMostApp().statusBar();
var predicate = "name beginswith 'Network'";
while (statusBar.elements().firstWithPredicate(predicate).isValid()) {
UIALogger.logMessage("Waiting for network");
@alexbosworth
alexbosworth / hour_floor.swift
Created March 20, 2015 09:25
Strip the minutes and seconds from a date, keeping yymmddhh
/** Strip minutes and seconds from a date
*/
func hourFloorFromDate(date: NSDate) -> NSDate? {
let calendar: NSCalendar
if let c = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian) { calendar = c } else { return nil }
let units = NSCalendarUnit.CalendarUnitYear | .CalendarUnitMonth | .CalendarUnitDay | .CalendarUnitHour
return calendar.dateFromComponents(calendar.components(units, fromDate: date))
//
// TableModifications.swift
// mn_ios
//
// Created by Alex Bosworth on 4/8/15.
// Copyright (c) 2015 adylitica. All rights reserved.
//
import UIKit
// Find the index of the first element found in a collection
func findInCollection<T: CollectionType where T.Generator.Element: Equatable>(collection: T, val: T.Generator.Element...) -> T.Index? {
for v in val { if let index = find(collection, v) { return index } }
return nil
}
@alexbosworth
alexbosworth / grayscale_uicolor.swift
Created September 8, 2015 04:01
convert a ui color to grayscale
var (hue, saturation, brightness, alpha) = (CGFloat(0.0), CGFloat(0.0), CGFloat(0.0), CGFloat(0.0))
let originalColor = UIColor.redColor()
if originalColor.getHue(&hue, saturation: &saturation, brightness: &brightness, alpha: &alpha) {
let grayscale = UIColor(hue: hue, saturation: 0, brightness: brightness, alpha: alpha)
}
func localizedStringForNumber(number: Int) -> String {
let numberFormatter = NSNumberFormatter()
numberFormatter.locale = NSLocale.currentLocale()
numberFormatter.numberStyle = .NoStyle
return numberFormatter.stringFromNumber(number) ?? String(number)
}
import UIKit
/** Helper methods for CGAffineTransform
*/
extension CGAffineTransform {
/** Make a vertical flip transformation
*/
static func flipVertical() -> CGAffineTransform {
return CGAffineTransformMakeScale(1, -1)
}
import UIKit
/** Alert controller that can be presented in any context and it will appear on top
*/
class GlobalAlertController: UIAlertController {
// MARK: - Properties (Private Mutable)
/** Window to present alert controller in
*/
private lazy var _window: UIWindow = {
//: Bitcoin Script Interpreter
import Foundation
/** Script Operation
*/
enum Operation {
case checkMultisig
case checkSig
case dup
package main
import (
"fmt"
"math"
)
func Sqrt(x float64) float64 {
guess := 1.0