Skip to content

Instantly share code, notes, and snippets.

@janodev
janodev / setCategoryLocal.swift
Created August 16, 2016 12:50
Set the category of a local notification
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler:(UNNotificationContent) -> Void)
{
content = (request.content.mutableCopy() as? UNMutableNotificationContent)
content?.categoryIdentifier = "DylanOrDermotCategory"
// ...
}
@janodev
janodev / customNotification.json
Created August 16, 2016 12:48
A custom notification payload
{
"aps": {
"alert": {...}
"mutable-content": 1
}
"my-attachment": "https://foo.bar/baz.jpg",
"category": "DylanOrDermotCategory"
}
@janodev
janodev / scheduleNotification.swift
Created August 16, 2016 12:47
Schedule a notification
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
let request = UNNotificationRequest(identifier: "local_notification", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request)
@janodev
janodev / createNotification.swift
Last active August 16, 2016 12:46
Create a notification with an image attachment
let content = UNMutableNotificationContent()
content.title = "Will it rain?"
content.body = "It never rains in (Southern) California!"
content.sound = UNNotificationSound.default()
let url = URL(string: "https://67.media.tumblr.com/ab04c028a5244377a0ab96e73915e584/tumblr_nfn3ztLjxk1tq4of6o1_400.gif")
let attachment = try! UNNotificationAttachment(identifier: "image", url: url!, options: nil)
content.attachments = [attachment]
@janodev
janodev / install.sh
Created August 3, 2016 10:11
Install El Capitan on a Virtual Box image
#!/bin/bash
# Mount the Installer image
hdiutil attach /Applications/Install\ OS\ X\ El\ Capitan.app/Contents/SharedSupport/InstallESD.dmg -noverify -nobrowse -mountpoint /Volumes/install_app
# Create El Capitan sparseimage of 7316mb with a Single Partition - Apple Partition Map
hdiutil create -o /tmp/ElCapitan -size 7316m -layout SPUD -fs HFS+J -type SPARSE
# Mount the El Capitan sparseimage
hdiutil attach /tmp/ElCapitan.sparseimage -noverify -nobrowse -mountpoint /Volumes/install_build
@janodev
janodev / gist:62849315b65590916f7d5d30cb31b9a6
Created July 29, 2016 10:18 — forked from reiz/gist:d67512deee814705134e
Vagrantfile for a Java dev. environment with Oracle Java 8 and Eclipse.
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.provider "virtualbox" do |vb|
vb.gui = true
// BASIC SWITCH
enum Media { case Book }
extension Media : CustomStringConvertible
{
var description: String {
switch self {
case .Book: return "bible"
}
find . -type f -a ! -name ".DS_Store" -exec shasum '{}' \; > shasums.txt
shasum -c < shasums.txt > check.txt
cat check.txt | fgrep -v OK
@janodev
janodev / semaphore.swift
Last active June 4, 2016 21:37
Mutex built on dispatch_semaphore
import Foundation
// a mutex built on a semaphore
// see http://www.cocoawithlove.com/blog/2016/06/02/threads-and-mutexes.html
struct DispatchSemaphore {
let s = dispatch_semaphore_create(1)
func sync<R>(@noescape f: () throws -> R) rethrows -> R {
_ = dispatch_semaphore_wait(s, DISPATCH_TIME_FOREVER)
defer { _ = dispatch_semaphore_signal(s) }
return try f()
@-moz-document domain("safaribooksonline.com") {
.card-annotation .annotation-quote,
.resizer .draggable-containment-wrapper:after,
.resizer .draggable-containment-wrapper:before,
body.video,
#lesson-fragment,
#sbo-rt-content
{
font-family: sans-serif !important;
}