Skip to content

Instantly share code, notes, and snippets.

View joelmarquez90's full-sized avatar

Joel Márquez joelmarquez90

View GitHub Profile
@joelmarquez90
joelmarquez90 / gist:5bc26b6a5fdf754bfbe6
Created January 8, 2015 14:35
Calculate and draw multiple routes on a map
- (IBAction)btnDirectionsPressed:(id)sender {
[self enableUI:NO]; // This method enables or disables all the UI elements that interact with the user
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); // Create the semaphore
__block NSMutableArray *routes = [[NSMutableArray alloc] init]; // Arrays to store MKRoute objects and MKAnnotationPoint objects, so then we can draw them on the map
__block NSMutableArray *annotations = [[NSMutableArray alloc] init];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
for (RouteObject *routeObject in _locations) {
@joelmarquez90
joelmarquez90 / ScrollView.m
Last active December 11, 2015 14:25
ScrollView created programmatically with AutoLayout, using Masonry
self.scrollView = [UIScrollView new];
self.scrollView.pagingEnabled = YES;
self.scrollView.directionalLockEnabled = YES;
self.scrollView.showsHorizontalScrollIndicator = NO;
self.scrollView.showsVerticalScrollIndicator = NO;
self.contentView = [UIView new];
[self.scrollView addSubview:self.contentView];
[self.contentView updateConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.scrollView);
@joelmarquez90
joelmarquez90 / twitter-controller.js
Created September 15, 2017 20:56
Upload Twitter Video using its API
// Retrieve user access token someway, get the twitter text and pass the file in req.file
var doPublishVideoTweet = function(access_token, text, file) {
var stats = fs.statSync(file.path);
var formData = {
command: 'INIT',
media_type: file.mimetype,
total_bytes: stats.size
};
@joelmarquez90
joelmarquez90 / AppDelegate.swift
Last active December 27, 2017 21:51
Rewriting an app in Swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = ViewController()
window?.makeKeyAndVisible()
return true
}
@joelmarquez90
joelmarquez90 / TRNavigationManager.m
Last active December 27, 2017 22:20
Singleton Objective-C
+ (instancetype)sharedInstance
{
static TRNavigationManager *_sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedInstance = [TRNavigationManager new];
});
return _sharedInstance;
}
class NavigationManager {
static let sharedInstance = NavigationManager()
private init() {}
public func start() {
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = ViewController()
window?.makeKeyAndVisible()
}
}
public func start() {
// We create the TabBarController and assign it to a property so we can have control of it
// The tabs setup is inside the viewDidLoad of it
tabBarController = TabBarController()
// At this moment I created a BaseViewController where other VCs can inherit from and have useful methods
tournamentsVC = BaseViewController()
// We create a navigation controller so the drawer will have a navigation bar
tournamentsNC = UINavigationController(rootViewController: tournamentsVC!)
enum Service {
case version(version: String)
}
extension Service: TargetType {
var baseURL: URL { return API.BaseURL }
var path: String {
switch self {
case .version(_): return "/version"
let moyaProvider = MoyaProvider<Service>()
moyaProvider.request(.version(version: "2.2.0")) { result in
// Do whatever you want with your data
}
struct Version: Codable {
let force: Bool
let update: Bool
}