Skip to content

Instantly share code, notes, and snippets.

@JohnCoates
JohnCoates / generateRandomPastelColor.swift
Last active December 5, 2022 14:20
Randomly generate pastel UIColor in Swift
// Adapted from Stack Overflow answer by David Crow http://stackoverflow.com/a/43235
// Question: Algorithm to randomly generate an aesthetically-pleasing color palette by Brian Gianforcaro
// Method randomly generates a pastel color, and optionally mixes it with another color
func generateRandomPastelColor(withMixedColor mixColor: UIColor?) -> UIColor {
// Randomly generate number in closure
let randomColorGenerator = { ()-> CGFloat in
CGFloat(arc4random() % 256 ) / 256
}
var red: CGFloat = randomColorGenerator()
@JohnCoates
JohnCoates / Async.swift
Created September 16, 2015 04:23
Fixes issue in duemunk/Async by using an Objective-C helper class, adapted from sample code at https://forums.developer.apple.com/message/50963
//
// Async.swift
//
// Created by Tobias DM on 15/07/14.
//
// OS X 10.10+ and iOS 8.0+
// Only use with ARC
//
// The MIT License (MIT)
// Copyright (c) 2014 Tobias Due Munk
@JohnCoates
JohnCoates / Less Example.less
Last active October 17, 2015 23:52
CSSketch Examples
// Match based on class
.shadow {
@horizontal: 1px;
@vertical: 2px;
@blur: 15px;
@spread: 2px;
@color: rgba(0,0,0,0.4);
box-shadow: @horizontal @vertical @blur @spread @color;
}
@JohnCoates
JohnCoates / readPhotoshopIconNames.php
Last active November 3, 2020 12:47
extract PSIconsHighRes.dat & IconResources.idx - filetype:| Photoshop Icon Resource Index 1.0
<?php
$filepath = "/Applications/Adobe Photoshop CC 2017/Adobe Photoshop CC 2017.app/Contents/Resources/IconResources.idx";
$headerMagic = "Photoshop Icon Resource Index 1.0\n";
$fp = fopen($filepath, "r");
$magic = fread($fp, strlen($headerMagic));
if ($magic != $headerMagic) {
exit("error: wrong magic");
@JohnCoates
JohnCoates / Readme.md
Last active August 23, 2021 16:54
extract PSIconsHighRes.dat & IconResources.idx - filetype: Photoshop Icon Resource Index 1.0

INSTRUCTIONS:

Put both files in a folder, then create a subfolder named "extracted". Run readPhotoshopIcons.php to extract images then run readPhotoshopIconNames.php to rename files to their correct names.

@JohnCoates
JohnCoates / writeOutPasteboard.m
Created February 2, 2016 19:11
Mac OS X Pasteboard Viewer : NSPasteboard extract
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
int main(int argc, char *argv[]) {
@autoreleasepool {
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
NSLog(@"items: %@", pasteboard.pasteboardItems);
for (NSPasteboardItem *item in pasteboard.pasteboardItems) {
NSLog(@"types: %@", item.types);
for (NSString *type in item.types) {
@JohnCoates
JohnCoates / autotap.js
Created June 6, 2016 08:04
Auto-tap load more on YouTube
buttons = document.getElementsByTagName("button");
for (key in buttons) {
button = buttons[key];
attributes = button.attributes
if (attributes != undefined && attributes.getNamedItem('aria-label')) {
label = attributes.getNamedItem('aria-label')
value = String(label.value)
if (value == "Load more\n") {
console.log("clicking load more!");
button.click();
@JohnCoates
JohnCoates / UIGestureRecognizer+Closure.swift
Created May 18, 2017 09:14
UIGestureRecognizer with closure, Swift 3
import UIKit
extension UIGestureRecognizer {
@discardableResult convenience init(addToView targetView: UIView,
closure: @escaping () -> Void) {
self.init()
GestureTarget.add(gesture: self,
closure: closure,
toView: targetView)
@JohnCoates
JohnCoates / FixUICodeCoverage
Created May 19, 2017 15:28
Fixes UI code coverage on builds run from xcode build
@import ObjectiveC.runtime;
@import MachO.dyld;
@import Foundation;
@interface IDELaunchParametersSnapshot : NSObject
+ (id)launchParametersWithSchemeIdentifier:(id)schemeIdentifier
launcherIdentifier:(id)launcherIdentifier
debuggerIdentifier:(id)debuggerIdentifier
launchStyle:(int)launchStyle
runnableLocation:(id)runnableLocation
@JohnCoates
JohnCoates / AutoHook.h
Created May 26, 2017 22:06
Simple Objective-C Method Hooking
@protocol AutoHook <NSObject>
@required
+ (NSArray <NSString *> *)targetClasses;
@end