Skip to content

Instantly share code, notes, and snippets.

View nguyentruongky's full-sized avatar
💻
Code for life.

Ky Nguyen nguyentruongky

💻
Code for life.
View GitHub Profile
// Online C++ compiler to run C++ program online
#include <iostream>
#include <string>
using namespace std;
struct Sach
{
string id;
string tenSach;
string tacGia;
@nguyentruongky
nguyentruongky / UITextFieldExtension.swift
Created May 15, 2019 09:02
UITextField extension functions
//
// UITextField.swift
// kLibrary
//
// Created by Ky Nguyen on 8/27/16.
// Copyright © 2016 Ky Nguyen. All rights reserved.
//
import UIKit
@nguyentruongky
nguyentruongky / button_process_indicator.swift
Created May 6, 2019 02:56
Show indicator view inside UIButton
func setProcess(visible: Bool,
style: UIActivityIndicatorView.Style = .white) {
if visible {
titleLabel?.layer.opacity = 0
isEnabled = false
let indicator = UIActivityIndicatorView(style: style)
indicator.translatesAutoresizingMaskIntoConstraints = false
indicator.tag = 12398137
indicator.startAnimating()
addSubview(indicator)
@nguyentruongky
nguyentruongky / view_loading_indicator.swift
Created April 24, 2019 10:44
Add loading indicator with color, size to any views
extension UIView {
static let loadingViewTag = 1938123987
func showLoading(style: UIActivityIndicatorView.Style = .gray, color: UIColor? = nil, scale: CGFloat = 1) {
var loading = viewWithTag(UIView.loadingViewTag) as? UIActivityIndicatorView
if loading == nil {
loading = UIActivityIndicatorView(style: style)
}
loading?.scale(value: scale)
if let color = color {
loading?.color = color
class Animator {
var view = UIView()
lazy var dropZone = self.makeDropZone()
var dragImageView: UIImageView?
var startPoint = CGPoint.zero
var recognizer: UILongPressGestureRecognizer?
private func makeDropZone() -> UIView {
let dropZoneEdge = 250
let dropZoneMissingEdge: CGFloat = 50
struct ogeSystemCalendar {
let eventStore = EKEventStore()
func addEvent(title: String, startDate: Date,
endDate: Date, notes: String?) {
eventStore.requestAccess(to: .event) { (granted, error) in
if granted == false {
DispatchQueue.main.async {
self.tellNoPermission() }
return
let userName = "myUsername"
let password = "myPassword"
let authString = userName + ":" + password
let credentialData = authString.dataUsingEncoding(NSUTF8StringEncoding)!
let base64Credentials = credentialData.base64EncodedStringWithOptions([])
let headers = ["Authorization": "Basic " + base64Credentials]
let url = URL(string: api)!
Alamofire.request(url, method: .post,
parameters: params,
@nguyentruongky
nguyentruongky / tab_controller_slide.swift
Created November 14, 2017 10:58
Slide animation in tab bar controller
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
animateSliding(fromController: selectedViewController, toController: viewController)
return false
}
func animateSliding(fromController: UIViewController?, toController: UIViewController?) {
guard let fromController = fromController, let toController = toController else { return }
guard let fromIndex = viewControllers?.index(of: fromController),
let toIndex = viewControllers?.index(of: toController) else { return }
@nguyentruongky
nguyentruongky / tab_controller_fading.swift
Created November 14, 2017 10:56
Fade animation in tab bar controller
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
animateFading(fromController: selectedViewController, toController: viewController)
return true
}
func animateFading(fromController: UIViewController?, toController: UIViewController?) {
if fromController == nil || toController == fromController { return }
guard let selectView = (selectedViewController as? UINavigationController)?.viewControllers.first?.view,
let newView = (toController as? UINavigationController)?.viewControllers.first?.view else { return }
@nguyentruongky
nguyentruongky / use_most_of_24_hours.md
Last active April 24, 2017 03:52
Tips to save your time and make your code quality become better. This talk is presented in Swift Battle.

Make the Most of Your 24 Hours

Bitter Experience

I started iOS as a 2-year-experience .NET developer. The salary range for a junior iOS dev is a little bit lower than the amount for a 2-year-experience develop get. I wanted to make myself stronger, earn more experience. I had a misconception of working and learning. I thought, freelance projects will help me strengthen my knowledge and experience. So I tried to get as more as possible freelance projects. And my nightmare started from here.

I had no time to spend with my family, no time to work on personal improvement, no time to go out with friends, no time at all. All of my time was used up on my freelance work from coding new features, fixing bugs and much more. I was killing myself working odd hours and missing out on quality time with my family and friends.

I made a mess, uncountable technical debts, bugs, with the project. I was angry with everyone and myself. And the company project was affected. I brought more bugs there, dozens of stupid bug