Skip to content

Instantly share code, notes, and snippets.

View mhdhejazi's full-sized avatar

Mhd Hejazi mhdhejazi

View GitHub Profile
@mhdhejazi
mhdhejazi / Catalyst-ScaleFactor.swift
Created April 27, 2020 10:42
Change the window scale factor in a Mac Catalyst app with the help of Dynamic (https://github.com/mhdhejazi/Dynamic)
override func viewDidAppear(_ animated: Bool) {
view.window?.scaleFactor = 1.0 // Default value is 0.77
}
extension UIWindow {
var scaleFactor: CGFloat {
get {
Dynamic.NSApplication.sharedApplication
.windows.firstObject.contentView
.subviews.firstObject.scaleFactor ?? 1.0
@mhdhejazi
mhdhejazi / Catalyst-NSOpenPanel.swift
Last active January 10, 2022 18:21
Use NSOpenPanel from a Mac Catalyst app with the help of Dynamic (https://github.com/mhdhejazi/Dynamic)
// macOS App
let panel = NSOpenPanel()
panel.beginSheetModal(for: view.window!, completionHandler: { response in
if let url: URL = panel.urls.first {
print("url: ", url)
}
})
// Mac Catalyst (with Dynamic)
let panel = Dynamic.NSOpenPanel()
@mhdhejazi
mhdhejazi / Catalyst-ToggleFullScreen.swift
Last active April 27, 2020 09:52
Enter fullscreen in a Mac Catalyst app with the help of Dynamic (https://github.com/mhdhejazi/Dynamic)
// macOS App
NSApplication.shared
.windows.first?
.toggleFullScreen(nil)
// Mac Catalyst (with Dynamic)
Dynamic.NSApplication.sharedApplication
.windows.firstObject
.toggleFullScreen(nil)
@mhdhejazi
mhdhejazi / Catalyst-NSWindow.swift
Last active April 27, 2020 09:53
Get the NSWindow from UIWindow in a Mac Catalyst app with the help of Dynamic (https://github.com/mhdhejazi/Dynamic). Credit: @steipete
extension UIWindow {
var nsWindow: NSObject? {
Dynamic.NSApplication.sharedApplication.delegate.hostWindowForUIWindow(self)
}
}
@mhdhejazi
mhdhejazi / CopyAsanaTasks.php
Created October 24, 2012 16:43
Copy/Move project to a new workspace in Asana
function asanaRequest($methodPath, $httpMethod = 'GET', $body = null)
{
$apiKey = 'ASANA_API_KEY_HERE'; /// Get it from http://app.asana.com/-/account_api
$url = "https://app.asana.com/api/1.0/$methodPath";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ) ;
curl_setopt($ch, CURLOPT_USERPWD, $apiKey);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);