Skip to content

Instantly share code, notes, and snippets.

View LemonSpike's full-sized avatar
🌋

Pranav Kasetti LemonSpike

🌋
View GitHub Profile
@LemonSpike
LemonSpike / NumericEitherEnum.swift
Last active March 3, 2021 20:58
Confusing NumericEitherEnum
import Foundation
enum NumericEitherEnum<Left, Right> {
case left(Left)
case right(Right)
var left: Left? {
switch self {
case .left(let left) where left is NumericEitherEnum:
return (left as? NumericEitherEnum)?.left
@LemonSpike
LemonSpike / RecursiveEitherEnum.swift
Last active March 5, 2021 02:53
Recursive Swift Either Enum with Associated Values
enum RecursiveEither<Left, Right> {
case left(ValueOrRecursiveEither<Left, Left, Right>)
case right(ValueOrRecursiveEither<Right, Left, Right>)
var left: Left? {
switch self {
case .left(.value(let left)):
return left
case .left(.either(let left)):
return left.left
@LemonSpike
LemonSpike / Best in Class iOS Checklist
Created April 19, 2021 06:37 — forked from DreamingInBinary/Best in Class iOS Checklist
This is a public checklist updated every year after the latest version of iOS and iPadOS are shipped. It's a boiled down version of a "Best in Class" app checklist created by Jordan Morgan.
# A Best in Class Checklist
A boiled down checklist adapted from this [post](https://www.swiftjectivec.com/a-best-in-class-app/), created by @jordanmorgan10.
> To use this, create a Github Issue in your own repo, and simply copy and paste this text.
## iOS Core Technology
_Things any iOS app can benefit from_
- [ ] iCloud Sync
- [ ] [Core Spotlight integration](https://github.com/DreamingInBinary/Spend-Stack/issues/120)
@LemonSpike
LemonSpike / iso8601timestampformatter.swift
Created April 30, 2021 18:48
Swift Date Formatter for ISO8601 timestamps
import Foundation
let dateFormatter = ISO8601DateFormatter()
let timestamp = "2021-04-30T18:11:29-06:00"
let date = dateFormatter.date(from: timestamp)
print(date) // 🎉 🤔 🎊
@LemonSpike
LemonSpike / CAGradientLayerExample.swift
Created April 30, 2021 19:00
Example code for creating gradients with CAGradientLayer
let view = UIView()
view.backgroundColor = .white
let gradient = CAGradientLayer()
gradient.frame = view.bounds
gradient.colors = [UIColor.black.cgColor, UIColor.white.cgColor]
gradient.locations = [0, 1]
gradient.startPoint = CGPoint(x: 1, y: 1)
gradient.endPoint = CGPoint(x: 0, y: 0)
@LemonSpike
LemonSpike / JavaInXcode.java
Last active April 30, 2021 19:10
Running Java in Xcode.. don't ask me why 🤷‍♂️. Taken from: https://discussions.apple.com/docs/DOC-5161.
import UIKit
// 🤔
class ChangeConstants {
private final int[] orderedCoinLabels = { FIFTY_POUNDS_VALUE,
TWENTY_POUNDS_VALUE,
TEN_POUNDS_VALUE,
FIVE_POUNDS_VALUE,
TWO_POUNDS_VALUE,
ONE_POUND_VALUE,
@LemonSpike
LemonSpike / SIMDToCGPoint.swift
Created April 30, 2021 19:21
Manipulating SIMD Vectors to create CGPoint (example reflection)
import UIKit
import simd
var p = SIMD2<Float>(Float(1), Float(1))
var v = SIMD2<Float>(Float(2), Float(1))
var y = simd_reflect(v, p)
var x = CGPoint(x: CGFloat(v[0]), y: CGFloat(v[1]))
@LemonSpike
LemonSpike / FourSumAlgorithm.swift
Created May 2, 2021 18:32
FourSum algorithm implemented in pure Swift
public class QOneSolutionOne {
func fourSum(_ nums: [Int], target: Int) -> [[Int]] {
let nums = nums.sorted()
return kSum(nums, target, 0, 4)
}
func kSum(_ nums: [Int], _ target: Int, _ start: Int, _ kValue: Int) -> [[Int]] {
var res: [[Int]] = []
if (start == nums.count) || (nums[start] * kValue > target) ||
@LemonSpike
LemonSpike / analysis_options.yaml
Created May 16, 2021 22:55
Pedantic Analysis Options for Dart/Flutter App Listing
include: package:pedantic/analysis_options.yaml
analyzer:
exclude:
# Exclude json serializable files, and generated files.
strong-mode:
implicit-casts: false
implicit-dynamic: false
errors:
prefer_const_constructors: error
@LemonSpike
LemonSpike / keybase.md
Created July 6, 2021 10:42
keybase.md

Keybase proof

I hereby claim:

  • I am lemonspike on github.
  • I am britcoin (https://keybase.io/britcoin) on keybase.
  • I have a public key ASAbL14RLrCxXP7Utx6xq8zEzFjoe4Fh48wAHJB28J_ouAo

To claim this, I am signing this object: