Skip to content

Instantly share code, notes, and snippets.

View NunoAlexandre's full-sized avatar

Nuno NunoAlexandre

View GitHub Profile
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
-- Support for https://nunoalexandre.com/2018/01/28/a-case-for-dependent-types
data ValueType = StringType | IntType
<?xml version="1.0" ?>
<items>
<item>
<title>IPode</level>
<price>1.15</price>
</item>
<item>
<title>iPadi</level>
<price>2.15</price>
</item>
### Command
``` bash
stack test --fast --test-arguments '-m "<identifier>"'
```
The `<identifier>` can be pretty much anything:
- Part of / a module's name
- A `describe` / `it` description
@NunoAlexandre
NunoAlexandre / feed.xml
Last active May 1, 2018 13:22
feed.xml
<?xml version='1.0' encoding='utf-8'?>
<items>
<item>
<additional_imagelinks>http://example.com/one.jpg</additional_imagelinks>
<additional_imagelinks>http://example.com/two.jpg</additional_imagelinks>
<additional_imagelinks>http://example.com/three.jpg</additional_imagelinks>
<profit>-9.4 EUR</profit>
<comma>-9,15</comma>
<numberz>--9.77EUR</numberz>
<numberpoints>-9..77EUR</numberpoints>
@NunoAlexandre
NunoAlexandre / proceduralModeling.swift
Last active December 23, 2018 10:38
Procedural modeling
class Slideshow: UIViewController {
let slides: [SlideView]
init(slides: [SlideView]) {
self.slides = slides
}
// UI & Layout code goes here...
}
@NunoAlexandre
NunoAlexandre / createSlideshowProcedural.swift
Created December 23, 2018 10:40
Create a Slideshow - Procedural Modeling
let slideshow = Slideshow(
slides: [
SlideView(index: 0),
SlideView(index: 1),
SlideView(index: 2)
]
)
@NunoAlexandre
NunoAlexandre / typedModeling.swift
Last active December 23, 2018 10:51
Typed Modeling
class Slideshow: UIView {
let slides: [SlideView]
// UI & Layout code goes here...
}
class SlideView: UIView {
let slide: Slide
// UI & Layout code goes here...
@NunoAlexandre
NunoAlexandre / createSlideshowTyped.swift
Last active December 23, 2018 10:53
Create Slideshow - Typed Modeling
let slides = [
Slide(
title: "Bobby Mcferrin",
description: "Jazz at its best",
image: UIImage(name: "BobbyMcferrin")!
),
Slide(
title: "Kurt Vile",
description: "A prolific creative",
image: UIImage(name: "KurtVile")!
@NunoAlexandre
NunoAlexandre / downloadBefore.swift
Created March 23, 2019 19:19
A callback hell downloading an item
@discardableResult
func downloadSpecificActivity(activityInfo: SpecificActivityFirebase, completion: @escaping ((URL?, Error?) -> Void), progress: ((Double?) -> Void)? = nil) -> ContentDownload? {
if SettingsManager.shared.wifiOnlyEnabled && SettingsManager.shared.reachabilityManager?.isReachableOnWWAN ?? false {
completion(nil, ContentError.notAllowedOnWWanError)
} else if SettingsManager.shared.reachabilityManager != nil && !SettingsManager.shared.reachabilityManager!.isReachable {
completion(nil, ContentError.notConnected)
} else {
let downloadStartDate = Date.now()
if let tempUrl = temporaryDownloadUrl(forSpecificActivity: activityInfo) {
@discardableResult
func attemptDownload(forItem item: Item) -> Promise<URL> {
if !canSubmitDownload(forItem: item) {
return Promise.reject(DownloadError.duplicatedDownload)
}
else if !SettingsManager.shared.canDownloadOrStream() {
let error = DownloadError.canNotUseInternet
self.registerFailedDownload(item, withError: error)
return Promise.reject(error)
}