現役のプログラマーが書くプログラミング情報

Technical News, Documents and Tips From Software Engineer

  • 2020-03-11

Docker: Check the Privacy Configuration if you use Docker on macOS Catalina 10.15

The Docker can mount the folder in host OS to share with container. This article says check points if this function doesn’t work fine. The running environment of this article is macOS Catalina 10.15. When the host OS is macOS, the privacy settings also needed to be checked. Situation I have been using the web server which is running on the docker container to develop. The content files are in the folder which is shared with the container, because I want to edit them quickly. The configuration file of the Docker Composer is following: I ran this container and access it, but the web browser said 404 Not Found error. When I move the folder contains files including docker-compose.yml to another location, the container works fine. What You Should Check This is a checklist for this situation. Is /usr/share/nginx/html exists? Can you see the contents of /usr/share/nginx/html ? Is ./content_home exists in host OS? Does docker has rights such as permission to the ./content_home in host OS? Check the Container Check the /usr/share/nginx/html in the container. The html is output so the html is exists. Next, check the contents. I couldn’t access to the contents of the folder, it seems that the docker doesn’t have the permission to […]

  • 2020-03-10

Python: Output the log with logging module

It is general to export the log from the batch script which is executed periodically. The log is also useful to analyze the problem. You may insert the special log for debug to explore the reason of bug. The log is base facility to explore the reason of problem and recover from it. You can output the log from Python script with logging module. Simple Logging Most simple logging code is following. Execute this script, the following log will be output. How to output the log You can output the log by following functions. You need to select the function for appropriated logging level. info() warning() error() critical() exception() debug() The argument of these functions is a formatted string. The Logging Levels The importance of each logs are different. The logging level is an importance. For example, in production environment, the log is not needed which is output by debug() function. However, in development environment, it is an important for the developer. The output logging level can be specified with the code. Change the output logging level The minimum output logging level is changed with level argument of the basicConfig() method. In this sample code, the logging level of the output is […]

  • 2020-03-08

Python: Get the Command Line Argument with ArgumentParser

It is easy to get the command line argument of python shell script with ArgumentParser class. The ArgumentParser class has following functions: Get the positional required argument Get the optional argument Output the help If the script executed without required arguments, the ArgumentParser class abort the script. It is hard work to write above functions by yourself in your own script. Basic usage The basic code to use `ArgumentParser` class is following: Write your program description You can set the description of your program with the description parameter of the initializer. The description is displayed by --help option. Descriptions of programs and arguments can be omitted. However, we recommend that you do not omit it. Immediately after implementing the code, you know for yourself what the program is. However, after a while you may forget. In addition, if you take over and explain when another person is in charge or when someone uses it, you only need to hand it over. Parse and Get the Required Argument Use add_argument() method to parse and get the required argument. This code add the value argument. You can set the description of the argument to the help parameter. You can omit it. The passed value can be get with […]

  • 2020-03-08
  • 2020-03-27

2020/03/27 Update: Requirements to Release On App Store Since April 30, 2020

Deadline for existing app updates has been extended to June 30, 2020. The article posted on March 30, 2020. Apple Developer News and Updates sites says that following two things will be required to release your apps on the App Store since April 30, 2020. Build with iOS 13 SDK or later Create the launch screen with a storyboard iPhone Apps support all size of iPhones On Apple Developer News and Updates, two articles has been post. These articles say same things. The difference is whether they are writing about iOS 13 or iPadOS. The required changes are the same for both operating systems. Build your app with iOS 13 SDK or later iOS 13 SDK is contained in Xcode 11. You need to build your app with Xcode 11 or later since April 30, 2020. If you want to see which version of SDK that Xcode has, see next article. If you write all code of your app by yourself, there is a no problem. If your app has third party SDK, and they are linked with old SDK, the App Store will not accept your app. You can use otool to check the SDK which is linked by […]

  • 2020-03-04
  • 2020-03-04

How to create the disk image file which is able to mount on APFS unsupported OS

The default file system of the macOS is changed to APFS since macOS High Sierra 10.13. The file system of the disk image file which is created by the Disk Utility had been changed to APFS also. They are not able to mount on earlier OS than macOS 10.13 which not supports APFS. This article how to create the disk image file with specify the file system. Creating the disk image file To create the disk image file, you can following way: Use the Disk Utility Use the hdiutil To specify the file system, use hdiutil to create the disk image file. Creating the disk image file with hdiutil To create the disk image file with hdiutil, enter the following line in the Terminal. The first argument is an action. The create specify create the disk image file. The -srcfolder option specify the source folder which contains files and folders are copied into the disk image. Above example specify the Test folder in the current directory. The -fs option specify the file system. The HFS+ is a default system which had been used until macOS 10.12. The last argument is a disk image file. Above example creates the Test.dmg file. The file system you […]

  • 2020-03-03
  • 2020-03-03

How to create the zip same as Finder creates, from the terminal or the shell script

Finder has a function create the zip file from the file or the folder. This zip file is different from the zip file Windows creates. This article says this zip file as Finder style zip file. You can create this zip file from the terminal and the shell script. You can create it in the automated script. This article explains that how to create the Finder style zip file and how to expand it. Creating the Finder style zip file You can create the Finder style zip file with ditto. Above line create the Test.zip file by archiving the Test folder. -c option specify creates the archive, -k option specify compress with PKZip, --sequesterRsrc option create the __MACOSX folder to store the resource fork and the HFS meta data. Specify only one file If you create the zip file with only one file, --keepParent option may be an obstacle. For example, following line create the zip file by archiving the 123.jpg file in the desktop. Expand it, the Desktop folder will be created and the 123.jpg file is put in the created folder. Redundant folder will be created. --keepParent option put the Desktop folder which is a parent folder of the […]

  • 2020-03-01
  • 2020-03-01

How to Localize the site title and catch phrase with THE THOR WP Theme and the Bogo plugin

This blog have been using the wordpress theme “THE THOR”. The other language version is also created and to localize with plugin “Bogo”. The Bogo has a function to replace text but the site title and the catch phrase couldn’t replace, so they had been exported in Japanese because the main language of this blog is Japanese. I want to replace them too so I had edit the functions.php of the child theme. At last, the site title and the catch phrase now to be localized. This article explains that how to do it. The way in this article, edit the file of the child theme. Please backup the file before edit them. Generating the site title string THE THOR implements the hook function of the pre_get_document_title to generate the site title string. I found the fit_title_document() function in the the-thor/inc/seo/title.php file. Override this function. Override the hook function in the child theme It is dangerous that you edit the file in the parent theme, so implement the hook function in the child theme. Edit the the-thor-child/functions.php file. Generating the site title tag string Add the following code into the the-thor-child/functions.php file. function localize_title() { ob_start(); bloginfo('name'); $localizedName = ob_get_clean(); […]

  • 2020-02-28
  • 2020-02-28

How To Support Notarization Services For Installer

If the application is packaged into the installer package and it is deployed, the installer package also need to support the Notarization Services. This article explains that how to support Notarization Services for the installer. Overview of How to make the installer The installer of macOS is created with following 2 steps. Create the component package with pkgbuild. Create the deployment installer with productbuild. If the deployment file is disk image format, the step to create the dmg file with hdiutils will be followed. And you will upload it to the Apple Notarization Services. Prerequirements of the Notarization In prerequirements of the notarization, following things are related to the installer. Code-sign with the Developer ID Application Certificate or the Developer ID Installer Certificate. Contains the secure-timestamp. I have used Developer ID Installer Certificate. I don’t know the Developer ID Application can be used. The Component Package and The Deployment Installer The deployment installer consists with some of component packages. The component package is created per selection of the custom install. The custom install is a function that the user can select to install or skip. If the installer only have express install and doesn’t have a custom install, required component […]

  • 2020-02-25
  • 2020-02-28

Introduction to Combine | How to connect to the Web Server with the Combine

This article explains that how to connect to the web server with the Combine. Create the Publisher of the DataTask Create the publisher of the data task to connect to the web server. Two methods are available to create it: The first method has an argument “URL”. If you want to simply connect to the URL and GET the contents, you can use this method. The second method has an argument “URLRequest”. With “URLRequest”, you can set the method of the HTTP, the body data, the header value and so on. You can handle most cases, but if wan to download the large file, you should use the download task of URLSession directly. Receiving Result To receive the result, use sink method. Returned value need to be keep in anywhere. You can write the code in following form: Keep in mind the thread Closures are executed on the sub-thread. Updating the GUI need to be executed on the main thread only. Sample Code Following code is a sample code. Enter the URL and tap the “GET” button, the application get the content from the URL with Combine. This code uses SwiftUI, you can copy & paste to the ContentView.swift and […]

  • 2020-02-24
  • 2020-02-28

Introduction to Combine | How to support Combine in a custom class

Combine is a framework to implement asynchronous operations. It is created by Apple, it is also used in Swift Data Binding. It is an important framework. If you new to Combine, see next article. If you want other samples, see following articles. This article explains how to support Combine in a custom class. Adopt to ObservableObject protocol. To make a class to support Combine, adopt to ObservableObject protocol. To notify a changes of properties with Combine, mark the property with @Published attribute. @Published The property which is marked with @Published attribute, can make the Publisher. Use $ operator to make the Publisher. Receive changes of properties of a custom class Use sink() to receive changes. The value of the property is not changed at the block is executing, so the value of the property is an old value yet. You should use a block argument “value”. Sample Application I made a sample application. “Hit” button decrement HP and “Heal” button recover it. I think this code will make you understand an effect of the ObservableObject.

RANKING ランキングトップ10

>現役のプログラマーが書くプログラミング情報

現役のプログラマーが書くプログラミング情報

日々の開発の中での学びや分かったこと、調べたことなどを書いていくブログです。

CTR IMG