Skip to content

Instantly share code, notes, and snippets.

View MainasuK's full-sized avatar

CMK MainasuK

View GitHub Profile
@MainasuK
MainasuK / tmux.conf
Created March 4, 2022 08:14 — forked from ronaldsuwandi/tmux.conf
Personal tmux.conf (updated for 3.2)
###########
# general #
###########
# Replace C-b prefix with Alt+Space (so it won't clash with vim)
unbind C-b
set-option -g prefix M-Space
set-window-option -g mode-keys vi
set-option -g default-shell /usr/local/bin/fish
@MainasuK
MainasuK / Apple.license
Last active November 8, 2021 08:52
Apple LICENSED APPLICATION END USER LICENSE AGREEMENT
Apps made available through the App Store are licensed, not sold, to you. Your license to each App is subject to your prior acceptance of either this Licensed Application End User License Agreement (“Standard EULA”), or a custom end user license agreement between you and the Application Provider (“Custom EULA”), if one is provided. Your license to any Apple App under this Standard EULA or Custom EULA is granted by Apple, and your license to any Third Party App under this Standard EULA or Custom EULA is granted by the Application Provider of that Third Party App. Any App that is subject to this Standard EULA is referred to herein as the “Licensed Application.” The Application Provider or Apple as applicable (“Licensor”) reserves all rights in and to the Licensed Application not expressly granted to you under this Standard EULA.
a. Scope of License: Licensor grants to you a nontransferable license to use the Licensed Application on any Apple-branded products that you own or control and as permitted by the Usag
@MainasuK
MainasuK / AutoLayout.swift
Last active June 4, 2020 07:27
Xcode Code Snippets
<#subview#>.translatesAutoresizingMaskIntoConstraints = false
addSubview(<#subview#>)
NSLayoutConstraint.activate([
<#subview#>.topAnchor.constraint(equalTo: topAnchor),
<#subview#>.leadingAnchor.constraint(equalTo: leadingAnchor),
trailingAnchor.constraint(equalTo: <#subview#>.trailingAnchor),
bottomAnchor.constraint(equalTo: <#subview#>.bottomAnchor),
])
@MainasuK
MainasuK / Bash.swift
Last active May 21, 2020 00:54 — forked from andreacipriani/Bash.swift
Execute shell/bash commands from Swift
#!/usr/bin/swift
import Foundation
class Bash {
static var debugEnabled = false
// save command search time
static var commandCache: [String: String] = [:]
@discardableResult
@MainasuK
MainasuK / NSTreeController+Binding.swift
Created March 14, 2020 15:18
Bind NSTreeController contentArray to model
final class ViewModel: NSObject {
@objc var tree: [Node] = []
override init() {
super.init()
}
}
@MainasuK
MainasuK / ScreenRecordHelper.swift
Last active January 26, 2021 06:01
Screen Record Permission Request Helper for macOS Catalina
let stream = CGDisplayStream(display: CGDirectDisplayID(), outputWidth: 1, outputHeight: 1, pixelFormat: Int32(kCVPixelFormatType_32BGRA), properties: nil, handler: { (status, time, surface, update) in
// do nothing
})
@MainasuK
MainasuK / NSViewControllerPreview.swift
Last active May 21, 2022 20:09 — forked from mattt/UIViewControllerPreview.swift
Generic structures to host previews of UIView and UIViewController subclasses. Also NSView and NSViewController
import Cocoa
#if canImport(SwiftUI) && DEBUG
import SwiftUI
struct NSViewControllerPreview<ViewController: NSViewController>: NSViewControllerRepresentable {
let viewController: ViewController
init(_ builder: @escaping () -> ViewController) {
viewController = builder()

Keybase proof

I hereby claim:

  • I am mainasuk on github.
  • I am mainasuk (https://keybase.io/mainasuk) on keybase.
  • I have a public key ASAsqiEANz0eSQXHxi1YjIBC1m9lm3k8TldYLv-HRafSHAo

To claim this, I am signing this object:

@MainasuK
MainasuK / AppDelegate.swift
Created September 5, 2019 08:05
AppDelegate for iOS 13 with multiple windows supports
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Set up application here

It often be helpful to be able to debug memory usage in Swift on Linux, for example to debug memory leaks.

This is a quick overview of how to generate a report of memory usage for your Swift app. This guide will only show you how to generate the report, not how to analyze it, it might be written up in a blog post later.

Install Valgrind

First we need to install a tool called Valgrind, which is used to trace memory usage.