Skip to content

Instantly share code, notes, and snippets.

View axelrivera's full-sized avatar

Axel Rivera axelrivera

View GitHub Profile
@axelrivera
axelrivera / MKMapView+ShowHide.swift
Created May 1, 2023 23:29 — forked from danielrotaermel/MKMapView+ShowHide.swift
MKAnnotationView extensions to show/hide annotations completely
//
// MKMapView+ShowHide.swift
//
// Created by Daniel Rotärmel on 27.10.20.
//
import MapKit
// MKAnnotationView extensions to show/hide annotations completely
extension MKMapView {
import Foundation
typealias TableInfo = [String: Any]
typealias TableSectionArray = [TableSection]
typealias TableRowArray = [TableRow]
struct TableSection {
var groupIdentifier: String?
var identifier: String?
var title: String?
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
upColor = ParamColor("Up Color", colorBlack);
downColor = ParamColor("Down Color", colorRed);
Plot(C, "Close", IIf(C >= Ref(C, -1), upColor, downColor), styleBar);
extension NSURLSession {
class func sendSynchronousRequest(request: NSURLRequest, inout returningResponse: NSHTTPURLResponse?, inout error: NSError?) -> NSData? {
var data: NSData?
var sem: dispatch_semaphore_t
sem = dispatch_semaphore_create(0)
NSURLSession.sharedSession().dataTaskWithRequest(request) { (requestData, requestResponse, requestError) in
@axelrivera
axelrivera / TableUtils.swift
Created November 29, 2015 18:42
Custom data structures to help with complex UITableViews
import UIKit
typealias TableInfo = [String: Any]
typealias TableSectionArray = [TableSection]
typealias TableRowArray = [TableRow]
enum TableRowType {
case Text
case Detail
case Subtitle
@axelrivera
axelrivera / UIColor+Hex.swift
Created December 29, 2014 14:12
UIColor+Hex
extension UIColor {
convenience init(hex: NSInteger) {
self.init(hex: hex, alpha: 1.0)
}
convenience init (hex: NSInteger, alpha: CGFloat) {
let red = CGFloat((hex & 0xFF0000) >> 16) / 255.0
let green = CGFloat((hex & 0xFF00) >> 8) / 255.0
let blue = CGFloat((hex & 0xFF)) / 255.0
@axelrivera
axelrivera / SwiftUtilities.swift
Last active August 3, 2017 15:40
A repository of my frequently used methods and macros in swift
//
// SwiftUtilities.swift
//
// Created by Axel Rivera on 12/21/14.
// Copyright (c) 2014 Axel Rivera. All rights reserved.
//
import Foundation
// MARK: - Macros
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {
// do some stuff in the background
let string = "my string"
// remove if you don't need to call the main queue
dispatch_async(dispatch_get_main_queue(), {
// do some stuff in the main queue
// mostly call the UI
})
// end of remove
var query: PFQuery = PFQuery(className: "userPhoto")
query.findObjectsInBackgroundWithBlock { [weak self] (objects, error) -> Void in
if let weakSelf = self {
println("Got \(objects.count) entries")
weakSelf.feedData = objects
weakSelf.tableView.reloadData()
}
}
@implementation UITextView (Annex)
@dynamic visibleTextRange;
- (NSRange)visibleTextRange
{
CGRect bounds = self.bounds;
CGSize textSize = [self.text sizeWithFont:self.font constrainedToSize:bounds.size];
UITextPosition *start = [self characterRangeAtPoint:bounds.origin].start;