Skip to content

Instantly share code, notes, and snippets.

View mbernson's full-sized avatar
👨‍💻
Coding...

Mathijs Bernson mbernson

👨‍💻
Coding...
View GitHub Profile
@mbernson
mbernson / formatting.sh
Created September 25, 2020 08:06
Automatically format Swift files that have changed before committing
#!/usr/bin/env bash
# formatting.sh - Automatically formats Swift files that have changed before committing.
DIFF_FILTER="ACMR" # Only format files that have been added, copied, modified or renamed.
STAGED_FILES=$(git diff --cached --name-only --diff-filter=$DIFF_FILTER "*.swift")
NOT_STAGED_FILES=$(git diff --name-only --diff-filter=$DIFF_FILTER "*.swift")
# Skip formatting for partially staged files. This is done by subtracting any files that git also considers unstaged from the list.
FILES_TO_FORMAT=($(comm -23 <(printf "%s\n" "${STAGED_FILES[@]}" | sort) <(printf "%s\n" "${NOT_STAGED_FILES[@]}" | sort)))
@mbernson
mbernson / x.rb
Last active November 13, 2020 08:04
X - Opens the Xcode workspace/project or Swift package in your current working directory using Xcode.
#!/usr/bin/env ruby
XCODE_PATH = File.expand_path(File.join(`xcode-select -p`.chomp, '../..'))
def open_cmd(pattern)
files = Dir.glob(pattern)
`open -a "#{XCODE_PATH}" "#{files.first}"` and exit if files.count == 1
end
open_cmd '*.xcworkspace'
@mbernson
mbernson / create_color_assets.php
Last active June 25, 2019 13:09
Generate color assset catalog
<?php
// Configuration
$source_file = 'Theme.swift';
$output_asset_catalog = 'MyApp/Resources/Colors.xcassets';
//
function mkdir_if_not_exists($directory) {
if (!is_dir($directory)) {
@mbernson
mbernson / camera.yaml
Last active March 9, 2024 23:45
esphome configuration for the TTGO T-Camera ESP32-WROVER-B
# esphome configuration for the TTGO T-Camera ESP32-WROVER-B
# https://www.aliexpress.com/item/TTGO-T-Camera-ESP32-WROVER-B-PSRAM-Camera-Module-ESP32-WROVER-OV2640-Camera-Module-0-96/32966036489.html
# I use this 3D-printed case for the device:
# https://www.thingiverse.com/thing:3540059
esphome:
name: woonkamer
platform: ESP32
board: esp32dev
@mbernson
mbernson / easter.swift
Created March 26, 2019 16:33
All Easter dates from the year 0 until 2100
import Foundation
func easter(for year: Int) -> Date? {
// Code from Gist: https://gist.github.com/duedal/2eabcede718c69670102
let a = year % 19
let b = Int(floor(Double(year) / 100))
let c = year % 100
let d = Int(floor(Double(b) / 4))
let e = b % 4
let f = Int(floor(Double(b+8) / 25))
@mbernson
mbernson / UIImage+Tinted.swift
Created January 10, 2019 09:08
Applies a tint color to a uiimage
import UIKit
extension UIImage {
func tinted(withColor color: UIColor) -> UIImage? {
UIGraphicsBeginImageContextWithOptions(size, false, 0)
defer { UIGraphicsEndImageContext() }
let rect = CGRect(origin: .zero, size: size)
// Tint the image
self.draw(in: rect)
@mbernson
mbernson / phone.py
Created December 9, 2018 15:59
AIY Phone project
#!/usr/bin/env python3
# Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
@mbernson
mbernson / notification_callback_add.php
Last active January 2, 2018 19:10
Listing/adding/removing notification filters using the bunq API
<?php
use bunq\Context\ApiContext;
use bunq\Model\Generated\Endpoint\User;
use bunq\Model\Generated\Endpoint\UserCompany;
use bunq\Model\Generated\Endpoint\UserPerson;
use bunq\Model\Generated\Object\NotificationFilter;
require 'vendor/autoload.php';
@mbernson
mbernson / diff.txt
Created April 10, 2017 08:41
Eachine AIOF3_BRUSHED Flight Controller Flysky default config
# diff
# version
# BetaFlight/OMNIBUS 3.0.1 Oct 18 2016 / 10:21:07 (48b7b4f)
# name
# mixer
# servo
@mbernson
mbernson / gist:3d501bcaa453b477752de8d414fb9ec6
Last active March 22, 2017 09:20
Bertcopter Betafligth settings (diff output)
CLI
# diff
# Betaflight / OMNIBUS 3.1.6 Mar 6 2017 / 22:16:32 (1fd502c3)
name Bertcopter
feature -RX_PPM
feature -CURRENT_METER
feature -OSD
feature RX_SERIAL