Skip to content

Instantly share code, notes, and snippets.

@jeantimex
jeantimex / SwiftyLibTests.swift
Created February 24, 2019 19:16
SwiftyLibTests.swift - Part 1
//
// SwiftyLibTests.swift
//
import XCTest
@testable import SwiftyLib
class SwiftyLibTests: XCTestCase {
var swiftyLib: SwiftyLib!
@jeantimex
jeantimex / SwiftyLib.swift
Last active February 24, 2019 18:53
SwiftyLib.swift
//
// SwiftyLib.swift
//
public final class SwiftyLib {
let name = "SwiftyLib"
public func add(a: Int, b: Int) -> Int {
return a + b
@jeantimex
jeantimex / PromisAllWithFails.js
Created August 21, 2018 22:05 — forked from nhagen/PromisAllWithFails.js
Wait until all promises have completed even when some reject, with Promise.all
var a = ["sdfdf", "http://oooooolol"],
handleNetErr = function(e) { return e };
Promise.all(fetch('sdfdsf').catch(handleNetErr), fetch('http://invalidurl').catch(handleNetErr))
.then(function(sdf, invalid) {
console.log(sdf, invalid) // [Response, TypeError]
})
.catch(function(err) {
console.log(err);
})
@jeantimex
jeantimex / iterm2-solarized.md
Created July 27, 2017 17:58 — forked from kevin-smets/iterm2-solarized.md
iTerm2 + Oh My Zsh + Solarized color scheme + Meslo powerline font + [Powerlevel9k] - (macOS)

Default

Default

Powerlevel9k

Powerlevel9k

override func viewDidLoad() {
super.viewDidLoad()
// Auto resizing the height of the cell
tableView.estimatedRowHeight = 44.0
tableView.rowHeight = UITableViewAutomaticDimension
...
}
@jeantimex
jeantimex / toggleSection.swift
Last active July 19, 2017 19:07
toggleSection
extension CollapsibleTableViewController: CollapsibleTableViewHeaderDelegate {
func toggleSection(_ header: CollapsibleTableViewHeader, section: Int) {
let collapsed = !sections[section].collapsed
// Toggle collapse
sections[section].collapsed = collapsed
header.setCollapsed(collapsed)
// Reload the whole section
tableView.reloadSections(NSIndexSet(index: section) as IndexSet, with: .automatic)
@jeantimex
jeantimex / heightForRowAtIndexPath.swift
Last active July 19, 2017 19:06
heightForRowAtIndexPath
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return sections[(indexPath as NSIndexPath).section].collapsed ? 0 : UITableViewAutomaticDimension
}
@jeantimex
jeantimex / cellForRowAtIndexPath.swift
Created October 2, 2016 02:03
cellForRowAtIndexPath
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell? ?? UITableViewCell(style: .Default, reuseIdentifier: "cell")
cell.textLabel?.text = sections[indexPath.section].items[indexPath.row]
return cell
}
@jeantimex
jeantimex / viewForHeaderInSection.swift
Created October 2, 2016 02:03
viewForHeaderInSection
override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let header = tableView.dequeueReusableHeaderFooterViewWithIdentifier("header") as? CollapsibleTableViewHeader ?? CollapsibleTableViewHeader(reuseIdentifier: "header")
header.titleLabel.text = sections[section].name
header.arrowLabel.text = ">"
header.setCollapsed(sections[section].collapsed)
header.section = section
header.delegate = self
return header
}
@jeantimex
jeantimex / numberOfRowsInSection.swift
Last active July 19, 2017 19:06
numberOfRowsInSection
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return sections[section].collapsed ? 0 : sections[section].items.count
}