Skip to content

Instantly share code, notes, and snippets.

View dimitris-c's full-sized avatar

Dimitris C. dimitris-c

View GitHub Profile
@dimitris-c
dimitris-c / sonos-udm-mutiple-networks.md
Created January 4, 2024 15:23 — forked from plmcgrn/sonos-udm-mutiple-networks.md
Unifi UDM and Sonos home theater with multiple VLAN's

Overview

This goal of this setup is to put the Sonos speakers on an untrusted network to keep all but the required traffic away from the trusted network where devices like personal computers, phones, etc. live. This write-up assumes you already have two networks setup and working.

Important Note on Unifi OS 3.x

UI broke cross-VLAN multicast DNS in this version. See below for steps to install the multicast-relay script to re-enable this. Without it, your Sonos controller app will not be able to discover your speakers on the other VLAN.

System

I have a Sonos Playbar, Sub, and 2 Play:3's as rear surrounds as one home theater setup connected to a UDM (non-Pro, but this should work on Pro too). Some of this setup may be easier for people with non-paired speakers, as Sonos does some shenanigans with which speaker is actively sending traffic to your wifi.

@dimitris-c
dimitris-c / gist:16191abf55114b8dd9230b98d3c9b428
Created March 1, 2021 21:45
EdgeRouter X - IoT VLAN - Sonos Config
IoT VLAN: 7
IGMP Proxy
- Config Tree
- Protocols
- igmp-proxy
- switch0
- role: upstream
- threshold: 1
- switch0.7
@dimitris-c
dimitris-c / chucks
Created November 19, 2020 13:13
Chucks of size from Data
@inline(__always)
private func chunks(of size: Int, in data: Data) -> [Data] {
let chunkSize = size
return data.withUnsafeBytes { (buffer: UnsafeRawBufferPointer) -> [Data] in
guard !buffer.isEmpty else { return [] }
let mutableRawPointer = UnsafeMutableRawBufferPointer(mutating: buffer)
let totalSize = buffer.count
var offset = 0
var chunks = [Data]()
Taken from : https://www.smackfu.com/stuff/programming/shoutcast.html
Webarchive: https://web.archive.org/web/20190521203350/https://www.smackfu.com/stuff/programming/shoutcast.html
Shoutcast Metadata Protocol
How To Parse Titles from MP3 Streams
I wanted to add the ability to show titles from Shoutcast streams on the SliMP3, like Winamp does. The protocol isn't documented anywhere officially (of course). So I ended up cobbling together info from google caches, xmms source code, and mailing lists. Hopefully, this document will save others from the same fate.
## Step 0: Overview picture
-----------------------------------------------------------------------
[ audio data ][metadata.length][metadata][ audio data ]
import Foundation
import UIKit
import RxSwift
import RxCocoa
final class CircularCountdownView: UIView {
let disposeBag = DisposeBag()
private var progressView = UIView()
private var progressLayer: CAShapeLayer = {
@dimitris-c
dimitris-c / RxTest+Nimble.swift
Last active June 22, 2018 10:48
Nimble Matchers to work with RxTest and Events
import Foundation
import RxSwift
import RxCocoa
import RxTest
import Nimble
// Nimble Matchers to work with RxTest and Events
public func equal<T: Equatable>(_ expectedValue: [Recorded<Event<T>>]) -> Predicate<[Recorded<Event<T>>]> {
return Predicate.define("equal <\(stringify(expectedValue))>") { actualExpression, msg in
@dimitris-c
dimitris-c / IndexPathToIndexConversion.swift
Last active April 11, 2018 15:12
Converting an indexPath to the correct index of a one dimension array
let originalArray = [1, 2, 3, 4, 5, 6]
let sections = [[1, 2, 3], [5, 6]]
let indexPath = IndexPath(section: 0, row: 1)
let sectionTotal = self.sections.prefix(upTo: indexPath.section).map { $0.count }.reduce(0, +)
let index = sectionTotal + indexPath.row
let element = originalArray[index]
// element is `2`
@dimitris-c
dimitris-c / Either.swift
Last active April 24, 2018 10:33
A generic Either structure.
public enum Either<L, R> {
case left(L)
case right(R)
}
extension Either {
public var left: L? {
switch self {
case .left(let value): return value
@dimitris-c
dimitris-c / Amount.swift
Last active December 20, 2017 14:17
MoneyTextField - A textfield that enforces rules based an inputting amount of money
import Foundation
public protocol AmountType {
var minorUnits: Int { get }
var currency: Currency { get }
init(amount: Int, currency: Currency)
@dimitris-c
dimitris-c / gist:8d32a81fe711f17665f113fce78d7c15
Last active November 6, 2017 14:26
A UILabel subclass that provides extra padding for background
class EdgesLabel: UILabel {
var edgeInsets: UIEdgeInsets = .zero {
didSet {
layoutIfNeeded()
}
}
override func drawText(in rect: CGRect) {
super.drawText(in: UIEdgeInsetsInsetRect(rect, edgeInsets))