Skip to content

Instantly share code, notes, and snippets.

View alexito4's full-sized avatar

Alejandro Martínez alexito4

View GitHub Profile
@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 / keybase.md
Created February 11, 2016 11:06
keybase.md

Keybase proof

I hereby claim:

  • I am alexito4 on github.
  • I am alejandromp (https://keybase.io/alejandromp) on keybase.
  • I have a public key whose fingerprint is F281 C10D C3E7 50B6 E256 ABCC DB9D C4B2 043A 15C9

To claim this, I am signing this object:

@alexito4
alexito4 / sessionslist.txt
Created June 6, 2018 18:39
WWDC 18 List of Sessions
What's New in Swift
Creating Apps for a Global Audience
Introducing Podcast Analytics
What's New in Cocoa Touch
Using Accelerate and simd
Live Screen Broadcast with ReplayKit
I Have This Idea For An App...
Automatic Strong Passwords and Security Code AutoFill
Measuring and Optimizing HLS Performance
What’s New in ARKit 2
@alexito4
alexito4 / lists.swift
Last active May 8, 2019 14:35
Swift script to convert Reminders export files (.ics) to lists.
#!/usr/bin/swift sh
import Foundation
guard let path = CommandLine.arguments.dropFirst().first else { exit(1) }
print(path)
let content = try! String(contentsOfFile: path)
let lines = content
@alexito4
alexito4 / RemoteImage.swift
Last active August 19, 2020 15:32
Rough sketch of SwiftUI RemoteImage using AlamofireImage
import SwiftUI
import Combine
import AlamofireImage
let imageDownloader = ImageDownloader(
configuration: ImageDownloader.defaultURLSessionConfiguration(),
downloadPrioritization: .fifo,
maximumActiveDownloads: 4,
imageCache: AutoPurgingImageCache()
)
@alexito4
alexito4 / markAllFilesAsViewed.js
Created October 15, 2019 09:28
GitHub PR Mark ALL files as viewed
for (const checkbox of document.querySelectorAll('.js-reviewed-checkbox')) {
if (checkbox.attributes["data-ga-click"].value.includes("value:false")) {
checkbox.click();
}
}