Skip to content

Instantly share code, notes, and snippets.

View yojkim's full-sized avatar

Yongjae Kim yojkim

View GitHub Profile
private var _view: UIView?
var view: UIView! {
get {
guard let view = _view else {
// force-loading
loadView()
return _view
}
}
import 'package:flutter/widgets.dart';
void main() {
runApp(const Center(
child: const Text('Hello', textDirection: TextDirection.ltr)));
}
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return GestureDetector(onTap: () => print('tapped'));
}
let arr = ["a", "aa", "aaa", "aaaa", "aaaaa", "aaaaaa"]
func getElementCount(_ index: Int) -> Int {
guard let value = arr[safe: index] else { return 0 }
return value.count
}
(-5..<10).forEach {
print("\($0) : \(getElementCount($0))")
}
extension Collection {
subscript (safe index: Index) -> Element? {
return indices.contains(index) ? self[index] : nil
}
}
@yojkim
yojkim / safe-way-to-access-array-1.swift
Created January 1, 2021 13:12
more safe way to access array in swift - 1
let arr = [1, 2, 3, 4]
arr[4] // Fatal error: Index out of range
extension UINavigationController: UINavigationControllerDelegate {
open override func viewDidLoad() {
super.viewDidLoad()
self.delegate = self
}
public func navigationController(
_ navigationController: UINavigationController,
didShow viewController: UIViewController,
func sumSubarrayMins(A []int) int {
dp := make([]int, len(A)+1)
stack := []int{-1}
res := 0
for i, n := range A {
for stack[len(stack)-1] != -1 && n <= A[stack[len(stack)-1]] {
stack = stack[:len(stack)-1]
}
package main
import (
"fmt"
"io/ioutil"
"log"
"sort"
"strconv"
"strings"
)
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"regexp"
"strings"
)