Skip to content

Instantly share code, notes, and snippets.

View khanhbui's full-sized avatar

Khanh Bui khanhbui

  • Hanoi - Vietnam
View GitHub Profile
@khanhbui
khanhbui / Change the author and committer name and e-mail
Last active April 19, 2022 03:29
Change the author and committer name and e-mail
git filter-branch -f --env-filter "
GIT_AUTHOR_NAME='Newname'
GIT_AUTHOR_EMAIL='new@email'
GIT_COMMITTER_NAME='Newname'
GIT_COMMITTER_EMAIL='new@email'
" HEAD
@khanhbui
khanhbui / .gitconfig
Last active November 30, 2021 10:41
Pretty git log
[alias]
lg1 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all
lg2 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all
lg = !"git lg1"
@khanhbui
khanhbui / Multiple github accounts on a machine.md
Last active November 30, 2021 10:35
Multiple github accounts on a machine

SSH Key

  • Generate an SSH-key id_rsa_your_personal
ssh-keygen -t rsa -C "your@personal.com"
  • Add the SSH public-key to GitHub from ~/.ssh/id_rsa_your_personal.pub and tell ssh about the key.
ssh-add ~/.ssh/id_rsa_your_personal.
  • Create a config file in ~/.ssh with the following contents:
Objective C
UIInterfaceOrientation currentOrientation = [UIApplication sharedApplication].statusBarOrientation;
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
[UIViewController attemptRotationToDeviceOrientation];
Update Swift 4.0
var currentOrientation: UIInterfaceOrientation = UIApplication.shared.statusBarOrientation
@khanhbui
khanhbui / FakeNavigationBar.swift
Created March 29, 2019 04:54 — forked from fuxingloh/FakeNavigationBar.swift
Add fake navigation bar, remove, revert, load, unload and change status tint color, fake navigation bar can be used to assist transition from a controller with navigation background to one without.
extension UIViewController {
// Nav tag id
private var fakeNavTag: Int{get{return 80327}}
// Remove bar bar color and add fake nav bar
public func loadFakeNavigationBar(){
removeNavigationBarBackground()
addFakeNavigationBar()
}
@khanhbui
khanhbui / PushDissolveAnimationSegue.swift
Created March 29, 2019 04:51 — forked from fuxingloh/PushDissolveAnimationSegue.swift
iOS Swift: A PushDissolveAnimationSegue with a dissolve animation,
class PushDissolveAnimationSegue: UIStoryboardSegue {
override func perform() {
let transition = CATransition()
transition.duration = 0.2
transition.type = kCATransitionFade
self.sourceViewController.navigationController!.view.layer.addAnimation(transition, forKey: kCATransition)
self.sourceViewController.navigationController!.pushViewController(self.destinationViewController, animated: false)
@khanhbui
khanhbui / UICollectionView.swift
Created March 29, 2019 04:49 — forked from fuxingloh/UICollectionView.swift
iOS Swift: How to count the width of the UILabel. And how to size UICollectionViewCell dynamically with label.
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let text = collections[indexPath.row].name
let width = UILabel.textWidth(font: titleFont, text: text)
return CGSize(width: width + left + right, height: height)
}
@khanhbui
khanhbui / Gradient.swift
Created March 29, 2019 04:47 — forked from fuxingloh/Gradient.swift
How to add gradient on top and bottom of image view.
// Call this in layoutSubView or viewDidLoad
self.imageView.layer.sublayers?.forEach { $0.removeFromSuperlayer() }
let width = self.bounds.width
let height = self.bounds.height
let sHeight:CGFloat = 60.0
let shadow = UIColor.black.withAlphaComponent(0.6).cgColor
// Add gradient bar for image on top
let topImageGradient = CAGradientLayer()
@khanhbui
khanhbui / UILabelSize.swift
Created March 29, 2019 04:41 — forked from fuxingloh/UILabelSize.swift
iOS Swift: How to find text width, text height or size of UILabel.
extension UILabel {
func textWidth() -> CGFloat {
return UILabel.textWidth(label: self)
}
class func textWidth(label: UILabel) -> CGFloat {
return textWidth(label: label, text: label.text!)
}
class func textWidth(label: UILabel, text: String) -> CGFloat {
@khanhbui
khanhbui / UILabelCountLines.swift
Created March 29, 2019 04:40 — forked from fuxingloh/UILabelCountLines.swift
iOS Swift: How to check if UILabel is truncated? Calculate number of lines for UILabel
func countLabelLines(label: UILabel) -> Int {
// Call self.layoutIfNeeded() if your view uses auto layout
let myText = label.text! as NSString
let rect = CGSize(width: label.bounds.width, height: CGFloat.greatestFiniteMagnitude)
let labelSize = myText.boundingRect(with: rect, options: .usesLineFragmentOrigin, attributes: [NSAttributedStringKey.font: label.font], context: nil)
return Int(ceil(CGFloat(labelSize.height) / label.font.lineHeight))
}