Skip to content

Instantly share code, notes, and snippets.

View orgmir's full-sized avatar

Luis Ramos orgmir

View GitHub Profile
@justin
justin / sim.zsh
Last active January 18, 2023 20:21
Convenience wrapper around the simctl command to perform operations related to iOS simulators.
#!/usr/bin/env zsh
#
# Convenience wrapper around the simctl command to perform operations related to iOS simulators.
# Author: Justin Williams (@justin)
#
# Usage: sim <options> <subcommand>
#
# This script is designed to work with ZSH. ymmv with other shells.
set -e
@kean
kean / cURLDescription.swift
Last active April 28, 2022 09:55
test-octokit 2
extension URLRequest {
public func cURLDescription() -> String {
guard let url = url, let method = httpMethod else {
return "$ curl command generation failed"
}
var components = ["curl -v"]
components.append("-X \(method)")
for header in allHTTPHeaderFields ?? [:] {
let escapedValue = header.value.replacingOccurrences(of: "\"", with: "\\\"")
components.append("-H \"\(header.key): \(escapedValue)\"")
@steipete
steipete / View.swift
Created April 4, 2021 13:43
Accept dropping a file onto SwiftUI (both iOS and macOS)
.onDrop(of: [.fileURL], isTargeted: nil) { providers in
if let loadableProvider = providers.first(where: { $0.canLoadObject(ofClass: URL.self) }) {
_ = loadableProvider.loadObject(ofClass: URL.self) { fileURL, _ in
if let fileURL = fileURL, fileURL.pathExtension.lowercased() == "zip" {
self.logger.info("Dropped \(fileURL.path)")
DispatchQueue.main.async {
importer.open(zipArchiveURL: fileURL)
}
}
}
@orgmir
orgmir / main.swift
Created August 21, 2018 02:08
Disable the AppDelegate when initializing a NSApplication for testing
import AppKit
private func isTestRun() -> Bool {
return NSClassFromString("XCTestCase") != nil
}
if isTestRun() {
// This skipping setting up the app delegate
NSApplication.shared.run()
} else {
@cellularmitosis
cellularmitosis / EmojiPointersDemo.swift
Created August 15, 2018 18:11
Representing pointer values as emoji can be useful for "visually" debugging certain issues, like cell reuse, etc.
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let window = UIWindow(frame: UIScreen.main.bounds)
@bnorm
bnorm / strings.kt
Created December 20, 2017 20:33
Turns a Kotlin Data class toString() into formatted JSON-like output
fun Any?.toIndentString(): String {
val notFancy = toString()
return buildString(notFancy.length) {
var indent = 0
fun StringBuilder.line() {
appendln()
repeat(2 * indent) { append(' ') }
}
#if DEBUG
extension UIWindow {
class var key: UIWindow {
let selector: Selector = NSSelectorFromString("keyWindow")
let result = UIWindow.perform(selector)
return result?.takeUnretainedValue() as! UIWindow
}
}
@swillits
swillits / Keycodes.swift
Last active March 26, 2024 23:20
Swift Keyboard Keycodes
struct Keycode {
// Layout-independent Keys
// eg.These key codes are always the same key on all layouts.
static let returnKey : UInt16 = 0x24
static let enter : UInt16 = 0x4C
static let tab : UInt16 = 0x30
static let space : UInt16 = 0x31
static let delete : UInt16 = 0x33
static let escape : UInt16 = 0x35
#!/bin/sh
ADB_PATH="/Users/medyo/Library/Android/sdk/platform-tools"
PACKAGE_NAME="com.mobiacube.elbotola.debug"
DB_NAME="default.realm"
DESTINATION_PATH="/Users/Medyo/Desktop/"
NOT_PRESENT="List of devices attached"
ADB_FOUND=`${ADB_PATH}/adb devices | tail -2 | head -1 | cut -f 1 | sed 's/ *$//g'`
if [[ ${ADB_FOUND} == ${NOT_PRESENT} ]]; then
echo "Make sure a device is connected"
else
@sinclairtarget
sinclairtarget / BasicGradient.shader
Created January 25, 2016 03:04
Simple Gradient Shader
Shader "Custom/BasicGradient"
{
Properties
{
_TopColor ("Top Color", Color) = (1, 1, 1, 1)
_BottomColor ("Bottom Color", Color) = (1, 1, 1, 1)
_RampTex ("Ramp Texture", 2D) = "white" {}
}
SubShader