Skip to content

Instantly share code, notes, and snippets.

Mick F dirtyhenry

View GitHub Profile
@dirtyhenry
dirtyhenry / Brewfile
Created Jul 1, 2020
A Makefile for Swift packages
View Brewfile
brew "swiftlint"
brew "swiftformat"
View TitleCase.pl
#!/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 Feb 23, 2020
A solution to the 711 problem: 1.2, 1.25, 1.5, 3.16
View 711.swift
//
// main.swift
// Maths2
//
// Created by Mickaël Floc'hlay on 23/02/2020.
// Copyright © 2020 mickf.net. All rights reserved.
//
import Foundation
View gist:ced0aef8a354f80c22e4a8b6ff3e06b2
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 / MyCell.swift
Created Oct 19, 2017
Definitive UICollectionViewCell dynamic size
View MyCell.swift
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 {
@dirtyhenry
dirtyhenry / keychain.swift
Created Jun 26, 2017
How to log and delete keychain items from your iOS app?
View keychain.swift
func iterateKeychainItems(log: Bool, delete: Bool) {
let secItemClasses = [
kSecClassGenericPassword,
kSecClassInternetPassword,
kSecClassCertificate,
kSecClassKey,
kSecClassIdentity
]
if (log) {
View Gemfile
# frozen_string_literal: true
source "https://rubygems.org"
gem 'cocoapods'
gem 'fastlane'
gem 'jazzy'
@dirtyhenry
dirtyhenry / appannie_histogram.R
Created Sep 14, 2016
R Script to get a plot of weekly/monthly downloads aggregations from App Annie files.
View appannie_histogram.R
#
# appannie_histogram.R
#
# Create weekly and monthly aggregations bar plots of your downloads
# from AppAnnie CSV files.
#
# Improvements:
#
# * First and last week of years can have much less than 7 days and create false
# decreases of downloads.
View test.css
body {
background-color: red;
}
@dirtyhenry
dirtyhenry / linear-optimization.rb
Created Aug 5, 2015
MITx 15.071x - Unit 8 - Linear Optimization - Radiation Therapy: An Application of Linear Optimization
View linear-optimization.rb
# Unit 8 of the Analytics Edge
#
# Minimize :
# z = (1 + 2) * X1 + (2 + 2.5) * X2 + 2.5 * X3 + X4 + 2 * X5 + (1 + 2 + 1) * X6
#
# Beamlet
# 1 - 1 2 2 0 0 0 0 0 0
# 2 - 0 0 0 1 2 2.5 0 0 0
# 3 - 0 0 0 0 0 0 1.5 1.5 2.5
# 4 - 1 0 0 2 0 0 1 0 0
You can’t perform that action at this time.