This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
func getDriveBSDNames() -> [String] { | |
var iterator: io_iterator_t = 0 | |
let matching: CFDictionary = IOServiceMatching(kIOServicePlane) | |
// Use 'kIOMasterPortDefault' for macOS older than 12.0 Monterey | |
IOServiceGetMatchingServices(kIOMainPortDefault, matching, &iterator) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
#ref: https://gist.github.com/pudquick/eebc4d569100c8e3039bf3eae56bee4c | |
from Foundation import NSBundle | |
import objc # pip3 install objc | |
CoreServices = NSBundle.bundleWithIdentifier_('com.apple.CoreServices') | |
functions = [ | |
('_LSCopyRunningApplicationArray', b'@I'), | |
('_LSCopyApplicationInformation', b'@I@@'), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
/* Setting up the demo: | |
cd ~/Desktop | |
mkdir demo | |
touch target.txt | |
cd demo | |
ln -s ../target.txt link.txt | |
readlink -f ~/Desktop/demo/link.txt # => /Users/Alex/Desktop/target.txt | |
cd ~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# Warming up -------------------------------------- | |
# a.equal?(b) 670.728k i/100ms | |
# a.id == b.id 367.019k i/100ms | |
# Calculating ------------------------------------- | |
# a.equal?(b) 6.588M (± 2.5%) i/s - 33.536M in 5.093834s | |
# a.id == b.id 3.646M (± 3.0%) i/s - 18.351M in 5.038107s | |
# | |
# Comparison: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Darwin | |
struct ProcFileDescriptorInfo { | |
let fd: Int32 | |
let path: String | |
} | |
func getFileDescriptors(pid: pid_t) -> [ProcFileDescriptorInfo] { | |
let bufferSize = proc_pidinfo(pid, PROC_PIDLISTFDS, 0, nil, 0) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23] | |
# Comparison: | |
# Memo+Freeze+Ident H : 15333385.5 i/s | |
# Memo+Freeze Hash : 11604676.7 i/s - 1.32x slower | |
# case : 11026464.0 i/s - 1.39x slower | |
# Memo'ed Hash : 4516328.0 i/s - 3.40x slower | |
# Hash full of Ints : 4387124.4 i/s - 3.50x slower |
OlderNewer