Skip to content

Instantly share code, notes, and snippets.

@RustyKnight
RustyKnight / CircleProgressTest.java
Created July 26, 2018 11:12
An implementation of circular progress bar concept in Java/Swing using the 2D Graphics, Shapes API
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
@RustyKnight
RustyKnight / Animation.swift
Last active August 2, 2018 22:39
A really basic implementation of "animatable" concept - something which can generate a time based progression for the purpose of animation
import Foundation
import UIKit
// MARK: Base animation
public class Animation {
internal var displayLink: CADisplayLink?
public var isRunning: Bool {
@RustyKnight
RustyKnight / UIImage+CircularProgress.swift
Last active August 2, 2018 09:03
An extension to provide a "circular progress" effect, which makes the image grey scale, generates a "pie slice" progression path and overlays the "exposed" color image
internal extension FloatingPoint {
var degreesToRadians: Self { return self * .pi / 180 }
var radiansToDegrees: Self { return self * 180 / .pi }
}
extension UIImage {
func circularProgress(_ progress: Double,
grayScaleAlpha: Double = 1.0,
@RustyKnight
RustyKnight / ImageViewProgess.swift
Created August 2, 2018 23:38
A implementation of a circular progress image based on a UIImageView
import Foundation
import UIKit
public class ImageViewProgess: UIImageView {
fileprivate var actualImage: UIImage?
fileprivate var grayScaleImage: UIImage?
@IBInspectable public override var image: UIImage? {
@RustyKnight
RustyKnight / Test.java
Created August 9, 2018 08:20
Demonstration of using two threads to synchronise the printing of odd and even lists of numbers, so they appear in order
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Test {
public static void main(String[] args) throws InterruptedException {
ReentrantLock lock = new ReentrantLock();
Condition con = lock.newCondition();
@RustyKnight
RustyKnight / AbstractAnimatable.java
Last active August 19, 2018 01:26
A simple Java/Swing based time based animation framework
import java.time.Duration;
import java.time.LocalDateTime;
public abstract class AbstractAnimatable<T> implements Animatable<T> {
private Range<T> range;
private LocalDateTime startTime;
private Duration duration = Duration.ofSeconds(5);
private T value;
private AnimatableListener<T> animatableListener;
@RustyKnight
RustyKnight / String+Trimmed.swift
Created August 29, 2018 22:01
Simple "trimming" support for String
import Foundation
extension String {
var trimmed: String {
return self.trimmingCharacters(in: .whitespacesAndNewlines)
}
var isEmptyWhenTrimmed: Bool {
return trimmed.isEmpty
@RustyKnight
RustyKnight / UIViewController+DismissKeyboard.swift
Created August 29, 2018 22:03
Dismissible keyboard support for iOS
import Foundation
import UIKit
// I'm not a fan of this, but this will allow us to maintain state beyond the capabailities of the the extension API
fileprivate var cache = NSMapTable<UIViewController, UITapGestureRecognizer>(keyOptions: .weakMemory, valueOptions: .weakMemory)
extension UIViewController {
fileprivate var tapRecognizer: UITapGestureRecognizer? {
@RustyKnight
RustyKnight / UIViewController+HideKeyboard.swift
Created August 29, 2018 22:05
Extension to hide the keyboard (resign first responder) globally
import Foundation
import UIKit
extension UIViewController {
@objc func hideKeyboard() {
UIApplication.shared.sendAction(#selector(UIApplication.resignFirstResponder), to: nil, from: nil, for: nil)
}
@RustyKnight
RustyKnight / UIViewController+KeyboardDisplacer.swift
Created August 29, 2018 22:05
Extension to display the view when keyboard is presented
import Foundation
import UIKit
// I'm not a fan of this, but this will allow us to maintain state beyond the capabailities of the the extension API
fileprivate var cache = NSHashTable<UIViewController>(options: .weakMemory)
extension UIViewController {
fileprivate var isInstalled: Bool {