Skip to content

Instantly share code, notes, and snippets.

View alexito4's full-sized avatar

Alejandro Martínez alexito4

View GitHub Profile
#import <Foundation/Foundation.h>
// typedef
typedef NSString*(^ConvertBlock)(NSString *text);
@interface Thing : NSObject
@property (nonatomic, strong) void (^coolPropertyBlock)(NSString *text); // Property
// method param
- (void)doSomething:(void(^)(NSString *text))block with:(NSString *)person;
@alexito4
alexito4 / gist:5be48be412d4aa44c60c
Created August 30, 2014 10:00
Understanding Value and Reference Types in Swift
// Understanding Value and Reference Types in Swift
/*
One of the coolest parts about Swift is how powerful all the types are. Structs are not like basic C structs, they have a lot of similarities with classes, and the same goes for the Enums. This is really good but also comes with the risk that newcomers doesn't know the differences between them. The oficial Swift blog has a great post about [Value and Reference Types](https://developer.apple.com/swift/blog/?id=10), read it.
In this post/playground I want to go step by step in some cases that will help newcomers understand how the different types work in Swift. It's good for people that comes form Objective-C to understand how Swift still has pointers, but hidden behind the language to make it safe. And for the newcomers, that doesn't know much about programming or *pointers*, will be good to understand what's actually happening behind the scenes.
## Categorization
Swift has two categories of Types: Value and Reference.
local wait = 60
os.loadAPI("weather")
local city = "London,uk"
while true do
local commandBlock = peripheral.wrap("back")
local w = weather.getWeather(city)
@alexito4
alexito4 / Amazing.h
Last active August 29, 2015 14:14
Add XCTest at runtime
#import <Foundation/Foundation.h>
#import "Smiler.h"
@interface Amazing : NSObject <Smiler>
@end
@alexito4
alexito4 / srly.rb
Created January 26, 2015 19:05
Download youtube videos form the safari reading list. More info at: http://www.alejandromp.com/blog/2015/1/26/download-youtube-videos-from-the-safari-reading-list
require 'nokogiri-plist'
require 'uri'
class SRLItem
attr_accessor :title
attr_accessor :url
attr_accessor :source
def initialize(dict)
@alexito4
alexito4 / hang.swift
Last active September 4, 2015 07:00
Is this not valid in Swift? Tried on Xcode 7b6
protocol Stack {
typealias Element
mutating func push(value: Element)
mutating func pop() -> Element?
}
struct ArrayStack<T>: Stack {
....
@alexito4
alexito4 / gist:3582382
Created September 1, 2012 18:22
AFNetworking - UIImageView+AFNetworking - New method setImageURL + blocks
/*
If you want to use blocks the only method that works is:
setImageWithURLRequest:placeholderImage:success:failure:
But you don't want to use URLRequest!
*/
// .h
- (void)setImageWithURL:(NSURL *)url
placeholderImage:(UIImage *)placeholderImage
@alexito4
alexito4 / monitordb.sh
Created September 4, 2012 08:10
Easy acces to Android emulator database
#!/bin/sh
while :
do
./querydb.sh
sleep 2
done
@alexito4
alexito4 / UIViewController+ModalCheck.h
Created October 11, 2012 21:04
Checking whether ViewController is presented as Modal
// UIViewController+ModalCheck.h
//
// Created by Felipe Sabino on 06/14/11
#import <UIKit/UIKit.h>
@interface UIViewController (ModalCheck)
-(BOOL)isPresentedAsModal;
@alexito4
alexito4 / gist:4249907
Created December 10, 2012 10:46
Responsive youtube, videos...
embed, iframe, object { max-width: 100%; }