Skip to content

Instantly share code, notes, and snippets.

Avatar

Kevin Peng aoenth

  • Toronto, Canada
View GitHub Profile
@aoenth
aoenth / init.vim
Created Aug 30, 2021
Configuration for Neovim
View init.vim
" 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'
View LayoutGuides.swift
import UIKit
class TestViewController: UIViewController {
let stackView: UIStackView = {
let stackView = UIStackView()
stackView.translatesAutoresizingMaskIntoConstraints = false
stackView.axis = .vertical
stackView.spacing = 16
return stackView
View keybase.md

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:

@aoenth
aoenth / UIColor+Extensions.swift
Created May 28, 2020
UIColor convenience initializer, taking hex as an argument
View UIColor+Extensions.swift
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)
}
}
@aoenth
aoenth / DynamicColors.swift
Created May 27, 2020
Return a color based on percentage. 0% is Red, and 100% is Green
View DynamicColors.swift
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
Return a color based on percentage. 0% is Red and 100% is Green
View FixedColors.swift
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)
View CZ010.swift
let anotherDate = normalDate(fromYear: 1991, month: 1, day: 20)
let anotherZodiac = zodiacFrom(date: anotherDate)
print(anotherZodiac)
View CZ009.swift
let date = normalDate(fromYear: 1991, month: 6, day: 22)
let zodiac = zodiacFrom(date: date)
print(zodiac)
View CZ008.swift
func normalDate(fromYear year: Int, month: Int, day: Int) -> Date {
var normalCalendarDateComponents = DateComponents()
normalCalendarDateComponents.year = year
normalCalendarDateComponents.month = month
normalCalendarDateComponents.day = day
let normalCalendar = Calendar(identifier: .gregorian)
let normalDate = normalCalendar.date(from: normalCalendarDateComponents)!
return normalDate
}
View CZ007.swift
guard let hyphen = chineseDate.firstIndex(of: "-") else {
fatalError("\(chineseDate) is not correctly formatted, use DateFormatter.Style.full")
}
let startIndex = chineseDate.index(after: hyphen)
let endIndex = chineseDate.index(chineseDate.endIndex, offsetBy: -2)
let branch = chineseDate[startIndex ... endIndex]
print(branch)