Skip to content

Instantly share code, notes, and snippets.

@nicklockwood
nicklockwood / main.swift
Created May 18, 2020 22:58
A simple one-file language parser and compiler test
import Foundation
enum LexingError: Error, Equatable {
case syntaxError(String)
case unexpectedEOF
}
enum ParsingError: Error {
case expected(String)
case unexpectedToken(Token)
@Dev1an
Dev1an / Above.swift
Created March 7, 2020 00:35
Show a SwiftUI View floating above another View without altering its layout.
import SwiftUI
extension View {
func float<Content: View>(above: Content) -> ModifiedContent<Self, Above<Content>> {
self.modifier(Above(aboveContent: above))
}
}
struct Above<AboveContent: View>: ViewModifier {
let aboveContent: AboveContent
@chriseidhof
chriseidhof / collectionview.swift
Last active January 31, 2024 19:00
SwiftUI Flow Layout
//
// ContentView.swift
// DeleteMe
//
// Created by Chris Eidhof on 02.02.21.
//
import SwiftUI
/*
@firyalff
firyalff / base64S3Upload.go
Created July 18, 2018 08:25
Upload base64 encoded file to S3 using go and AWS SDK
package main
import (
"bytes"
"encoding/base64"
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active February 14, 2026 18:42
Making efficient use of the libdispatch (GCD)

libdispatch efficiency tips

The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).

My take-aways are:

  • You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.

  • Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse

@RomanVolkov
RomanVolkov / Cacher.swift
Created January 9, 2017 13:48
Cacher for iOS
import Foundation
public protocol Cachable {
var fileName: String { get }
func transform() -> Data
}
final class Cacher {
let destination: URL
private let queue = OperationQueue()
@lennet
lennet / Cache.swift
Last active April 27, 2018 21:28
Generic NSCache in Swift
import Foundation
class Cache<T: AnyObject>: NSCache {
subscript(key: AnyObject) -> T? {
get {
return objectForKey(key)
}
set {
if let value = newValue {
@emaloney
emaloney / upgrade-weak-self.md
Last active March 9, 2018 20:12
Allow using optional binding to upgrade a weakly-captured self to a strong reference

Allow using optional binding to upgrade self from a weak to strong reference

  • Proposal: TBD
  • Author: Evan Maloney
  • Status: Draft
  • Review manager: TBD

Introduction

When working with escaping Swift closures, it is a common pattern to have the closure capture self weakly to avoid creating an object reference cycle.

@yancyn
yancyn / godaddydomain.md
Last active January 27, 2026 22:32
Setup Godaddy Domain for GitHub Page

Setup Godaddy Domain for GitHub Page

  1. Create a new file CNAME and put the domain.com in the file.
  2. Login GoDaddy > Manage domain > DNS Zone File.
  3. Under A (Host) change @ point to 192.30.252.153.
  4. Under CName (Alias) change www point to website.github.io.

see also GitHub Pages + GoDaddy

@paucoma
paucoma / gglCalEventsOnSpreadSheet.gs
Last active April 25, 2025 15:08
Script to read Google Calendar Events and Count total Hours
const gblFrom = {
year : 2020 ,
month : 3,
day : 29,
hour : 0
};
const gblTo = {
year : 2020 ,
month : 8,
day : 1,