Skip to content

Instantly share code, notes, and snippets.

View dirtyhenry's full-sized avatar

Mick F dirtyhenry

View GitHub Profile
@dirtyhenry
dirtyhenry / deploy_website.yml
Created October 24, 2023 08:48
Deploy Jekyll site on GitHub Pages
name: Deploy Website
on:
push:
branches:
- main
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
# 📜 https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch
permissions:
@dirtyhenry
dirtyhenry / keychain.swift
Created June 26, 2017 11:27
How to log and delete keychain items from your iOS app?
func iterateKeychainItems(log: Bool, delete: Bool) {
let secItemClasses = [
kSecClassGenericPassword,
kSecClassInternetPassword,
kSecClassCertificate,
kSecClassKey,
kSecClassIdentity
]
if (log) {
@dirtyhenry
dirtyhenry / Component.test.tsx
Last active May 25, 2021 12:55
React Component Test Template
import { ComponentProps, ReactNode } from 'react';
import { Store } from 'common/store/test-utils/factories';
import expectRenderError from 'test-utils/expectRenderError';
import { fireEvent, renderWithHoc } from 'test-utils/helpers';
import XXX from '..';
type RenderComponentProps = {
props: Partial<ComponentProps<typeof XXX>>;
@dirtyhenry
dirtyhenry / inter-features-list
Created January 3, 2021 15:58
The output of listFeatures for the Inter-Bold font
["CTFeatureTypeIdentifier": 0, "CTFeatureTypeName": All Typographic Features, "CTFeatureTypeSelectors": <__NSArrayM 0x600003b95bf0>(
{
CTFeatureSelectorDefault = 1;
CTFeatureSelectorIdentifier = 0;
CTFeatureSelectorName = On;
}
)
]
["CTFeatureTypeIdentifier": 1, "CTFeatureTypeName": Ligatures, "CTFeatureTypeSelectors": <__NSArrayM 0x600003b95680>(
{
@dirtyhenry
dirtyhenry / Brewfile
Created July 1, 2020 19:20
A Makefile for Swift packages
brew "swiftlint"
brew "swiftformat"
#!/usr/bin/perl
# This filter changes all words to Title Caps, and attempts to be clever
# about *un*capitalizing small words like a/an/the in the input.
#
# The list of "small words" which are not capped comes from
# the New York Times Manual of Style, plus 'vs' and 'v'.
#
# 10 May 2008
# Original version by John Gruber:
@dirtyhenry
dirtyhenry / 711.swift
Last active February 23, 2020 15:45
A solution to the 711 problem: 1.2, 1.25, 1.5, 3.16
//
// main.swift
// Maths2
//
// Created by Mickaël Floc'hlay on 23/02/2020.
// Copyright © 2020 mickf.net. All rights reserved.
//
import Foundation
let url1 = try! FileManager.default.url(for: .documentDirectory,
in: .userDomainMask,
appropriateFor: nil,
create: false)
.appendingPathComponent("1234")
let url2 = URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0])
.appendingPathComponent("1234")
debugPrint("Same URL? \(url1 == url2)")
@dirtyhenry
dirtyhenry / poc-openssl-aes.rb
Last active June 5, 2018 11:48
Encryption interoperability demo between Ruby and OpenSSL
require 'openssl'
require 'base64'
# Read the dummy file
data = File.read("test.txt")
# Create an encrypter
cipher = OpenSSL::Cipher::AES.new(256, :CBC)
cipher.encrypt
key = cipher.random_key
@dirtyhenry
dirtyhenry / MyCell.swift
Created October 19, 2017 14:53
Definitive UICollectionViewCell dynamic size
class FooCell: UICollectionViewCell {
private var sizingOnlyWidthConstraint: NSLayoutConstraint? = nil
func sizeWith(width: CGFloat, myString: String) -> CGSize {
if sizingOnlyWidthConstraint == nil {
sizingOnlyWidthConstraint = NSLayoutConstraint(item: self, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: width)
sizingOnlyWidthConstraint?.isActive = true
}
if sizingOnlyWidthConstraint!.constant != width {