Skip to content

Instantly share code, notes, and snippets.

View vietstone-ng's full-sized avatar
🎓

Viet Nguyen Tran vietstone-ng

🎓
View GitHub Profile
// This code can be put in UIViewController subclass
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
view.endEditing(true)
}
//
// SpacingLabel.swift
// SpacingLabel
//
// Created by Viet Nguyen Tran on 6/13/17.
// Copyright © 2017 iossimple. All rights reserved.
//
import UIKit
//
// SpacingButton.swift
// MglabSpice
//
// Created by Viet Nguyen Tran on 6/14/17.
// Copyright © 2017 iossimple. All rights reserved.
//
import UIKit
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>example.com</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
@vietstone-ng
vietstone-ng / timezone.swift
Created April 5, 2018 07:03
Manage datetime with timezone
import SwiftDate
let response = "2018-04-25T06:00:00"
let format = "yyyy-MM-dd'T'HH:mm:ss"
let utc = Region.GMT()
let timeInUTC = response.date(format: .custom(format), fromRegion: utc)
print(timeInUTC)
let absoluteTime = timeInUTC?.absoluteDate
print(absoluteTime)
let timeInVietnam = DateInRegion(absoluteDate: absoluteTime!, in: Region.Local())
extension UIColor {
convenience init(red: Int, green: Int, blue: Int) {
assert(red >= 0 && red <= 255, "Invalid red component")
assert(green >= 0 && green <= 255, "Invalid green component")
assert(blue >= 0 && blue <= 255, "Invalid blue component")
self.init(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: 1.0)
}
convenience init(netHex:Int) {
self.init(red:(netHex >> 16) & 0xff, green:(netHex >> 8) & 0xff, blue:netHex & 0xff)
extension UIApplication {
static func topViewController(base: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? {
if let nav = base as? UINavigationController {
return topViewController(base: nav.visibleViewController)
}
if let tab = base as? UITabBarController {
if let selected = tab.selectedViewController {
return topViewController(base: selected)
}
}
@vietstone-ng
vietstone-ng / EnumCodable.swift
Created April 23, 2018 16:35
Enum with raw values working with Codable
enum SongLanguage: Int {
case vietnamese = 0
case english = 1
case thai = 2
case unknown = -1
}
extension SongLanguage: Codable {
func encode(to encoder: Encoder) throws {
var container = encoder.unkeyedContainer()
@vietstone-ng
vietstone-ng / main.dart
Created March 18, 2022 07:46
Test Bottom Navigation Bar
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
@override
@vietstone-ng
vietstone-ng / universal-switcher
Created May 3, 2024 15:50 — forked from jthodge/universal-switcher
Show macOS app switcher across all monitors
defaults write com.apple.Dock appswitcher-all-displays -bool true
killall Dock