Skip to content

Instantly share code, notes, and snippets.

View VincentSit's full-sized avatar

Vincent VincentSit

View GitHub Profile
import UIKit
struct Action {
let title: String
let style: UIAlertAction.Style
let action: () -> Void
}
extension Action {
static func `default`(_ title: String, action: @escaping () -> Void) -> [Action] {
@danielmartin
danielmartin / BetterXcodeJumpToCounterpartSwift.org
Last active March 9, 2024 02:00
Add support for a better Xcode's Jump to Next Counterpart in Swift

If you work on a Swift project that follows the Model-View-ViewModel (MVVM) architecture or similar, you may want to jump to counterpart in Xcode from your view to your model, and then to your view model. (ie. by using Ctrl+Cmd+Up and Ctrl+Cmd+Down).

You can do this in recent versions of Xcode by setting a configuration default.

From a terminal, just type this command and press Enter:

defaults write com.apple.dt.Xcode IDEAdditionalCounterpartSuffixes -array-add "ViewModel" "View"
@rlam3
rlam3 / disable-cleanmymac.md
Created August 21, 2019 01:26
Mac disables "Setapp CleanMyMac-setapp.HealthMonitor" launchd services

sudo vim /private/var/db/launchd.db/com.apple.launchd/overrides.plist

Add the following code,as entries like:

<key>com.macpaw.CleanMyMac-setapp.HealthMonitor</key>
<dict>
<key>Disabled</key>
<true/>
@antfarm
antfarm / CRC32.swift
Last active March 29, 2023 10:52
CRC32 checksum generation in a few lines of Swift 5. https://en.wikipedia.org/wiki/Cyclic_redundancy_check#CRC-32_algorithm
class CRC32 {
static var table: [UInt32] = {
(0...255).map { i -> UInt32 in
(0..<8).reduce(UInt32(i), { c, _ in
(c % 2 == 0) ? (c >> 1) : (0xEDB88320 ^ (c >> 1))
})
}
}()
# See https://www.anaconda.com/understanding-and-improving-condas-performance/ for more info.
# help debug channel issues
show_channel_urls: true
# pip will always be installed with python
add_pip_as_python_dependency: true
# strict priority and conda-forge at the top will ensure
# that all of your packages will be from conda-forge unless they only exist on defaults
@arturgrigor
arturgrigor / Podfile
Created September 10, 2018 09:55
Sample Podfile for silencing warnings for CocoaPods dependencies
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target '%TargetName%' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for %TargetName%
# pod 'FBSDKCoreKit'
end
@fay59
fay59 / Quirks of C.md
Last active January 23, 2024 04:24
Quirks of C

Here's a list of mildly interesting things about the C language that I learned mostly by consuming Clang's ASTs. Although surprises are getting sparser, I might continue to update this document over time.

There are many more mildly interesting features of C++, but the language is literally known for being weird, whereas C is usually considered smaller and simpler, so this is (almost) only about C.

1. Combined type and variable/field declaration, inside a struct scope [https://godbolt.org/g/Rh94Go]

struct foo {
   struct bar {
 int x;
@lexrus
lexrus / RxTextFieldDelegateProxy.swift
Created February 14, 2018 03:33
RxSwift extension for textFieldShouldReturn of UITextFieldDelegate
//
// RxTextFieldDelegateProxy.swift
//
// Created by Lex Tang on 2/14/18.
// Copyright © 2018 Krunoslav Zaher. All rights reserved.
//
import RxSwift
import RxCocoa
@hfossli
hfossli / SHA256-Bridging-Header.h
Last active May 5, 2023 20:31
AES 256 in swift 4 with CommonCrypto
#import <CommonCrypto/CommonCrypto.h>
@rjz
rjz / crypto-aes-256-gcm-demo.js
Last active March 11, 2024 20:11
example using node.js crypto API with aes-256-gcm
const buffer = require('buffer');
const crypto = require('crypto');
// Demo implementation of using `aes-256-gcm` with node.js's `crypto` lib.
const aes256gcm = (key) => {
const ALGO = 'aes-256-gcm';
// encrypt returns base64-encoded ciphertext
const encrypt = (str) => {
// The `iv` for a given key must be globally unique to prevent