Skip to content

Instantly share code, notes, and snippets.

View aoenth's full-sized avatar

Kevin Peng aoenth

  • Toronto, Canada
View GitHub Profile
@aoenth
aoenth / DynamicColors.swift
Created May 27, 2020 20:39
Return a color based on percentage. 0% is Red, and 100% is Green
extension UIColor {
static func colorForPercent(_ percentage: Double) -> UIColor {
switch percentage {
case 0...0.5:
return firstHalf(percentage: percentage * 2)
case 0.5...1:
return secondHalf(percentage: (percentage - 0.5) * 2)
default:
fatalError("Bad Input: percentage must satisfy 0 <= percentage <= 1")
}
@aoenth
aoenth / FixedColors.swift
Last active May 27, 2020 20:59
Return a color based on percentage. 0% is Red and 100% is Green
static func colorForPercent(_ percentage: Double) -> UIColor {
switch percentage {
case 0..<0.33:
return UIColor(hex: 0xE02020)
case 0.33..<0.66:
return UIColor(hex: 0xFA6400)
case 0.66..<1:
return UIColor(hex: 0xF7B500)
case 1:
return UIColor(hex: 0x6DD400)
@aoenth
aoenth / UIColor+Extensions.swift
Created May 28, 2020 19:55
UIColor convenience initializer, taking hex as an argument
import UIKit
extension UIColor {
convenience init(hex: Int) {
let red = CGFloat((hex & 0xFF0000) >> (4 * 4))/0xFF
let green = CGFloat((hex & 0x00FF00) >> (4 * 2))/0xFF
let blue = CGFloat(hex & 0x0000FF)/0xFF
self.init(red: red, green: green, blue: blue, alpha: 1)
}
}

Keybase proof

I hereby claim:

  • I am aoenth on github.
  • I am aoenth (https://keybase.io/aoenth) on keybase.
  • I have a public key ASBy72mdXHPP8Kms3bwda6usSxk36YLJDUHMzcyUvhBm8Qo

To claim this, I am signing this object:

import UIKit
class TestViewController: UIViewController {
let stackView: UIStackView = {
let stackView = UIStackView()
stackView.translatesAutoresizingMaskIntoConstraints = false
stackView.axis = .vertical
stackView.spacing = 16
return stackView
@aoenth
aoenth / init.vim
Created August 30, 2021 14:26
Configuration for Neovim
" Plugged
call plug#begin("~/.config/nvim/plugged")
Plug 'morhetz/gruvbox'
Plug 'preservim/nerdtree'
Plug 'tiagofumo/vim-nerdtree-syntax-highlight'
Plug 'Xuyuanp/nerdtree-git-plugin'
Plug 'ryanoasis/vim-devicons'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
Plug 'itchyny/lightline.vim'
@aoenth
aoenth / WordSearch.swift
Last active January 14, 2023 00:23
A function to search words in a 2D character matrix
import Foundation
func find(word: String, in arr: [[Character]]) -> Bool {
let word = Array(word)
var index = 0
func check(x: Int, y: Int) -> Bool {
// check bounds
guard x >= 0,