Skip to content

Instantly share code, notes, and snippets.

View bubudrc's full-sized avatar

Marcelo Perretta bubudrc

View GitHub Profile
@robbdimitrov
robbdimitrov / iOS and Objective-C snippets.md
Last active August 6, 2020 03:56
Useful iOS and Objective-C snippets

iOS and Objective-C snippets

Move content from underneath the navigationBar (iOS 7)

if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) {
    [self setEdgesForExtendedLayout:UIRectEdgeRight|UIRectEdgeBottom|UIRectEdgeLeft];
}

Change the color of the back arrow in navigationBar (iOS 7)

@Seasons7
Seasons7 / nstask.swift
Created July 22, 2015 19:21
NSTask Sample for Swift
import Cocoa
import Foundation
var str = "Hello, playground"
var task:NSTask = NSTask()
var pipe:NSPipe = NSPipe()
task.launchPath = "/bin/ls"
task.arguments = ["-la"]
@AppleBetas
AppleBetas / NSAlert+QuickAlert.swift
Last active February 7, 2019 23:11
NSAlert+QuickAlert.swift - A Swift NSAlert extension to quickly show alerts (macOS)
//
// NSAlert+QuickAlert.swift
//
// Created by AppleBetas on 2016-10-24.
// Copyright © 2016 AppleBetas. All rights reserved.
//
import Cocoa
extension NSAlert {
@ollieatkinson
ollieatkinson / HTTPStatusCode.swift
Last active April 15, 2024 18:34
HTTP status codes as a Swift enum.
/// This is a list of Hypertext Transfer Protocol (HTTP) response status codes.
/// It includes codes from IETF internet standards, other IETF RFCs, other specifications, and some additional commonly used codes.
/// The first digit of the status code specifies one of five classes of response; an HTTP client must recognise these five classes at a minimum.
enum HTTPStatusCode: Int, Error {
/// The response class representation of status codes, these get grouped by their first digit.
enum ResponseType {
/// - informational: This class of status code indicates a provisional response, consisting only of the Status-Line and optional headers, and is terminated by an empty line.
case informational
@sooop
sooop / DragTableController.swift
Created February 9, 2017 06:07
NSTableView reordering row with drag and drop
//
// ViewController.swift
// DragTable
//
// Created by Anna Kim on 2017. 2. 9..
// Copyright © 2017년 Anna Kim. All rights reserved.
//
import Cocoa
@Tulakshana
Tulakshana / MyAPI.swift
Last active April 20, 2023 12:31
Handling re-direction with URLSession (Swift)
import UIKit
@objc class MyAPI: NSObject {
static let keyError: String = "Error"
static let keyResult: String = "Result"
static let unknownError: String = "Unknown error"
static let notificationMyAPIDidEnd = Notification.Name(rawValue: "notificationMyAPIDidEnd")
@bballentine
bballentine / Middleware
Created April 26, 2017 18:06
Vapor - Example middleware that checks user's role before giving access to protected resources.
import Vapor
import HTTP
public class AdminAuthMiddleware: Middleware {
public let error: Error
public let authLevel: UserRole
public init(error: Error, authLevel: UserRole) {
self.error = error
self.authLevel = authLevel
}
@zehfernandes
zehfernandes / pliim-turnOff.scpt
Last active December 17, 2023 22:15
One click and be ready to go up on stage and shine! - https://zehfernandes.github.io/pliim/
# Turn on Notifications
do shell script "defaults -currentHost write com.apple.notificationcenterui doNotDisturb -bool FALSE; defaults -currentHost delete com.apple.notificationcenterui doNotDisturbDate; osascript -e 'quit application \"NotificationCenter\" ' && killall usernoted" -- this set 'Do not disturb' to false in the pref
# Show Desktop
do shell script "defaults write com.apple.finder CreateDesktop -bool true; killall Finder"
# Show all windows
tell application "System Events"
set visible of (every process) to true
end tell
@scribblecat
scribblecat / Optional+Extensions.swift
Created November 24, 2017 22:03
Get Array from Optional NSSet. Especially useful for getting an Array of objects in a Core Data many relationship.
/*
* Returns Array from optional NSSet. Returns empty array if NSSet is nil.
* It's useful for when you want an Array of objects from a Core Data many relationship.
*
* Example usage with managed object `game` with 1-to-many relationship to `Goal` entity:
* let goalArray = game.goals.array(of: Goal.self)
*/
extension Optional where Wrapped == NSSet {
func array<T: Hashable>(of: T.Type) -> [T] {
@maysamsh
maysamsh / UISearchBar+Ext.swift
Last active March 14, 2022 01:07
A small extension for UISearchBar which shows an UIActivityIndicator while searching
//
// UISearchBar+Ext.swift
// frazeit
//
// Created by Maysam Shahsavari on 7/30/18.
// Updated on 9/26/19.
// Copyright © 2018 Maysam Shahsavari. All rights reserved.
// Updated: 10/02/2020.
import Foundation