Skip to content

Instantly share code, notes, and snippets.

View 4np's full-sized avatar

Jeroen Wesbeek 4np

  • ServiceNow
  • The Netherlands
View GitHub Profile
@4np
4np / README.md
Last active February 13, 2023 00:45
How to block adware and malware using bind.

Block adware and malware using DNS

Install bind

For Gentoo Linux:

emerge bind
@4np
4np / Gentoo-NFTables-Readme.md
Last active January 16, 2023 18:28
Gentoo Linux NFTables

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 April 18, 2019 19:31
Disable noisy layout constraint warnings that clutter up the Xcode console.
@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 April 5, 2019 11:17
Detecting Video Playback inside a WKWebView

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 April 4, 2019 08:48
Debug notification center notifications.
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 March 29, 2019 12:45
SwiftLint configuration that will only check for potential crash-causing force cast, force unwrapping and force try statements.
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
@4np
4np / HowTo use xcconfig or plist with SPM.md
Last active August 5, 2024 11:06
How to use a .xcconfig file and a .plist with a Swift Package Manager based project.

How to use a .xcconfig file and a .plist file with SPM

Worth a read for some more context.

Create a Package.xcconfig file

Create the file in the root of the project (where your Package.swift file lives as well), and use the following contents:

/// Package.xcconfig
@4np
4np / UXColor+Hex.swift
Last active June 15, 2018 09:34
Cross-platform hex colors for UIColor and NSColor
//
// UXColor+Hex.swift
//
// Created by Jeroen Wesbeek on 15/06/2018.
// Copyright © 2018 Jeroen Wesbeek. All rights reserved.
//
import Foundation
#if os(iOS) || os(tvOS) || os(watchOS)
@4np
4np / SlackBot.md
Last active April 26, 2018 15:47
Vapor SlackBot POC

Package.swift:

// swift-tools-version:4.0
import PackageDescription

let package = Package(
    name: "SlackBot",
    dependencies: [
        // 💧 A server-side Swift web framework.
@4np
4np / erase-touchbar-contents.sh
Created October 19, 2017 08:10
Erase TouchBar contents
#!/usr/bin/env bash
#source: https://9to5mac.com/2017/10/17/how-to-erase-macbook-pro-touch-bar-before-selling/
xartutil --erase-all