Skip to content

Instantly share code, notes, and snippets.

View xquezme's full-sized avatar

Sergei Pimenov xquezme

View GitHub Profile
// From https://stackoverflow.com/a/58985069/118631
@available(macOS 10.15, *)
func canRecordScreen() -> Bool {
let runningApplication = NSRunningApplication.current
let processIdentifier = runningApplication.processIdentifier
guard let windows = CGWindowListCopyWindowInfo([.optionOnScreenOnly], kCGNullWindowID)
as? [[String: AnyObject]] else
{
@max-potapov
max-potapov / SplitViewController.swift
Last active February 3, 2022 08:01
UITabBarController inside Master View of UISplitViewController
//
// SplitViewController.swift
// Gist
//
// Created by Maxim Potapov on 17/12/2017.
// Copyright © 2017 Maxim Potapov. All rights reserved.
//
import UIKit
@ha1f
ha1f / CIFilter+Extension.swift
Last active February 20, 2024 08:14
CIFilter+Extension.swift
//
// Created by はるふ on 2017/12/11.
// Copyright © 2017年 ha1f. All rights reserved.
//
import Foundation
import CoreImage
import AVFoundation
extension CIFilter {
@mminer
mminer / HyperlinkTextView.swift
Last active February 7, 2023 07:14
NSTextView subclass that displays and opens hyperlinks.
// You don't necessarily need this subclass if your NSTextView is selectable.
// If it isn't though, this allows you to have an uneditable, unselectable label where links work as expected.
import AppKit
class HyperlinkTextView: NSTextView {
override func mouseDown(with event: NSEvent) {
super.mouseDown(with: event)
openClickedHyperlink(with: event)
@andymatuschak
andymatuschak / States-v3.md
Last active June 12, 2024 04:17
A composable pattern for pure state machines with effects (draft v3)

A composable pattern for pure state machines with effects

State machines are everywhere in interactive systems, but they're rarely defined clearly and explicitly. Given some big blob of code including implicit state machines, which transitions are possible and under what conditions? What effects take place on what transitions?

There are existing design patterns for state machines, but all the patterns I've seen complect side effects with the structure of the state machine itself. Instances of these patterns are difficult to test without mocking, and they end up with more dependencies. Worse, the classic patterns compose poorly: hierarchical state machines are typically not straightforward extensions. The functional programming world has solutions, but they don't transpose neatly enough to be broadly usable in mainstream languages.

Here I present a composable pattern for pure state machiness with effects,

@timdonnelly
timdonnelly / Playground.swift
Last active April 23, 2023 05:26
Maintaining visible scroll position while inserting items in a UICollectionView (Swift playground)
import Foundation
import UIKit
import XCPlayground
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
class Layout: UICollectionViewLayout {
private var attributes: [[UICollectionViewLayoutAttributes]] = []
@zacwest
zacwest / ios-font-sizes.swift
Last active July 17, 2024 21:39
iOS default font sizes - also available on https://www.iosfontsizes.com
let styles: [UIFont.TextStyle] = [
// iOS 17
.extraLargeTitle, .extraLargeTitle2,
// iOS 11
.largeTitle,
// iOS 9
.title1, .title2, .title3, .callout,
// iOS 7
.headline, .subheadline, .body, .footnote, .caption1, .caption2,
]
@PurpleBooth
PurpleBooth / README-Template.md
Last active July 26, 2024 11:55
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@clementgenzmer
clementgenzmer / FBAnimationPerformanceTracker.h
Last active September 18, 2023 23:02
FBAnimationPerformanceTracker
/*
* This is an example provided by Facebook are for non-commercial testing and
* evaluation purposes only.
*
* Facebook reserves all rights not expressly granted.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
@ostinelli
ostinelli / jenkins_ci_on_osx.md
Last active February 28, 2023 02:38
Setup Jenkins CI on OSX.

Jenkins CI on OSX

Instructions on how to setup a secured Jenkins CI on a Mac.

Download & Install dependencies

All of these operations are done with your admin user.

Developer tools

Install the command line developer tools.