Skip to content

Instantly share code, notes, and snippets.

@jjrscott
jjrscott / RecursiveSequence.swift
Created March 31, 2022 11:23
Closure based recursive sequence for Swift
//
// RecursiveSequence.swift
//
// Created by John Scott on 31/03/2022.
//
///
/// To define a sequence by recursion, one needs a rule, called recurrence relation to construct each
/// element in terms of the ones before it. In addition, enough initial elements must be provided so
/// that all subsequent elements of the sequence can be computed by successive applications of
@jjrscott
jjrscott / BidirectionalCollection+RegularExpressions.swift
Created July 15, 2020 21:01
Reimplementation of Brian Kernighan's Regular Expression Matcher on BidirectionalCollection
//
// RegularExpression.swift
// RegularExpressions
//
// Created by John Scott on 15/07/2020.
//
// Original matching implementation Brian Kernighan : https://www.cs.princeton.edu/courses/archive/spr09/cos333/beautiful.html
// Swift port Ben Cohen : https://github.com/apple/swift/blob/a9eee38e109e3d99f103a9bee71bed4422fbb6fd/benchmark/single-source/StringMatch.swift
import Foundation
@jjrscott
jjrscott / resign_ipa.pl
Created May 3, 2019 14:55
Script to resign an IPA file (packaged iOS application)
#!/usr/bin/perl
use strict;
use Data::Dumper;
use Getopt::Long;
use File::Temp 'tempdir';
use DirHandle;
use File::Slurp;
my $tempdir = tempdir(CLEANUP => 1);
@jjrscott
jjrscott / Optional+SupportsCount.swift
Last active March 3, 2019 16:50
Shortens `anArray.count ?? 0` to `anArray.count` just like in ObjC
//
// Optional+SupportsCount.swift
//
// Created by John Scott on 02/03/2019.
//
/**
This file contains a little syntactic sugar to help the Objective-C oldies.
@jjrscott
jjrscott / git-sync
Created November 20, 2018 11:24
Commits and pushes EVERYTHING. Useful for pair programming and using git as a syncing mechanism
#!/usr/bin/perl
use strict;
use Getopt::Long;
warn "Stage\n";
qx(git add -A -v);
warn "Commit\n";
qx(git commit -a --allow-empty-message -m '' -v);
@jjrscott
jjrscott / JJRSIfKind.h
Created June 18, 2018 14:02
An ObjC equivalent of Swift's `if let`
//
// JJRSIfKind.h
// JJRSFoundation
//
// Copyright © 2018 John Scott ( https://jjrscott.com )
//
// This file is MIT licensed.
// Usage: ifkind (existing variable, required class name) { ... }
#define ifkind(anExistingVariable, aClass) __ifkind(anExistingVariable, aClass, __ifkind_temp(__COUNTER__))
@jjrscott
jjrscott / UIViewController+InlineSeques.h
Last active June 6, 2018 15:55
Programmatically calling segues with block preparation
//
// UIViewController+InlineSeques.h
//
// MIT License
//
// Copyright © 2018 John Scott.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
#!/usr/bin/perl
# This script builds an archive release of a project. It should be run thus:
# $ cd <the project directory>
# $ build_project
use strict;
use Data::Dumper;
use Getopt::Long;
@jjrscott
jjrscott / pdf2appiconset.pl
Created September 16, 2016 08:15
Fill up the ever expanding AppIcon.appiconset directory using a single PDF.
#!/usr/bin/perl
#
# This script will take your nice AppIcon in PDF format and resize it to all the different
# sizes inside the AppIcon.appiconset directory.
#
# Usage example:
#
# ./pdf2appiconset.pl <AppIcon.appiconset directory> <PDF path>
#
@jjrscott
jjrscott / AffineTransformMakeFromPointToPoint.m
Last active August 29, 2015 14:06
Use two points to generate a transform which will rotate one the start point to the angle of the second.
CGAffineTransform AffineTransformToPositionOnLines(const CGPoint points[],
size_t count,
CGFloat position,
BOOL rotate)
{
CGAffineTransform transform = CGAffineTransformIdentity;
if (count > 1)
{
for (size_t index = 0;index<count-1;index++)