Today I learn

A note about what I learn a day, it can be anything, not only iOS.


Auto remove apt in Ubuntu

    sudo apt autoremove


Hot keys for Visual Code

Format document

    Windows / Linux: Altr + Shift + F
    Mac: Option + Shift + F

Detail is here


Reindex spotlight High Sierra

    sudo mdutil -E /

Say this instead of “very”

  • very rude - vulgar
  • very short - brief
  • very boring - dull
  • very good - superb
  • very hot - scalding / scorching
  • very cold - freezing
  • very hungry - ravenous
  • very slow - fluggish
  • very fast - rapid
  • very tired - exhausted
  • very poor - destitute
  • very ric - wealthy
  • very happy - jubilant
  • very worried - anxious
  • very thirsty - parched
  • very dirty - squalid
  • very clean - spotless


Serve static file in Nginx

Without alias, can’t serve the static file.

    root /var/www/html/ogenii;

    location /tos {
    	default_type "text/html";
	    alias /var/www/html/ogenii/tos.html;


Create breakpoint to catch error

To see the actual statement that is causing the error add an exception breakpoint:

  • From the Main Menu Debug:Breakpoints:Create Exception Breakpoint.

  • Right-click the breakpoint and set the exception to Objective-C. This will ignore other types of exceptions such as from C++. There are parts of the APIs that use exceptions such as Core Data (Apple is Special).

  • Add an action: “po $arg1”.

Run the app to get the breakpoint and you will be at the line that causes the exception and the error message will be in the debugger console.


Change time format pm2

    pm2 start bin/www --log-date-format "YYYY-MM-DD HH:mm"


Open Location service

    if let url = URL(string: "App-Prefs:root=Privacy&path=LOCATION") {, options: [:], completionHandler: nil)

    sudo ln -s /etc/nginx/sites-available/testapp /etc/nginx/sites-enabled/testapp


Prevent rotation in iOS

There are three kinds of Device orientation keys there in the info.plist now.

  • Supported interface orientations (iPad)
  • Supported interface orientations (iPhone)
  • Supported interface orientations

Source: StackOverflow


Make app icon iOS is a really wonderful tool. Just copy folder AppIcon.appiconset and replace the old one in project and App Icon is set. Thanks a lot, awesome app.

Update SQL by removing text in text

UPDATE My_Table set my_column = REPLACE(my_column, "text_need_removed", '') where my_condition

Error in git

Error: The requested URL returned error: 403 while accessing


  • Edit .git/config file under your repo directory
  • Find url= entry under section [remote "origin"]
  • Change all the texts before @ symbol to ssh://git
  • Save

Source: StackOverflow


Open setting of my app

    if let url = URL(string: UIApplicationOpenSettingsURLString) {

Add event to calendar

    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() }
                self.addToCalendar(title: title, start: startDate,
                                end: endDate, notes: notes)
        private func tellNoPermission() {
            let alert = ogeMessage.showDialog(title: "no_permission".i18n, description: "no_calendar_permission".i18n)
            alert.addAction(PMAlertAction(title: "OK", style: .default, action: {
                DispatchQueue.main.async { ogeSystemInteractor.openCalendar() }
        private func addToCalendar(title: String, start startDate: Date,
                    end endDate: Date, notes: String?) {
            let event = EKEvent(eventStore: eventStore)
            event.title = title
            event.startDate = startDate
            event.endDate = endDate
            event.notes = notes
            event.calendar = eventStore.defaultCalendarForNewEvents
            do {
                try, span: .thisEvent)
                DispatchQueue.main.async {
                    ogeMessage.showMessage("saved_to_calendar".i18n) }
            } catch { }


Format string

Always display 2 characters for Int: 09:10, 10:15

String(format: "%02d:%02d", hr, min)


How to remove pod in iOS project

    sudo gem install cocoapods-deintegrate cocoapods-clean
    pod deintegrate
    pod clean
    rm Podfile

Integrate Zendesk SDK

Do not follow pod instruction from Zendesk tutorial, take too much time to fix but can’t run.

Add SDK manual way: Add 2 more framework from iOS MobileCoreServices.framework and Security.framework.

Access to Tagets/General, add all Zendesk SDK files to Embedded Binaries.

Merge unrelated histories in git

Usually have this issue when create new project in local, create repo in git then add remote url from git to local project.

git pull origin branch_name --allow-unrelated-histories

Basic Authorization

Learn from

    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,
                    encoding: JSONEncoding.default,
                    headers: headers)
        .validate().responseJSON { (response) in