Skip to content

Instantly share code, notes, and snippets.

View insidegui's full-sized avatar
🧩

Guilherme Rambo insidegui

🧩
View GitHub Profile
http://p.events-delivery.apple.com.edgesuite.net/1509pijnedfvopihbefvpijlkjb/m3u8/hls_mvp.m3u8
//
// DarkWindow.swift
//
// Created by Guilherme Rambo on 14/05/16.
// Copyright © 2016 Guilherme Rambo. All rights reserved.
//
import Cocoa
class DarkWindow: NSWindow {
//
// LevenshteinEditDistance.swift
//
// Created by Guilherme Rambo on 01/09/16.
// Based on https://gist.github.com/shergin/a6dba6ee5ae3b9ecb16c
// Copyright © 2016 Guilherme Rambo. All rights reserved.
//
import Foundation
@insidegui
insidegui / WebCacheCleaner.swift
Created September 14, 2016 23:12
Clear WKWebView's cookies and website data storage, very useful during development.
import Foundation
import WebKit
final class WebCacheCleaner {
class func clean() {
HTTPCookieStorage.shared.removeCookies(since: Date.distantPast)
print("[WebCacheCleaner] All cookies deleted")
WKWebsiteDataStore.default().fetchDataRecords(ofTypes: WKWebsiteDataStore.allWebsiteDataTypes()) { records in
@insidegui
insidegui / mergegenstrings.py
Created October 4, 2016 23:14 — forked from yoichitgy/mergegenstrings.py
A script to generate .strings file for .swift, .m, .storyboard and .xib files by genstrings and ibtool commands, and merge them with existing translations.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Localize.py - Incremental localization on XCode projects
# João Moreno 2009
# http://joaomoreno.com/
# Modified by Steve Streeting 2010 http://www.stevestreeting.com
# Changes
# - Use .strings files encoded as UTF-8
@insidegui
insidegui / Card type
Created January 11, 2017 20:34 — forked from igorcferreira/CardType.swift
Basic implementation to apply different regexes over a card number String and find the card type
import UIKit
//: Basic implementation to apply different regexes over a card number String and find the card type
enum CardType:String, CustomStringConvertible {
case invalid = "Not valid"
case visa = "^4[0-9]{6,}$"
case mastercard = "^5[0-9]{6,}$"
case amex = "^3[47][0-9]{13}$"
case diners = "^3(?:0[0-5]|[68][0-9])[0-9]{11}$"
@insidegui
insidegui / EncodableValue.swift
Created January 15, 2017 02:40
A better way to "store value types" in NSUserDefaults or NSUbiquitousKeyValueStore
/**
A better way to "store value types" in NSUserDefaults or NSUbiquitousKeyValueStore
*/
import Foundation
/// ValueCoder is a class that can encode values of a specific type via NSCoding
protocol ValueCoder: NSObjectProtocol, NSCoding {
/// The type this coder can encode/decode
associatedtype ValueType
@insidegui
insidegui / AccountStatus.swift
Last active July 27, 2018 19:01
Obtaining the user's iCloud account status using CloudKit
CKContainer.default().accountStatus { status, error in
if let error = error {
// some error occurred (probably a failed connection, try again)
} else {
switch status {
case .available:
// the user is logged in
case .noAccount:
// the user is NOT logged in
case .couldNotDetermine:
extension CKRecord {
subscript(key: MovieKey) -> Any? {
get {
return self[key.rawValue]
}
set {
self[key.rawValue] = newValue as? CKRecordValue
}
}
enum MovieKey: String {
case title
case releaseDate
case location
case rating
}