Skip to content

Instantly share code, notes, and snippets.

Avatar

Patrick Perini pcperini

View GitHub Profile
View fruition-pcperini.js
$('div[data-block-id]:has(div:contains("c8f6e963-f28b-444e-ad23-054d6d94f25d"))').waitUntilExists('div[data-block-id]:has(div:contains("c8f6e963-f28b-444e-ad23-054d6d94f25d"))', function() {
// Page has loaded
$('div[data-block-id]:has(div:contains("c8f6e963-f28b-444e-ad23-054d6d94f25d"))').css('display', 'none');
$('div[data-block-id]:has(div:contains("Directory"))').css('display', 'none');
$('a.notion-link-token.notion-enable-hover span').css('opacity', 1.0);
$('a:regex(href, ^((?!:\/\/).)*$)').removeAttr('target');
$('a:regex(href, ^((?!:\/\/).)*$)').removeAttr('data-token-index');
}, true);
View fruition-jquery-ext.js
(function (e, f) {
var b = {};
var g = function (a) {
if(b[a]) {
f.clearInterval(b[a]);
b[a] = null;
};
};
e.fn.waitUntilExists = function (s, h, o, c) {
View guard_beaut.swift
guard (
!argument.isEmpty,
nums.count == arguments.count
) else {
print("Blah blah")
}
View enum.py
def Enum(**kwargs):
values = kwargs
class EnumClass(type):
def __new__(cls, name, parents, dct):
# create a class_id if it's not specified
if 'class_id' not in dct:
dct['class_id'] = name.lower()
# we need to call type.__new__ to complete the initialization
new_type = super(EnumClass, cls).__new__(cls, name, parents, dct)
View ContainedViewController.swift
class ContainedViewController: UIViewController {
weak var dataDelegate: FrameViewControllerDataDelegate?
override func willMoveToParentViewController(parent: UIViewController?) {
super.willMoveToParentViewController(parent)
self.dataDelegate = parent as? FrameViewControllerDataDelegate
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
View ViewController.swift
class ViewController: UIViewController, ConstraintStateMachineType {
typealias State = Alignment
enum Alignment: String {
case Left = "Left"
case Right = "Right"
}
override func viewDidLoad() {
super.viewDidLoad()
View ConstraintStateMachineType-ViewController.swift
public extension ConstraintStateMachineType where Self: UIViewController {
// MARK: Properties
var allConstraints: [NSLayoutConstraint] {
return self.view.flatConstraints // helper function, recursively collects constraints
// https://gist.github.com/pcperini/5a8ea37e8cbbe904a031
}
// MARK: Mutators
func setNeedsUpdateConstraints() {
self.view.setNeedsUpdateConstraints()
View Helpers.swift
public extension CollectionType {
// MARK: Flatteners
public func flatten(path: (Self.Generator.Element) -> [Self.Generator.Element]) -> [Self.Generator.Element] {
guard !self.isEmpty else { return [] }
return self + self.flatMap { path($0).flatten(path) }
}
}
public extension UIView {
// MARK: Properties
View ConstraintStateMachineType.swift
public protocol ConstraintStateMachineType: class {
// MARK: Types
typealias State: RawRepresentable
// MARK: Properties
var state: State? { get set }
var allConstraints: [NSLayoutConstraint] { get }
// MARK: Mutators
func setNeedsUpdateConstraints()
View StatefulConstraint.swift
@IBDesignable
public class StatefulConstraint: NSLayoutConstraint {
// MARK: Properties
@IBInspectable var state: String = ""
}
You can’t perform that action at this time.