All posts by Pistolfly

Software Engineer in Tokyo, Japan

Change file timestamp on Windows

Run Set-ItemProperty with PowerShell.

Change last modified datetime

> Set-ItemProperty "<PATH TO FILE>" -Name LastWriteTime -Value "<DATETIME STRING>"

Change creation datetime

> Set-ItemProperty "<PATH TO FILE>" -Name CreationTime -Value "<DATETIME STRING>"

It seems to be good that the DATETIME STRING format specified for -Value is a standard date and time string that can be parsed with .NET, such as "2018/06/01 12:27:59".

Display the character code of the character at the cursor position on Emacs

C-x = (M-x what-cursor-position)

The code point in Unicode of the character at the cursor position is displayed in the minibuffer.
For example, if you place the cursor on the letter "あ" in the file of Shift_JIS and press 'C-x =', the following is displayed in the minibuffer.

Char: あ (12354, #o30102, #x3042, file ...) point=1 of 2 (0%) column=0

`12354, #o30102, #x3042` are decimal, octal, hexadecimal notation of the code point in Unicode of "あ".

C-u C-x = (M-x describe-char)

Display detailed information of the character at the cursor position in the split window.
For example, place the cursor on the letter "あ" in the file of Shift_JIS and press 'C-u C-x =', then the following is displayed in the split window.

             position: 1 of 2 (0%), column: 0
            character: あ (displayed as あ) (codepoint 12354, #o30102, #x3042)
    preferred charset: japanese-jisx0208 (JISX0208.1983/1990 Japanese Kanji: ISO-IR-87)
code point in charset: 0x2422
               script: kana
               syntax: w  which means: word
             category: .:Base, H:2-byte Hiragana, L:Left-to-right (strong), c:Chinese, h:Korean, j:
Japanese, |:line breakable
             to input: type "C-x 8 RET 3042" or "C-x 8 RET HIRAGANA LETTER A"
          buffer code: #xE3 #x81 #x82
            file code: #x82 #xA0 (encoded by coding system japanese-shift-jis-dos)
              display: terminal code #xE3 #x81 #x82

`code point in charset: 0x2422` represents the code point of "あ" in character set JIS X 0208,
`buffer code: #xE3 #x81 #x82` represents the encoding in the buffer (UTF-8),
`file code: #x82 #xA0` represents the encoding in the file (Shift_JIS).

Installing Ruby-2.5.0 on CentOS6

Attempting to install Ruby-2.5.0 from the source on CentOS6 causes an error in `make` and it can not be installed.
It is an error because gcc on CentOS6 is old.

$ ./configure --prefix=/opt/ruby-2.5.0 --disable-install-doc
$ make
...(略)
prelude.c: In function ‘prelude_eval’:
prelude.c:204: error: #pragma GCC diagnostic not allowed inside functions
prelude.c:205: error: #pragma GCC diagnostic not allowed inside functions
prelude.c:221: error: #pragma GCC diagnostic not allowed inside functions
トップレベル:
cc1: 警告: unrecognized command line option "-Wno-self-assign"
cc1: 警告: unrecognized command line option "-Wno-constant-logical-operand"
cc1: 警告: unrecognized command line option "-Wno-parentheses-equality"
cc1: 警告: unrecognized command line option "-Wno-tautological-compare"
make: *** [prelude.o] エラー 1

Bug #14234: Failed to build on CentOS 6.9 - Ruby trunk - Ruby Issue Tracking System

It will be fixed on the next release (Ruby-2.5.1), but you can install Ruby-2.5.0 using scl's devtoolset for the time being.

Installing scl devtoolset on CentOS6

Create under /etc/profile.d with the following content(example for devtoolset-4 collection)and enable scl's devtoolset for users after reboot. So you can install Passenger by `passenger-install-apache2-module` or install gems which need native build with Capistrano.

$ cat /etc/profile.d/enabledevtoolset-4.sh
#!/bin/bash
source scl_source enable devtoolset-4

Show logs on macOS(10.12 Sierra or later)

Overview

Use `log`.

Streaming (like tail command)

`log stream`

Find from past log

`log show`

See `man log` for detail.

Example

cron

$ log stream --info --predicate 'process == "cron"'
$ log show --info --predicate 'process == "cron"' --start '2017-05-25'

postfix

$ log stream --info --predicate '(process == "smtp") || (process == "smtpd")'
$ log show --info --predicate '(process == "smtp") || (process == "smtpd")' --start '2017-05-25'

If you doesn't know process name to specify

$ log show --info --start '2017-11-08' | grep 'xxx'

and guess process name.

Restart services installed with MacPorts

You can restart services installed with MacPorts using `port reload <portname>`.

$ port help load
...
If you want to restart a daemon, you can use port reload, which is a convenience wrapper around port unload followed by a short delay and port load.
...

Example

Apache

$ sudo port reload apache2

MySQL

$ sudo port reload mysql56-server

Certificate without subjectAltName causes NET::ERR_CERT_COMMON_NAME_INVALID error on Chrome

When I visited a site that uses a self-signed SSL certificate for development environment with Chrome, "Your connection is not private. NET::ERR_CERT_COMMON_NAME_INVALID" error occurred.

Although I use a self-signed certificate, I installed it for the clients and trusted it. (Keychain Access on Mac and Certificate Manager on Windows.)
The CN(Common Name) also matches the host name being accessed.

There is no problem with browsers other than Chrome.
Even Chrome could access without problems, but suddenly it got an error.

There is "[missing_subjectAltName]" in the error, so I thought the certificate without subjectAltName caused the error.

Cause

For Chrome 58 and later, only the subjectAlternativeName extension, not commonName, is used to match the domain name and site certificate.

https://support.google.com/chrome/a/answer/7391219?hl=en

Workaround

Create self-signed certificate with subjectAltName extension

Copy openssl.cnf and set subjectAltName, use it on creating certificate.

  1. Copy openssl.cnf(Below is example on Red Hat family. Change the path to openssl.cnf for other platforms.)
    $ cp /etc/pki/tls/openssl.cnf my-server.example.com.cnf
    
  2. x509_extensions in [ req ] section is v3_ca. So it seems I should add subjectAltName in [ v3_ca ] section.
    $ vi my-server.example.com.cnf
    
    [ req ]
    ...
    x509_extensions = v3_ca # The extentions to add to the self signed cert
    ...
    

    Add subjectAltName in [ v3_ca ] section.

    [ v3_ca ]
    ...
    subjectAltName=DNS.1:my-server.example.com
    ...
    

    You can also set multiple subjectAltNames.

    subjectAltName=DNS.1:my-server.example.com,DNS.2:my-server2.example.com
    

    See `man 5 x509v3_config` for detail.

  3. Create private key
    $ openssl genrsa -out my-server.example.com.key 2048
    
  4. Create certificate(Specify your cnf file for the -config option
    $ openssl req -new -x509 -days 36500 -sha256 -config my-server.example.com.cnf -key my-server.example.com.key -out my-server.example.com.crt