Skip to content

Instantly share code, notes, and snippets.

Avatar

Nathan Borror nathanborror

View GitHub Profile
View entity.go
/*
Package entity implements functions to store and manipulate entity records
in a schema-less database. The current implementation supports Postgres only.
Inspired by: https://backchannel.org/blog/friendfeed-schemaless-mysql
Example implementation:
type Account struct {
ID string
Name string
View startapp.go
package main
//go:generate esc -o static.go -prefix "/" static
import (
"flag"
"fmt"
"os"
"text/template"
)
View TextViewCell.swift
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
View gen.sh
#!/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>
#
View Using Swift Package Manager with iOS.md

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.

View PagerController.swift
//
// PagerController.swift
//
import UIKit
open class PagerController: BaseViewController {
let scrollView = UIScrollView()
let viewControllers: [UIViewController]
View ViewModel.swift
// 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
}
View NSAttributedString.swift
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)
}
}
View tshark.md

tshark

Capturing traffic

Capture some traffic and save in ‘pcap’ format:

$ tshark -w capture.pcap

Reading captured data

View draft.go
// Markup (based on Draft.js: http://facebook.github.io/draft-js)
package draft
import (
"encoding/json"
"fmt"
)
type Markup struct {
Blocks []Block `json:"blocks"`