Skip to content

Instantly share code, notes, and snippets.

View nathanborror's full-sized avatar

Nathan Borror nathanborror

View GitHub Profile
class TextViewCell: UITableViewCell {
var onTap: ((URL) -> Void)?
lazy var textView: UITextView = {
let view = UITextView()
view.translatesAutoresizingMaskIntoConstraints = false
view.backgroundColor = UIColor(red: 1.0, green: 0, blue: 0, alpha: 0.1)
view.textContainer.lineFragmentPadding = 0
view.textContainerInset = .zero
#!/bin/bash
#
# Generate RSA certificate and key
#
# The 'host' is the host on which the server is listening and 'prefix' is just
# used to prefix the output files.
#
# $ gen.sh <host> <prefix>
#

Using Swift Package Manager with iOS

Step 1:

File > New > Project...

Step 2:

Create a Package.swift file in your root project directory, add dependencies, then run swift package fetch on the command line in the same directory. We’re not going to run swift build because it will just complain.

//
// PagerController.swift
//
import UIKit
open class PagerController: BaseViewController {
let scrollView = UIScrollView()
let viewControllers: [UIViewController]
// Table Cells
protocol TableCell {
associatedtype A: Any
associatedtype Cell: UITableViewCell
static func cell(for items: [A], at indexPath: IndexPath, of tableView: UITableView, configure: (cell: Cell, item: A) -> Void) -> Cell
}
extension NSMutableAttributedString {
func add(attribute: Attribute, range: NSRange) throws {
guard (range.location + range.length) <= length else {
throw AttributedStringError.InvalidRange(range: range)
}
addAttribute(attribute.name, value: attribute.value, range: range)
}
}

tshark

Capturing traffic

Capture some traffic and save in ‘pcap’ format:

$ tshark -w capture.pcap

Reading captured data

// Markup (based on Draft.js: http://facebook.github.io/draft-js)
package draft
import (
"encoding/json"
"fmt"
)
type Markup struct {
Blocks []Block `json:"blocks"`
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let builder = HelloRequest.Builder()
builder.name = "Bob"
do {
let req = try builder.build()
defmodule Nthn.Entry.Handler do
import Ecto.Query
alias Nthn.Entry
alias Nthn.Repo
def init({:tcp, :http}, req, opts) do
{:ok, req, opts}
end
def handle(req, state) do