Skip to content

Instantly share code, notes, and snippets.

View conath's full-sized avatar

CONATH conath

View GitHub Profile
@conath
conath / ResizableLineView.swift
Created September 12, 2020 19:16
A UIView that fills its bounds with a black rectangle in light mode, or a white rectangle in dark mode.
//
// ResizableLineView.swift
// YourProjectName
//
// Created by conath on 09/12/20. Should work on iOS 12 and later.
//
// This is free and unencumbered software released into the public domain.
//
// Anyone is free to copy, modify, publish, use, compile, sell, or
// distribute this software, either in source code form or as a compiled
@conath
conath / Data+Hex.swift
Last active April 24, 2024 00:22
A close to complete CoreData Bluetooth peripheral implementation of the Bluetooth HID Keyboard standard. As of iOS 14, the services are blocked by the system so it's impossible to make an iOS device act as a bluetooth keyboard, for example.
import Foundation
extension Data {
init?(hexString: String) {
let len = hexString.count / 2
var data = Data(capacity: len)
for i in 0..<len {
let j = hexString.index(hexString.startIndex, offsetBy: i*2)
let k = hexString.index(j, offsetBy: 2)
let bytes = hexString[j..<k]
@conath
conath / UIView+animateWiggle.swift
Created June 9, 2020 12:37
Shakes a UIView left and right, a good duration seems to be 0.15s
import UIKit
extension UIView {
func animateWiggle(withDuration duration: TimeInterval, delay: TimeInterval, completion: @escaping((Bool) -> ())) {
UIView.animate(withDuration: duration/4, delay: delay, usingSpringWithDamping: 0.5, initialSpringVelocity: 10, options: [], animations: {
self.transform = CGAffineTransform.identity.translatedBy(x: 8, y: 0)
}) { _ in
UIView.animate(withDuration: duration/4, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 10, options: [], animations: {
self.transform = CGAffineTransform.identity.translatedBy(x: -7, y: 0)
}) { _ in
@conath
conath / matrix-table-printing.py
Created February 3, 2017 17:03
[Python 2.7] 2d str matrix table-str generation
# Licensed under "The Unlicense"
# Created by CONATH on 03 Feb 2017
def repeatStr(string, times):
ausgabe = str(string)
for i in range(times):
ausgabe += string
return ausgabe
def maxLength(matrix):