Skip to content

Instantly share code, notes, and snippets.

View verebes1's full-sized avatar

David verebes1

View GitHub Profile
@MathVasc
MathVasc / SwizzleFunction.swift
Created June 8, 2020 18:26
SwizzleFunction
static func swizzle() {
let aClass: AnyClass? = object_getClass(SomeClass())
let selector1: Selector = #selector(SomeClass.someMethod)
let selector2: Selector = #selector(SomeClass.someOtherMethod)
let method1: Method? = class_getInstanceMethod(aClass, selector1)
let method2: Method? = class_getInstanceMethod(aClass, selector2)
if let originalMethod = method1, let swizzledMethod = method2 {
@wbotelhos
wbotelhos / gpg-safe.sh
Created September 27, 2019 19:00
gpg: WARNING: unsafe permissions on homedir '~/.gnupg'
sudo chown -R $USER ~/.gnupg
sudo chmod 700 ~/.gnupg
sudo chmod 600 ~/.gnupg/*
@bgromov
bgromov / readme.md
Last active September 30, 2023 15:35
Compiling Swift framework with mixed-in Objective-C code

Problem

You can't use bridging headers within a framework.

Solution 1 (umbrella header):

Xcode will automatically create umbrella header for you Cocoa Framework project. That will be the file named <FrameworkName>.h in the <FrameworkName> group/folder (where the rest of your sources are).

  1. To include the required Obj-C header you need to set it as Public: select it in the project explorer (left pane) and change the property Target Membership (left—Inspectors—pane) from Project to Public.
  2. Open umbrella header (<FrameworkName>.h) and import the required header as:
@oseme-techguy
oseme-techguy / Correct_GnuPG_Permission.sh
Last active November 4, 2024 08:39
This fixes the " gpg: WARNING: unsafe permissions on homedir '/home/path/to/user/.gnupg' " error while using Gnupg .
#!/usr/bin/env bash
# To fix the " gpg: WARNING: unsafe permissions on homedir '/home/path/to/user/.gnupg' " error
# Make sure that the .gnupg directory and its contents is accessibile by your user.
chown -R $(whoami) ~/.gnupg/
# Also correct the permissions and access rights on the directory
chmod 600 ~/.gnupg/*
chmod 700 ~/.gnupg
@ankitthakur
ankitthakur / Network.swift
Created December 14, 2018 16:17
Swift Network Request
public class Network:NSObject, URLSessionDelegate, URLSessionTaskDelegate, URLSessionDataDelegate {
internal static let sharedInstance = Network()
fileprivate var networkParams:Array<NetworkParams> = Array()
fileprivate func networkCall(_ request:URLRequest, completionBlock:@escaping NetworkCompletionBlock)
{
let configurationId = String(format: "Network%d", arc4random())
let configuration = URLSessionConfiguration.background(withIdentifier: configurationId)
configuration.timeoutIntervalForRequest = request.timeoutInterval
@TomSoderling
TomSoderling / Disable iOS Simulator Incoming Connections Popup.sh
Last active December 14, 2023 10:26
Bash script for turning off the iOS simulator pop-up message
#!/bin/bash
# Script to disable the iOS Simulator app from showing the "Do you want the application xxxx to accept incoming network connections?" pop-up every time the app is run
echo "> Enter password to temporarily shut firewall off"
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate off
echo "> Add Xcode as a firewall exception"
/usr/libexec/ApplicationFirewall/socketfilterfw --add /Applications/Xcode.app/Contents/MacOS/Xcode
@krodak
krodak / Realm+CascadeDeleting.swift
Last active April 27, 2023 19:16
Cascade deletion for RealmSwift
import RealmSwift
import Realm
protocol CascadeDeleting: class {
func delete<Entity>(_ list: List<Entity>, cascading: Bool)
func delete<Entity>(_ results: Results<Entity>, cascading: Bool)
func delete<Entity: Object>(_ entity: Entity, cascading: Bool)
}
@dmathewwws
dmathewwws / URLSession POST.swift
Created November 5, 2016 01:35
URLSession POST request example
private static func createUserEventData(user:SKUser, eventType:SKEventType, sticker:Sticker?) {
// server endpoint
let endpoint = "https://app.stickerkit.io/userEvent/v1/\(user.projectID)"
guard let endpointUrl = URL(string: endpoint) else {
return nil
}
//Make JSON to send to send to server
@mitulmanish
mitulmanish / TwoDimensionalArray.swift
Created July 6, 2016 07:03
Iterating over 2D array in Swift(with indices)
let twoDimArr: [[Int]] = [[0, 0, 1], [1, 0, 1]]
for (i,row) in twoDimArr.enumerate() {
for (j, cell) in row.enumerate() {
print("m[\(i),\(j)] = \(cell)")
print("**************")
}
}
@squarism
squarism / iterm2.md
Last active November 19, 2024 15:14
An iTerm2 Cheatsheet

Tabs and Windows

Function Shortcut
New Tab + T
Close Tab or Window + W (same as many mac apps)
Go to Tab + Number Key (ie: ⌘2 is 2nd tab)
Go to Split Pane by Direction + Option + Arrow Key
Cycle iTerm Windows + backtick (true of all mac apps and works with desktops/mission control)