Skip to content

Instantly share code, notes, and snippets.

View hustlzp's full-sized avatar
🎯
Focusing

Zhipeng Liu hustlzp

🎯
Focusing
  • Wuhan, China
View GitHub Profile
@dkun7944
dkun7944 / CDView.swift
Last active January 14, 2024 23:45
SwiftUI + Swift.Shader CD
//
// CDView.swift
// CD
//
// Created by Daniel Kuntz on 7/3/23.
//
import SwiftUI
struct ShapeWithHole: Shape {
@JunyuKuang
JunyuKuang / OverrideCatalystScaleFactor.swift
Last active September 26, 2023 05:17
Disable 77% scaling for Mac Catalyst apps. (Swift)
let overrideCatalystScaleFactor: Void = {
guard let sceneViewClass = NSClassFromString("UINSSceneView") as? NSObject.Type else {
return
}
if sceneViewClass.instancesRespond(to: NSSelectorFromString("scaleFactor")) {
// old
swizzleInstanceMethod(
class: sceneViewClass,
originalSelector: NSSelectorFromString("scaleFactor"),
swizzledSelector: #selector(swizzle_scaleFactor)
@cupnoodle
cupnoodle / toggleSync.md
Last active November 13, 2023 15:11
Disable sync of NSPersistentCloudKitContainer at launch, then enable sync later

To disable iCloud sync of core data when the app launches, set the cloudKitContainerOptions to nil for the persistent store.

In your AppDelegate.swift file :

lazy var persistentContainer: NSPersistentCloudKitContainer = {

        let container = NSPersistentCloudKitContainer(name: "your core data container name")
        
        guard let description = container.persistentStoreDescriptions.first else {
            fatalError("###\(#function): Failed to retrieve a persistent store description.")
@kieranb662
kieranb662 / Rainbow.md
Last active May 25, 2023 12:58
[Rainbow ViewModifier] Rainbow animation view modifiers for SwiftUI #SwiftUI #ViewModifier

Rainbow Example

@wtsnz
wtsnz / Scale Around Anchor Point.swift
Created June 12, 2019 23:45
Scale transform around anchor point
func scaleTransform(for view: UIView, scaledBy scale: CGPoint, aroundAnchorPoint relativeAnchorPoint: CGPoint) -> CGAffineTransform {
let bounds = view.bounds
let anchorPoint = CGPoint(x: bounds.width * relativeAnchorPoint.x, y: bounds.height * relativeAnchorPoint.y)
return CGAffineTransform.identity
.translatedBy(x: anchorPoint.x, y: anchorPoint.y)
.scaledBy(x: scale.x, y: scale.y)
.translatedBy(x: -anchorPoint.x, y: -anchorPoint.y)
}
@mspvirajpatel
mspvirajpatel / RPScreenWriter.swift
Created June 10, 2019 06:25
ScreenWriter With ReplayKit
import Foundation
import AVFoundation
import ReplayKit
class RPScreenWriter {
// Write video
var videoOutputURL: URL
var videoWriter: AVAssetWriter?
var videoInput: AVAssetWriterInput?
// Write audio
@KittenYang
KittenYang / UIGestureRecognizer+Block.m
Last active June 16, 2019 01:46
使用 Block 创建 UIGestureRecognizer
static const int target_key;
@implementation UIGestureRecognizer (Block)
+(instancetype)nvm_gestureRecognizerWithActionBlock:(NVMGestureBlock)block {
return [[self alloc]initWithActionBlock:block];
}
- (instancetype)initWithActionBlock:(NVMGestureBlock)block {
self = [self init];
[self addActionBlock:block];
@mwaterfall
mwaterfall / StringExtensionHTML.swift
Last active May 27, 2024 04:36
Decoding HTML Entities in Swift
// Very slightly adapted from http://stackoverflow.com/a/30141700/106244
// 99.99% Credit to Martin R!
// Mapping from XML/HTML character entity reference to character
// From http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references
private let characterEntities : [String: Character] = [
// XML predefined entities:
""" : "\"",
"&" : "&",
@tevino
tevino / fix_virtualenv
Last active March 24, 2024 09:41
Fix python virtualenv after python update
#!/usr/bin/env bash
ENV_PATH="$(dirname "$(dirname "$(which pip)")")"
SYSTEM_VIRTUALENV="$(which -a virtualenv|tail -1)"
BAD_ENV_PATHS="/usr/local"
echo "Ensure the root of the broken virtualenv:"
echo " $ENV_PATH"
@nyg
nyg / iOSCreatePDF.swift
Last active April 2, 2024 11:09
iOS, Swift: Create a PDF file from an HTML string.
// Thanks to http://www.labs.saachitech.com/2012/10/23/pdf-generation-using-uiprintpagerenderer
// Note: including images in the HTML won't work, see here:
// https://github.com/nyg/HTMLWithImagesToPDF
import UIKit
// 1. Create a print formatter
let html = "<b>Hello <i>World!</i></b>"
let fmt = UIMarkupTextPrintFormatter(markupText: html)