Skip to content

Instantly share code, notes, and snippets.

Woohoooo 12k on SO!

Andrew Zheng aheze

Woohoooo 12k on SO!
View GitHub Profile
BrentMifsud / PreviewDevice+Devices.swift
Last active Nov 30, 2021
Extension on PreviewDevice that includes all available devices
View PreviewDevice+Devices.swift
import SwiftUI
/// Static properties for all preview devices.
/// Usage:
/// ```swift
/// struct TestView_Previews: PreviewProvider {
/// static var previews: some View {
/// Group {
View gist:35c31a29e7f9eebdccfdc7cdfe9fe724
else if type == NSFetchedResultsChangeType.move {
// A hackish way to ensure PIN icon is updated.
if let newIndexPath = newIndexPath, let indexPath = indexPath {
if let plainNote = nsPlainNoteProvider.getNSPlainNote(newIndexPath), let noteCell = collectionView.cellForItem(at: indexPath) as? NoteCell {
selected: false,
animate: false

Breaking Changes of 2.0

These are the breaking changes of version 2.0.

"Breaking change" includes:

  • [R]emoval: a feature is removed.
  • [N]ame changes: a feature is renamed.
  • [B]ehavior: something does not behave the way they did in 1.x.
  • [T]yping: types of arguments, attributes or return values changes in an incompatible way. (e.g. None disallowed for argument)
  • [S]yntax: a syntax previously allowed for an operation is no longer allowed. (e.g. positional only arguments, new required arguments)
View gist:b32fd2d321c18818037a62e06b1bbab9
// Good
@IBAction func sideMenuClicked(_ sender: UIBarButtonItem) {
statusBarHidden = true
self.navigationController? = 20
UIView.animate(withDuration: Constants.config_shortAnimTime) { () -> Void in
View Jumping view with anchors, alignmentGuides and preferenceKeys
// TransactionView.swift
// Created by Balazs Erdesz on 2021. 02. 23..
import SwiftUI
import Combine
struct TransactionView: View {

Minecraft on Apple Silicon

In this gist, you can find the steps to run Minecraft 1.16.4 natively on Apple Silicon (AS), without needing Rosetta 2 translation of the dependencies (mainly LWJGL and related libraries).

While it's possible to use a launcher like MultiMC to have a prettier way to run the game on AS, it requires installing even more dependencies (like QT) which take time and are difficult to distribute. Therefore, I've put together a command line-based launcher tool using a couple shell & Python scripts.

To get up and running quickly, follow the steps below. Otherwise, for more detail, watch my YouTube video.

Download my package

aheze / DocumentPicker.swift
Last active Aug 6, 2021
UIDocumentPickerViewController example in Swift 5. Bug fixed version of this article:
View DocumentPicker.swift
// DocumentPicker.swift
import UIKit
import MobileCoreServices
protocol DocumentDelegate: class {
func didPickDocument(document: Document?)
hkamran80 / canvas_lms.user.js
Last active Aug 22, 2020
Canvas LMS - Keystrokes
View canvas_lms.user.js
// ==UserScript==
// @name Canvas LMS - Keystrokes
// @namespace
// @version 1.0.1
// @description Snippets for the Canvas LMS
// @author H. Kamran
// @downloadUrl
// @updateUrl
// @match https://**
// @grant none

How to play custom audio on Swift Playgrounds for iPad, using SwiftUI.

import AVFoundation
import SwiftUI
import PlaygroundSupport

struct SwiftUIAudioPlayerView: View {
    /// the audio player that will play your audio file. Can't be a local variable.
rogerluan / String+Regex.swift
Created Jul 27, 2020
Handy Regex utility to find and replace matching groups in Swift.
View String+Regex.swift
extension String {
/// Finds matching groups and replace them with a template using an intuitive API.
/// This example will go through an input string and replace all occurrences of "MyGreatBrand" with "**MyGreatBrand**".
/// let regex = try! NSRegularExpression(pattern: #"(MyGreatBrand)"#) // Matches all occurrences of MyGreatBrand
/// someMarkdownDocument.replaceGroups(matching: regex, with: #"**$1**"#) // Surround all matches with **, formatting as bold text in markdown.
/// print(someMarkdownDocument)
/// - Parameters: