Skip to content

Instantly share code, notes, and snippets.

Avatar

Jeroen Wesbeek 4np

  • ServiceNow
  • The Netherlands
View GitHub Profile
@4np
4np / macOS-beta-enrollment.md
Last active Nov 23, 2020
Fix macOS beta opt out / unenrollment
View macOS-beta-enrollment.md

Sometimes unenrolling from the macOS beta feed does not work properly.

macOS Beta Channel

You can fix this by enrolling / unenrolling through Terminal:

sudo /System/Library/PrivateFrameworks/Seeding.framework/Versions/A/Resources/seedutil enroll DeveloperSeed
sudo /System/Library/PrivateFrameworks/Seeding.framework/Versions/A/Resources/seedutil unenroll
@4np
4np / RetainCyclePlayground.swift
Last active May 15, 2020
A Swift Playground demonstrating why you need to again weekly capture self in nested closures after unwrapping self.
View RetainCyclePlayground.swift
import Cocoa
class TestClass {
var name = ""
var block1: (() -> Void)?
var block2: (() -> Void)?
var retainCount: Int {
CFGetRetainCount(self)
}
@4np
4np / ValueTypePlayground.swift
Created May 15, 2020
Swift value type memory management
View ValueTypePlayground.swift
import Cocoa
func address(of object: UnsafeRawPointer) -> String {
let addr = Int(bitPattern: object)
return String(format: "%p", addr)
}
struct Foo {
public var baz: String
}
@4np
4np / named.conf
Created Oct 15, 2019 — forked from cpswan/named.conf
Unbound/BIND config for DNS over TLS to 1.1.1.1
View named.conf
options {
directory "/tmp";
listen-on-v6 { none; };
forwarders {
127.0.0.1 port 2053;
};
auth-nxdomain no; # conform to RFC1035
@4np
4np / README.md
Last active Oct 3, 2019
How to block adware and malware using bind.
View README.md

Block adware and malware using DNS

Install bind

For Gentoo Linux:

emerge bind
@4np
4np / Gentoo-NFTables-Readme.md
Last active Apr 2, 2021
Gentoo Linux NFTables
View Gentoo-NFTables-Readme.md

Basic firewall / network router using Gentoo Linux.

After compiling the 4.19.66-gentoo kernel, udev renamed the network interfaces of my home linux Router / Firewall and my iptables setup stopped working due ip-conntrack kernel deprecations. I decided to move over to nftables, the new packet classification framework that replaces the existing {ip,ip6,arp,eb} tables infrastructure.

Even though nftables has been in the Linux kernel since 2014, the documentation is extremely sparse. As such this gist :)

Subjectively, using nftables setting up connections to my machine seems to be more responsive compared to using iptables. Connections seem to be made more quickly and ssh-ing into my machine seems more responsive. There always used to be a bit of a lag when I was using iptables, not anymore.

Preperations

@4np
4np / AppDelegate.swift
Last active Apr 18, 2019
Disable noisy layout constraint warnings that clutter up the Xcode console.
View AppDelegate.swift
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
...
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
...
// Disable the NSLayoutConstraint warnings thast are cluttering
@4np
4np / WKWebView-and-AVPlayer.md
Created Apr 5, 2019
Detecting Video Playback inside a WKWebView
View WKWebView-and-AVPlayer.md

Detecting Video Playback inside a WKWebView

Observing video playback inside a black-boxed WKWebView is difficult as you don't have direct access to the video player.

Another complicating matter is that depending on the video, the video might be played using a HTML5 video player, while others might launch the native AVPlayerViewController for playback. While it might be possible to detect HTML5 based playback by injecting custom JavaScript using a WKUserContentController, this is not the approach we will follow in the document as these depend on what HTML5 Video Player is involved and is, as such, not a generic solution.

Making sure AVKit is used

@4np
4np / notifications.swift
Created Apr 4, 2019
Debug notification center notifications.
View notifications.swift
import Foundation
import os.log
NotificationCenter.default.addObserver(forName: nil, object: nil, queue: nil) { (notification) in
os_log("Received notification: %@", log: .default, type: .debug, notification.name.rawValue)
}
@4np
4np / .swiftlint.yml
Created Mar 29, 2019
SwiftLint configuration that will only check for potential crash-causing force cast, force unwrapping and force try statements.
View .swiftlint.yml
disabled_rules: # rule identifiers to exclude from running
- anyobject_protocol
- array_init
- attributes
- block_based_kvo
- class_delegate_protocol
- closing_brace
- closure_body_length
- closure_end_indentation
- closure_parameter_position