Skip to content

Instantly share code, notes, and snippets.

View jnewc's full-sized avatar

Jack Newcombe jnewc

View GitHub Profile
@jnewc
jnewc / NotesApp.swift
Last active January 21, 2024 17:40
A notes app written in >100 lines of swift using SwiftUI
import SwiftUI
let dateFormatter = DateFormatter()
struct NoteItem: Codable, Hashable, Identifiable {
let id: Int
let text: String
var date = Date()
var dateText: String {
dateFormatter.dateFormat = "MMM d yyyy, h:mm a"
@jnewc
jnewc / i2c_test.c
Last active May 8, 2021 03:17
i2c analog stick driver
/*
* i2c_test.c
*/
#include <linux/slab.h> /* kzalloc */
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* KERN_INFO */
#include <linux/timer.h> /* timer_list */
#include <linux/workqueue.h> /* schedule_work */
@jnewc
jnewc / fix-sourcetree-git-secrets.sh
Last active August 26, 2020 16:44 — forked from Neo23x0/fix-sourcetree-git-secrets.sh
SourceTree git-secrets
#!/bin/bash
#
# THIS WORKS WITH GIT INSTALLED VIA BREW
#
# Fixes error:
# git: 'secrets' is not a git command. See 'git --help'.
#
# More information: https://qiita.com/yamaryu0508/items/d959dc32442b08b8a0a4
brew install git
@jnewc
jnewc / yolo.swift
Created August 15, 2020 17:15
More natural (fight me) OptionSet syntax for Swift
func |<T>(_ first: T, _ second: T) -> T where T: OptionSet {
return first.union(second)
}
@jnewc
jnewc / file.c
Created April 14, 2020 16:37
LEDTime.ino
#include <Time.h>
#include <TimeLib.h>
#include <NeoPixelBus.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <WiFiUdp.h>
int dividerLEDs[] = { 4, 11 };
int dividerLEDsCount = 2;
@jnewc
jnewc / swiftver.md
Created June 23, 2018 13:05
swiftver

swiftver - Swift versioning scheme

Currently Swift modules are mostly consumed using semantic versioning (i.e. using SPM or Cocoapods).

This scheme is a revised version of semantic versioning that links the major version of the latest Swift toolchain that the

Scheme

MAJOR - Incremented when the project is updated to a new Swift language version. e.g. For Swift 4, this would be '4'.

@jnewc
jnewc / ConditionalExecutionOperators.swift
Last active June 28, 2017 19:47
Conditional Execution Operators
/// Conditional execution operators
///
/// For a given argument:
/// * if the argument is truthy (i.e. true or non-nil), execute closure
/// * if the argument is falsy (i.e. false or nil), do not execute the closure
infix operator => : NilCoalescingPrecedence
public func =>(state: Bool, closure: @autoclosure () -> ()) {
if state { closure() }
@jnewc
jnewc / Logger.swift
Last active February 22, 2017 20:25
Class-based logger as a protocol extension
import Foundation
import Rainbow
public enum LogLevel: UInt {
case none = 0b0000
case debug = 0b0001
case info = 0b0011
case warn = 0b0111
case error = 0b1111
}
@jnewc
jnewc / NilRejectionExample.swift
Last active February 8, 2017 21:48
Nil-rejection operator example
infix operator !! : NilCoalescingPrecedence
func !!<UnwrappedType: Any, ErrorType: Error>(lhs: Optional<UnwrappedType>, rhs: ErrorType) throws -> UnwrappedType {
guard let unwrappedValue = lhs else {
throw rhs
}
return unwrappedValue
}
@jnewc
jnewc / reggie-gpio-keys.c
Created April 29, 2016 09:00
Reggie's gpio-keys driver
// Reggie added, simple gpio keys polled driver, adds button support via gpio
// will be useful for embedded devices, see gpio-mouse, gpio-fan and rotary-encoder
// for other examples of gpio access to devices from the linux kernel
// this will use GPIO4,17,21,22 as a simple test, they will be set to active_low
// so should have a pullup added to each pin and button tied to ground.
// We have to use polled at the moment because the current kernel doesn't have
// code to handle an interrupt driven gpio-keys driver, which would've been much nicer
// you should check the wiki to make sure that these gpio are correctly configured
// and see whether they are physically pulled up on the schematic, if they're not
// add a 10k pullup to the gpio-keys pins and tie the button to gnd