Skip to content

Instantly share code, notes, and snippets.

View phaibin's full-sized avatar
🎯
Focusing

Leon phaibin

🎯
Focusing
View GitHub Profile
@rob-secondstage
rob-secondstage / LocationMetadata.swift
Created July 6, 2022 21:19
Adds GPS metadata to an existing image file without re-encoding or re-compressing the image. Swift, iOS.
import AVFoundation
import CoreLocation
import OSLog
private let logger = Logger(subsystem: "utilities", category: "images")
/// Adds the GPS metadata from `location` to the image file at `url` without re-encoding the image.
/// - Note: The image at `url` must be `JPG` or `HEIC` format. `HEIF` will not work.
/// - Warning: The file at `url` will be overwritten with a new file containing the updated metadata.
/// - Parameters:
@joelekstrom
joelekstrom / SwiftUIDoubleClickModifier.swift
Last active February 22, 2025 21:22
A view modifier that can reliably detect double clicks on macOS, even in List
extension View {
/// Adds a double click handler this view (macOS only)
///
/// Example
/// ```
/// Text("Hello")
/// .onDoubleClick { print("Double click detected") }
/// ```
/// - Parameters:
/// - handler: Block invoked when a double click is detected
@mag911
mag911 / Parallel_Tools_fix_for_Ubuntu_19.04.md
Last active April 15, 2025 11:19
Parallel Tools fix for Ubuntu 20.04, 19.04, 19.10, 18.04

Update 25 April 2020:

Many thanks to @KZL1992 @tomslominski @ptrofi @n-thumann for recent comments on their experiences with 20.04 and Parallels 13/14/15, especially the subsitution of the latest prl-tools-lin.iso for older Parallels to get it going.


First off, credit goes to github.com/rudolfratusinski for leading the way here.

https://gist.github.com/rudolfratusinski/a4d9e3caff11a4d9d81d2e84abc9afbf

@vfreex
vfreex / scan_isp_blocklist.sh
Created November 20, 2018 09:58
Test which TCP ports are blocked by my ISP
#!/bin/bash
for port in {1..9999}; do
echo -n "TCP $port: "
result=$(nc "$1" "$port" -w 1 2>&1 < /dev/null)
if [ "$?" -eq 0 ]; then
echo "Open"
continue
fi
if [[ "$result" == *refused* ]]; then
@osteslag
osteslag / Metadata.swift
Created August 14, 2018 16:55
Swift Playground for updating an image file’s metadata without re-processing the image.
// Adapted from Apple's Tech Note, [Modifying Image Metadata Without Recompressing Image](https://developer.apple.com/library/archive/qa/qa1895/_index.html).
import Cocoa
import ImageIO
let url = URL(fileURLWithPath: "/path/to/file.tiff")
guard let imageSource = CGImageSourceCreateWithURL(url as CFURL, nil) else { fatalError("Cannot create URL") }
guard var properties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil) as? Dictionary<CFString, Any> else { fatalError("Cannot get image properties") }
properties[kCGImageDestinationDateTime] = Date()
@dfang
dfang / formula extension method
Last active May 22, 2019 08:07
Enable brew service support for prometheus
```
def plist; <<~EOS
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<dict>
<key>SuccessfulExit</key>
<false/>
@agentsim
agentsim / highsierra_bootable.sh
Created June 10, 2017 02:23
Create bootable ISO from HighSierra Installer
# Generate a BaseSystem.dmg with 10.13 Install Packages
hdiutil attach /Applications/Install\ macOS\ 10.13\ Beta.app/Contents/SharedSupport/InstallESD.dmg -noverify -mountpoint /Volumes/highsierra
hdiutil create -o /tmp/HighSierraBase.cdr -size 7316m -layout SPUD -fs HFS+J
hdiutil attach /tmp/HighSierraBase.cdr.dmg -noverify -mountpoint /Volumes/install_build
asr restore -source /Applications/Install\ macOS\ 10.13\ Beta.app/Contents/SharedSupport/BaseSystem.dmg -target /Volumes/install_build -noprompt -noverify -erase
cp -R /Volumes/highsierra/Packages /Volumes/OS\ X\ Base\ System/System/Installation
hdiutil detach /Volumes/OS\ X\ Base\ System/
hdiutil detach /Volumes/highsierra/
mv /tmp/HighSierraBase.cdr.dmg /tmp/BaseSystem.dmg
@kwylez
kwylez / EXIFImage-playground.swift
Created February 1, 2017 14:10
Modifying EXIF Data with Swift 3
//: Playground - noun: a place where people can play
import UIKit
import ImageIO
import MobileCoreServices
let TEST_IMAGE: String = "replace.jpg"
let beach: UIImage = UIImage(named: TEST_IMAGE)!
let imageData: Data = UIImageJPEGRepresentation(beach, 1)!
import UIKit
import MobileCoreServices
import ImageIO
let sourceOptions: [String: AnyObject] = [kCGImageSourceTypeIdentifierHint as String: kUTTypeJPEG]
let cfSourceOptions = sourceOptions as CFDictionary
let image = UIImage(named: "input.jpg")!
let data = UIImageJPEGRepresentation(image, 1.0)
@wavezhang
wavezhang / java_download.sh
Last active April 30, 2025 16:57
download java from oracle without login
wget -c --no-cookies --no-check-certificate --header "Cookie: oraclelicense=accept-securebackup-cookie" https://download.oracle.com/otn-pub/java/jdk/12.0.2+10/e482c34c86bd4bf8b56c0b35558996b9/jdk-12.0.2_linux-x64_bin.tar.gz