Skip to content

Instantly share code, notes, and snippets.

func processHTML(_ string: String) -> NSAttributedString {
let stringData = string.data(using: .utf8)!
let attrString = try! NSMutableAttributedString(
data: stringData,
options: [.documentType: NSAttributedString.DocumentType.html],
documentAttributes: nil
)
var boldRanges: [NSRange] = []
var italicRanges: [NSRange] = []
#!/bin/bash
# Credit to Joel Ekström at Spotify for original creation.
# USAGE:
# 1. Replace `{ insert repo url here }` at the bottom with your GH repo's URL
# 2. `chmod +x open-xcode-selection-in-gh.sh` to make it executable
# 3. Create a new Behaviour in Xcode settings. In the bottom, select "Run script", and choose this file
# 4. Next to your new behaviour in the list, click the cmd symbol to add to keyboard shortcut
@alexpersian
alexpersian / GlowingPillView.swift
Created January 19, 2021 22:29
Rough attempt at making a glowing pill style view
//: A UIKit based Playground for presenting user interface
import UIKit
import PlaygroundSupport
class MyViewController : UIViewController {
override func loadView() {
let pillView = UIView(frame: CGRect(x: 64, y: 64, width: 32, height: 128))
pillView.backgroundColor = .white
pillView.layer.cornerRadius = pillView.frame.width / 2
@alexpersian
alexpersian / wasd_rule.json
Last active January 16, 2021 20:22 — forked from icanswiftabit/rule.json
Arrow pad with caps_lock as toggle key
{
"title": "WASD Arrow Keys",
"rules": [
{
"description": "WASD Mode [Capslock as trigger key]",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "caps_lock"
//
// TurnipCalculator
//
// Translated from https://gist.github.com/Treeki/85be14d297c80c8b3c0a76375743325b#file-turnipprices-cpp
//
// TODO: Calculation is slightly off from C++ impl still
import Foundation
// MARK: Lighten Blend Filter
let lightenFilter = CIFilter(name: "CILightenBlendMode")!
let solidDarkColorImage = CIImage(color:CIColor(red: 0.09, green: 0.14, blue: 0.32))
lightenFilter.setValuesForKeys([
"inputImage": multiplyFilter.outputImage!,
"inputBackgroundImage": solidDarkColorImage
])
// MARK: Multiply Blend Filter
let multiplyFilter = CIFilter(name: "CIMultiplyBlendMode")!
let solidLightColorImage = CIImage(color: CIColor(red: 0.33, green: 0.98, blue: 0.25))
multiplyFilter.setValuesForKeys([
"inputImage": grayscaleFilter.outputImage!,
"inputBackgroundImage": solidLightColorImage
])
// MARK: Grayscale Filter
let grayscaleFilter = CIFilter(name: "CIPhotoEffectMono")!
grayscaleFilter.setValue(CIImage(cgImage: image.cgImage!), forKey: kCIInputImageKey)
@alexpersian
alexpersian / BoundingBox.swift
Last active January 15, 2020 02:12
ViewController class that will render a shape and then on-tap will draw a bounding box around that shape.
//
// ViewController with a single shape drawn inside it.
// Tapping on the shape will cause a red minimum-bounding box to be drawn
// around the shape's bounds.
//
// Included as a single monofile for the sake of including it all within a single gist.
// Core logic centers around the Flood Fill algorithm with an interative, BFS approach used.
//
import UIKit
@alexpersian
alexpersian / GenerateParentheses.swift
Created January 12, 2020 20:26
Much simpler solution for generating a string of balanced parentheses of length (n * 2).
import Foundation
final class Generator {
private var store = [[""]]
func genBalanced(_ n: Int) -> [String] {
if n < store.count {
return store[n]
}