Skip to content

Instantly share code, notes, and snippets.

@janodev
janodev / diff.mdown
Created January 13, 2017 15:41 — forked from ndarville/diff.mdown
Paul Heckel's Diff Algorithm

[Isolating Differences Between Files][paper]

Advantage over Other Algorithms

The diff output is more specific:

[I]f a whole block of text is moved, then all of it, rather than just the beginning and end, is detected as changed.

>The algorithm described here avoids these difficulties. It detects differences that correspond very closely to our intuitive notion of difference.

@janodev
janodev / gist:76588cc804bc34766328dc5962b10f15
Created January 4, 2017 18:30
Kill dupes in Open With context menu
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user;killall Finder
@janodev
janodev / BaseConverter.swift
Created August 20, 2016 20:29
A base converter in Swift 3. For instance, BaseConverter.representNumber(number: 3405691582, inBase: 16) is "cafebabe"
import Foundation
public struct BaseConverter
{
static let alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" // 62 digits
static func representNumber(n: Int, asciiAlphabet: String) -> String
{
let base = asciiAlphabet.lengthOfBytes(using: String.Encoding.utf8)
if (n < base){
@janodev
janodev / handleNotifications.swift
Created August 16, 2016 12:59
Handle the notifications
@import UserNotifications;
extension NotificationManager: UNUserNotificationCenterDelegate
{
// Called because the user interacted with a notification. Actions may be dismiss, open, or choosing an action.
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: () -> Void)
{
print(response)
}
@janodev
janodev / registerToken.swift
Created August 16, 2016 12:57
Register the token
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data)
{
let token = deviceToken.description.components(separatedBy: CharacterSet(charactersIn: "<> ")).joined(separator: ""
dlog(token, .Info)
}
@janodev
janodev / requestAuthorization.swift
Created August 16, 2016 12:57
Request authorization
let center = UNUserNotificationCenter.current()
center.requestAuthorization([.sound, .alert, .badge]) { (granted, error) in
// ...
}
@janodev
janodev / handleTextResponse.swift
Created August 16, 2016 12:56
Handle a text response
class NotificationViewController: UIViewController, UINotificationContentExtension
{
override func canBecomeFirstResponder() -> Bool {
return true
}
override var inputAccessoryView: UIView {
get { return inputView }
}
@janodev
janodev / handleAction.swift
Created August 16, 2016 12:55
Handle the action
class NotificationViewController: UIViewController, UINotificationContentExtension
{
func didReceive(_ response: UNNotificationResponse,
completionHandler done: (UNNotificationContentExtensionResponseOption) -> Void)
{
server.postEventResponse(response.actionIdentifier)
{
if response.actionIdentifier == "accept"
{
eventResponse.text = "Going!"
@janodev
janodev / recoverAttachment.swift
Created August 16, 2016 12:53
Recover a notification attachment
import UIKit
import UserNotifications
import UserNotificationsUI
struct Attachments {
static let image = (identifier:"image", jsonElement:"imageURL")
}
class ContentViewController: UIViewController, UNNotificationContentExtension
{
@janodev
janodev / layoutContent.swift
Created August 16, 2016 12:53
Layout the content
override func viewDidLoad()
{
super.viewDidLoad()
let size = view.bounds.size
preferrredContentSize = CGSize(width: size.width, height: size.width / 2)
}