Skip to content

Instantly share code, notes, and snippets.

View ksmandersen's full-sized avatar
🏠
Working from home

Kristian Andersen ksmandersen

🏠
Working from home
View GitHub Profile
@Sidelobe
Sidelobe / duplicate_line_xcode.md
Last active February 3, 2023 08:10 — forked from emotality/duplicate_line_xcode.md
Xcode - Duplicate Line key binding

Xcode line duplication (without overwriting your clipboard)

I find this shortcut extremely useful in Xcode: duplicate one or several lines without losing what you have on the clipboard.

Bind keys to duplicate lines in Xcode

  1. To add custom key bindings in Xcode, you have to edit this file (su privileges required): '/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/Current/Resources/IDETextKeyBindingSet.plist

I add the following new key at the bottom:

@davbeck
davbeck / README.md
Created June 19, 2019 22:07
A wrapper for UICollectionViewDiffableDataSource that also handles updates to data

UICollectionViewDiffableDataSource does an excellent job of handling changes to data and updating the items accordingly. However, there seems to be no good way to handle updates to existing items. If you follow the samples that Apple provides and define Equatable and Hashable to use an id instead of the complete models value, value changes won't cause the collection view to update those cells. If you leave Equatable as it should be and have it compare all values of a model, the cell will update, but it will completely replace the old cell, causing an undesirable "flash".

UICollectionViewComparableDataSource wraps a UICollectionViewDiffableDataSource and will check for items that have been updated, but not removed or added.

This allows us to make updates to a cell without completely reloading it. This is especially usefull if your cells have some sort of temporary state.

This is just an expirement. Use at your own risk.

@joscdk
joscdk / env.md
Created December 5, 2018 14:45
Using .env files in Vapor 3

.env files can be an easy way to setup Environment variables locally. You can start using a .env files in Vapor 3 by following this small guide.

First setup the vapor-ext package in your Package.swift file:

.package(url: "https://github.com/vapor-community/vapor-ext.git", from: "0.1.0"),

Next create a .env file in the root of your project:

@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)
@armand1m
armand1m / withInitialData.js
Created November 15, 2017 22:38
Simple HOC for fetching data that is compatible with the SSR technique described by @BenLu here: https://medium.com/@benlu/ssr-with-create-react-app-v2-1-ee83fb767327
import React, { Component } from 'react';
const hasDataForThisKey = (staticContext) =>
(key) => staticContext && Object.keys(staticContext.data).includes(key);
const windowHasDataForThisKey = (window) =>
(key) => Object.keys(window.__DATA__).includes(key);
export default ({
key,
@fousa
fousa / FairPlayer.swift
Last active June 1, 2023 12:28
Integrate HLS with FairPlay.
class FairPlayer: AVPlayer {
private let queue = DispatchQueue(label: "com.icapps.fairplay.queue")
func play(asset: AVURLAsset) {
// Set the resource loader delegate to this class. The `resourceLoader`'s delegate will be
// triggered when FairPlay handling is required.
asset.resourceLoader.setDelegate(self, queue: queue)
// Load the asset in the player.
@lattner
lattner / TaskConcurrencyManifesto.md
Last active May 5, 2024 22:32
Swift Concurrency Manifesto
@troyfontaine
troyfontaine / 1-setup.md
Last active May 3, 2024 10:52
Signing your Git Commits on MacOS

Methods of Signing Git Commits on MacOS

Last updated March 13, 2024

This Gist explains how to sign commits using gpg in a step-by-step fashion. Previously, krypt.co was heavily mentioned, but I've only recently learned they were acquired by Akamai and no longer update their previous free products. Those mentions have been removed.

Additionally, 1Password now supports signing Git commits with SSH keys and makes it pretty easy-plus you can easily configure Git Tower to use it for both signing and ssh.

For using a GUI-based GIT tool such as Tower or Github Desktop, follow the steps here for signing your commits with GPG.

@ksmandersen
ksmandersen / ApplicationContext.swift
Created May 26, 2017 15:42
Coordinator Pattern in Swift
final class ApplicationContext {
// This is where you initialize most of the application stack
// that needs to be passed down to the coordinator chain for
// fetching data, and other important stuff.
// Example:
// let networkClient = NetworkClient()
}
@jgamblin
jgamblin / slackspotify.sh
Created April 19, 2017 01:10
A Script To Set Current Spotify Song As Slack Status
#!/bin/bash
APIKEY="From Here https://api.slack.com/custom-integrations/legacy-tokens"
SONG=$(osascript -e 'tell application "Spotify" to name of current track as string')
URLSONG=$(echo "$SONG" | perl -MURI::Escape -ne 'chomp;print uri_escape($_),"\n"')
while true
do
curl -s -d "payload=$json" "https://slack.com/api/users.profile.set?token="$APIKEY"&profile=%7B%22status_text%22%3A%22"$URLSONG"%22%2C%22status_emoji%22%3A%22%3Amusical_note%3A%22%7D" > /dev/null
sleep 60
done