Skip to content

Instantly share code, notes, and snippets.

View jdev7's full-sized avatar

Juan Navas jdev7

View GitHub Profile
@jdev7
jdev7 / auto_mark_as_read_old_mails.gs
Created March 22, 2023 11:09
Gmail Maintenance automation: Mark as read emails older than 10 days, from specific labels.
// Inspiration source: https://www.maketecheasier.com/google-scripts-to-automate-gmail/
function auto_mark_as_read_old_mails() {
var labels = ["Builds/Firebase", "Builds/TestFlight", "AppStore Connect"];
for (var i = 0; i < labels.length; i++) {
var label = GmailApp.getUserLabelByName(labels[i]);
if(label != null) {
processThreads_(label.getThreads(), labels[i]);
} else {
console.log("wrong label: ", labels[i]);
}
import UIKit
import PlaygroundSupport
public class CircleProgressView: UIView {
private var radius: CGFloat { (bounds.height - lineWidth) / 2 }
private let baseLayer = CAShapeLayer()
private let progressLayer = CAShapeLayer()
private let progress: CGFloat
private let lineWidth: CGFloat = 10.0
@jdev7
jdev7 / AnimateCircleProgress.swift
Last active February 14, 2021 20:06
How to add an animation to animate the strokeEnd of a CAShapeLayer
func addAnimation(duration: TimeInterval, delay: TimeInterval) {
let animation = CABasicAnimation(keyPath: "strokeEnd")
animation.beginTime = CACurrentMediaTime() + delay
animation.duration = duration
animation.fromValue = 0
animation.toValue = 1
animation.timingFunction = CAMediaTimingFunction(name: .easeIn)
animation.fillMode = .forwards
animation.isRemovedOnCompletion = false
@jdev7
jdev7 / CGFloat+Angles.swift
Last active February 14, 2021 12:50
An extension to calculate radians based on a North initial point
private extension CGFloat {
static var initialAngle: CGFloat = -(.pi / 2)
static func endAngle(progress: CGFloat) -> CGFloat {
.pi * 2 * progress + .initialAngle
}
}
let path = UIBezierPath(
arcCenter: CGPoint(x: bounds.width / 2, y: bounds.height / 2),
@jdev7
jdev7 / CircleWithCAShapeLayer+UIBezierPath.swift
Created February 14, 2021 12:00
Drawing a circle with CAShapeLayer and UIBezierPath
let layer = CAShapeLayer()
layer.lineWidth = 8
layer.fillColor = UIColor.clear.cgColor
layer.lineWidth = lineWidth
layer.strokeColor = UIColor.orange.cgColor
let path = UIBezierPath(
arcCenter: CGPoint(x: bounds.width / 2, y: bounds.height / 2),
radius: (bounds.height - lineWidth) / 2,
startAngle: 0,
@jdev7
jdev7 / gist:ac12402ec4d331d723de55c6e48635ec
Created July 1, 2020 10:28
Command to launch an URL in the iOS simulator, which is useful to try Universal Links (since in Safari you can't launch the app with a Universal Link)
xcrun simctl openurl booted https://www.example.com/faq
// https://objectivetidbits.com/2017/06/08/working-with-universal-links-on-ios-simulator/
@jdev7
jdev7 / IntrinsicContentSizeTableView.swift
Last active May 25, 2020 14:23
A UITableView subclass that adapts to its content size, up to a seteable maxHeight
// Idea obtained from https://medium.com/@dushyant_db/swift-4-recipe-self-sizing-table-view-2635ac3df8ab
// it can be useful if you want to center it in the screen (let's say in an iPad for example), or take up all the available
// height. Also it could be used to be placed inside a UIStackView
class IntrinsicContentSizeTableView: UITableView {
var maxHeight: CGFloat = UIScreen.main.bounds.size.height
override var intrinsicContentSize: CGSize {
let height = min(contentSize.height, maxHeight)
return CGSize(width: contentSize.width, height: height)
}
@jdev7
jdev7 / MeasuringImprovementReduce1000iterations.swift
Last active November 3, 2017 17:04
Measuring improvement against unoptimized reduce
Total time: 2.64654844999313
TotalTimeOptimized: 2.50773054361343
Total time difference: 0.1388179063797
Average: 0.0001388179063797
@jdev7
jdev7 / ReduceRandomStringOptimized.swift
Created November 3, 2017 16:59
Random string by reducing, optimized
extension String {
static func randomStringOptimized(size: UInt) -> String {
let stringSet = "0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ"
return (0..<size).reduce(into: "", stringSet.randomCharacterOptimized)
}
private func randomCharacterOptimized(partialResult: inout String, iterationIndex: UInt) {
let randomIndex = arc4random_uniform(UInt32(count))
let charIndex = index(startIndex, offsetBy: String.IndexDistance(randomIndex))
@jdev7
jdev7 / ReduceRandomStringFunction.swift
Created November 1, 2017 21:52
Using reduce to get a random string, with a function
extension String {
static func randomString(size: UInt) -> String {
let stringSet = "0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ"
return (0..<size).reduce("", stringSet.randomCharacter)
}
private func randomCharacter(partialResult: String, iterationIndex: UInt) -> String {
let randomIndex = arc4random_uniform(UInt32(count))
let charIndex = index(startIndex, offsetBy: String.IndexDistance(randomIndex))
return partialResult.appending(String(self[charIndex]))