Skip to content

Instantly share code, notes, and snippets.

@raberm
raberm / GradientView.swift
Last active October 18, 2015 16:36
@IBDesignable/@IBInspectable GradientView (linear gradient, 2 stops)
// ©2015 Massimiliano Raber, MIT license
// @IBDesignable/@IBInspectable GradientView (linear gradient, 2 stops)
import UIKit
@IBDesignable
class GradientView: UIView {
@IBInspectable var startColor: UIColor = UIColor.whiteColor() {
didSet {
@raberm
raberm / gist:a8097399f37eee604e98b4b1e50202dc
Created January 21, 2023 10:44
html to NSAttributedString
extension String {
func htmlAttributedString() -> NSAttributedString? {
guard let data = self.data(using: String.Encoding.utf16, allowLossyConversion: false) else { return nil }
guard let html = try? NSMutableAttributedString(
data: data,
options: [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html],
documentAttributes: nil) else { return nil }
return html
}
}
float frexp(float x, out float e)
{
e = ceil(log2(x));
return(x * exp2(-e));
}
x = 0.15625;
x = -118.62500;
v = Ceiling[Log2[Abs[x]]] - 1