Skip to content

Instantly share code, notes, and snippets.

View mtancock's full-sized avatar

Matt Tancock mtancock

View GitHub Profile
@algal
algal / Zipping.swift
Created February 17, 2019 01:18
Zip files on iOS, without using external libraries and without interoperating with the low-level Compression framework
// Zipping.swift
// known-good: Swift 4.2
// Alexis Gallagher
import Foundation
public extension URL {
/// Creates a zip archive of the file or folder represented by this URL and returns a references to the zipped file
///
@vzsg
vzsg / 1_Fetch.swift
Last active June 25, 2021 10:37
A solution for the N+1 problem when fetching children for parents (Fluent 3)
import Fluent
func fetchChildren<Parent, ParentID, Child: Model, Result>(
of parents: [Parent],
idKey: KeyPath<Parent, ParentID?>,
via reference: KeyPath<Child, ParentID>,
on conn: DatabaseConnectable,
combining: @escaping (Parent, [Child]) -> Result) -> Future<[Result]> where ParentID: Hashable & Encodable {
let parentIDs = parents.compactMap { $0[keyPath: idKey] }
let children = Child.query(on: conn)
@codingwaysarg
codingwaysarg / PlaceHolderFastImage.js
Created June 18, 2018 15:16
FastImage placeholder wrapper
import React, { Component } from 'react'
import { ActivityIndicator, View, StyleSheet } from 'react-native'
import { Images, Metrics } from '../Themes'
import FastImage from 'react-native-fast-image'
export default class PlaceHolderFastImage extends Component {
constructor(props){
super(props)
this.state = {