Skip to content

Instantly share code, notes, and snippets.

View eneko's full-sized avatar
💻

Eneko Alonso eneko

💻
View GitHub Profile
@eneko
eneko / isEmoji.swift
Created July 23, 2019 23:56
Determine if a Character is an emoji, in Swift
extension Character {
var isEmoji: Bool {
return Character(UnicodeScalar(UInt32(0x1d000))!) <= self && self <= Character(UnicodeScalar(UInt32(0x1f77f))!)
|| Character(UnicodeScalar(UInt32(0x2100))!) <= self && self <= Character(UnicodeScalar(UInt32(0x26ff))!)
}
}
@eneko
eneko / retain_cycles.swift
Last active February 8, 2019 17:56
Function references and retain cycles
class MyClass {
var foo: () -> Void = {}
init() {
foo = defaultFoo
}
private func defaultFoo() {
print("Foo Bar")
}
deinit {
print("MyClass Released 🎉") // Never gets called, retain cycle
@eneko
eneko / List.swift
Last active July 29, 2018 12:21
Linked List in Swift
/// A list is either empty or it is composed of a first element (head)
/// and a tail, which is a list itself.
///
/// See http://www.enekoalonso.com/projects/99-swift-problems/#linked-lists
class List<T> {
var value: T
var nextItem: List<T>?
convenience init?(_ values: T...) {
self.init(Array(values))
@eneko
eneko / Output
Created January 2, 2018 19:59
Swift 4 Dispatch on Linux
$ swift run
Hello, world!
Bye!
$ whois google.com
Whois Server Version 2.0
Domain names in the .com and .net domains can now be registered
with many different competing registrars. Go to http://www.internic.net
for detailed information.
GOOGLE.COM.ACKNOWLEDGES.NON-FREE.COM.NAMESILO.COM
GOOGLE.COM.AFRICANBATS.ORG
@eneko
eneko / instabug.md
Last active May 18, 2017 18:25
Instabug -> GitHub Integration issue
@eneko
eneko / xcodeclean.sh
Created July 19, 2016 00:04
xcodeclean
alias xcodeclean='rm -frd ~/Library/Developer/Xcode/DerivedData/* && rm -frd ~/Library/Caches/com.apple.dt.Xcode/*'
@eneko
eneko / cache.swift
Created October 25, 2016 03:13
Basic cache, failing on Ubuntu 14.04 with Swift 3.0
import Foundation
fileprivate class CachedItem<T> {
let value: T
fileprivate init(value: T) {
self.value = value
}
}
@eneko
eneko / ergast-indices.sql
Last active November 30, 2016 06:17
Ergast MySQL indices
-- Constructor Standings
alter table constructorstandings add index (constructorid);
alter table constructorstandings add index (raceid);
alter table constructorstandings add unique index constructorrace (constructorid, raceid);
-- Drivers
alter table drivers add unique index driverref (driverref);
-- Driver Standings
alter table driverstandings add index (driverid);
@eneko
eneko / gist:77153be33607e23cc6984e8af5bb46b0
Created September 30, 2016 21:34
Final run of vapor swift install script
$ curl -sL swift.vapor.sh/ubuntu | bash
Swift 3 Quick Installer
🖥 Operating System: ubuntu1404
📦 Installing Dependencies
🔒 Sudo required
Ign http://eu-west-1.ec2.archive.ubuntu.com trusty InRelease
Hit http://eu-west-1.ec2.archive.ubuntu.com trusty-updates InRelease
Hit http://eu-west-1.ec2.archive.ubuntu.com trusty-backports InRelease
Hit http://eu-west-1.ec2.archive.ubuntu.com trusty Release.gpg
Hit http://eu-west-1.ec2.archive.ubuntu.com trusty Release