Skip to content

Instantly share code, notes, and snippets.


Marcelo Perretta bubudrc

View GitHub Profile
bubudrc / GoogleTranslate.swift
Created Jul 14, 2022
Use Google Translate without API on Swift
View GoogleTranslate.swift
private func getTranslationLanguage(translate: String, from originLanguage: String = "auto", to destinationLanguage: String = "en", completion: @escaping (_ result: String?) -> Void) {
// 1- Create the query
if let translatationURL: String = "\(originLanguage)&tl=\(destinationLanguage)&dt=t&q= \(translate)&ie=UTF-8&oe=UTF-8".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed),
let validURL = URL(string: translatationURL) {
var resultSearch: String = keyword
// 2- Make Request
URLSession.shared.dataTask(with: validURL) { [weak self] data, _, error in
guard error == nil, let data = data else {
bubudrc / Optional+Extensions.swift
Created May 20, 2022 — forked from scribblecat/Optional+Extensions.swift
Get Array from Optional NSSet. Especially useful for getting an Array of objects in a Core Data many relationship.
View Optional+Extensions.swift
* 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] {
bubudrc / AuthImagePickerSettings.swift
Last active May 19, 2022
ImagePicker. Simple solution to use camera/photo library to pick an image
View AuthImagePickerSettings.swift
// AuthImagePickerSettings.swift
// Created by Marcelo Perretta on 18/05/2022.
import UIKit
import AVFoundation
import Photos
import PhotosUI
bubudrc / SpeechManager.swift
Created Apr 23, 2022
This a singleton class that lets dev start, pause, stop an speech in a correct way. Because is a singleton, you can share the instance throw the app. Also, because we set an AVAudioSession, we are able to keep listening the audio when the app goes to the background. To work correctly, you must to set the Capability 'Audio, AirPlay, and Picture i…
View SpeechManager.swift
// SpeechManager.swift
// Created by Marcelo Perretta on 22/04/2022.
import Foundation
import AVFoundation
// We need this because the delegate doesnt works correctly
bubudrc / CustomTitleView.swift
Last active Apr 23, 2022
This gist shows how to create a custom titleView to use correctly in any UINavigationController (UINavigationItem)
View CustomTitleView.swift
// CustomitleView
// Created by Marcelo Perretta on 21/04/2022.
import UIKit
class CustomTitleView: UIView {
private let elementsDistance: CGFloat = 5.0
private let iconSize: CGFloat = 25.0
bubudrc / UISearchBar+Ext.swift
Created Mar 5, 2022 — forked from maysamsh/UISearchBar+Ext.swift
A small extension for UISearchBar which shows an UIActivityIndicator while searching
View UISearchBar+Ext.swift
// 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
bubudrc / HTTPStatusCode.swift
Created Feb 2, 2022 — forked from ollieatkinson/HTTPStatusCode.swift
HTTP status codes as a Swift enum.
View HTTPStatusCode.swift
/// 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
View NSSecureCodingValueTransformer.swift
import Foundation
public protocol ValueTransforming: NSSecureCoding {
static var valueTransformerName: NSValueTransformerName { get }
public class NSSecureCodingValueTransformer<T: NSObject & ValueTransforming>: ValueTransformer {
public override class func transformedValueClass() -> AnyClass { T.self }
public override class func allowsReverseTransformation() -> Bool { true }
bubudrc / 1_AppleAppLookup.swift
Created Dec 10, 2021 — forked from vzsg/1_AppleAppLookup.swift
App Store Rating Lookup for Vapor 3
View 1_AppleAppLookup.swift
import Foundation
import Vapor
struct AppInfo: Codable {
let averageUserRating: Double
let userRatingCount: Int
enum AppleAppLookupError: Error {
case notFound
bubudrc / IkigaJSON+Content.swift
Created Dec 10, 2021 — forked from vzsg/IkigaJSON+Content.swift
Example on how to integrate IkigaJSON with Vapor 4
View IkigaJSON+Content.swift
import Vapor
import IkigaJSON
extension IkigaJSONEncoder: ContentEncoder {
public func encode<E: Encodable>(
_ encodable: E,
to body: inout ByteBuffer,
headers: inout HTTPHeaders
) throws {
headers.contentType = .json