Tobira Kanji and WaniKani

December 5th, 2021
Posted in 日本語 | No Comments

Tobira Gateway to Advanced Japanese Learning through Content and Multimedia assumes 297 kanji are already learned by its potential readers. Tobira presents many words using these kanji without furigana. Learning the statistically most common kanji on- and kun-readings through WaniKani makes Tobira more accessible.

The following table shows what percentage of these prerequisite kanji are covered at particular WaniKani levels:

Level 5: 40%
Level 10: 76%
Level 15: 92%
Level 20: 97%

Only nine prerequisite kanji are introduced by WaniKani after level 20: 職違質授痛貸婚汚遅. The other 277 required kanji are covered in the first 20 levels.

The following snippet, with furigana as provided in Tobira, is extracted from page 5 of the textbook:

日本には、47の都道府県(一都、一道、二府、四十三県)があります。一都は東京都(首都しゅと)、一道は北海道、二府は大阪おおさか府と京都府で、そのほかは、静岡しずおか県や広島ひろしま県のように全部、県です。静岡県はお茶や富士山ふじさんで有名で、広島県には戦争せんそうおそろしさと平和の大切さを伝える原爆げんばくドームがあります。

Working through level 20 on WaniKani will not give language students the ability to know all vocabulary in the above text. However, they will be able to make good guesses at how to read words such as 都道府県 and use online dictionaries like Jisho. Several words with furigana included by Tobira, such as 他, 大阪, 広島, and 戦争, should be known by WaniKani users at level 20. If Tobira is a gateway to advanced Japanese, then WaniKani is a great tool to develop vocabulary and reading skills needed to pass through that gateway.

The above percentage data was derived from output of a JavaScript program, wktobira.js, which maps Tobira prerequisite kanji to WaniKani levels and is an example of using the WaniKani Web API.

JavaScript: SHA-256 Implementation

October 3rd, 2021
Posted in JavaScript | No Comments

This weekend I decided to experiment with using JavaScript to implement client-side processing of files using a web browser. To make it interesting, I wanted to see if it was possible to implement a cryptographically strong hash function: SHA-256.

This exercise gave me exposure to Web Workers and the Stream API. I encountered compatibility challenges. Google Chrome does not respond to UI updates when using setInterval() or setTimeout() while the browser is busy, but its user interface can be updated when processing messages from web workers. Mozilla Firefox does not support passing {type: ‘module’} to the Worker() constructor; ECMAScript modules are unsupported. Firefox reports a syntax error when trying to import modules from the Web Worker’s source file. This forced me to add Worker code to the source code file containing the JavaScript SHA-256 implementation.

The following checksum generator implements SHA-256 as defined by FIPS PUB 180-4. Files are not sent to the server for processing. The cost of transferring data would be too much. Files are processed locally on the web browser running on the user’s computer.

SHA-256 Checksum Generator

Input File:
Checksum:
Source Code: sha256.js, sha256main.js

Using GoDaddy API for Dynamic DNS

September 27th, 2021

It has been difficult accessing my home computer, with potentially a dynamically allocated IP address, from anywhere on the Internet after dyndns.org became a paid service. The following bash script made available by TheBelcherman on the GoDaddy Community forum simulates the functionality of dyndns.org by programmatically updating a DNS record that has GoDaddy as its authoritative nameserver:

#!/bin/bash

# This script is used to check and update your GoDaddy DNS server to the IP
# IP address of your current internet connection.
# Special thanks to mfox for his ps script
# https://github.com/markafox/GoDaddy_Powershell_DDNS
#
# First go to GoDaddy developer site to create a developer account and get
# your key and secret
#
# https://developer.godaddy.com/getstarted
# Be aware that there are 2 types of key and secret - one for the test server
# and one for the production server
# Get a key and secret for the production server
#
# Enter vaules for all variables, Latest API call requries them.

domain="mydomainname.com"                   # your domain
type="A"                                    # Record type A, CNAME, MX, etc.
name="myhostname"                           # name of record to update
ttl="600"                                   # Time to Live min value 600
port="1"                                    # Required port, Min value 1
weight="1"                                  # Required weight, Min value 1
key="ABCxyz123+qwertzxcvASDFasdfBCDEFGwysi" # key for godaddy developer API
secret="122333444455555xyz123abcqwerty"     # secret for godaddy developer API

headers="Authorization: sso-key $key:$secret"

# echo $headers

result=$(curl -s -X GET -H "$headers" \
 "https://api.godaddy.com/v1/domains/$domain/records/$type/$name")
echo $result

dnsIp=$(echo $result | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b")
echo "dnsIp:" $dnsIp

# Get public ip address there are several websites that can do this.
ret=$(curl -s GET "http://ipinfo.io/json")

# echo $ret
currentIp=$(echo $ret | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b")
echo "currentIp:" $currentIp

if [ -z $dnsIp ] || [ $dnsIp != $currentIp ];
then
  echo "IP's are not equal, updating record"
  curl \
    -X PUT "https://api.godaddy.com/v1/domains/$domain/records/$type/$name" \
    -H "accept: application/json" \
    -H "Content-Type: application/json" \
    -H "$headers" \
    -d "[ { \"data\": \"$currentIp\", " \
        + "\"port\": $port, \"priority\": 0, " \
        + "\"protocol\": \"string\", \"service\": " \
        + "\"string\", \"ttl\": $ttl } ]"
fi

if [ ! -z $dnsIp ] && [ $dnsIp = $currentIp ];
then
        echo "IP's are equal, no update required"
fi

With the above bash script saved at /usr/local/bin/updatedns, the following crontab entry is added to schedule repeated execution of the above script:
*/30 * * * * /usr/local/bin/updatedns

Now, I am able to ssh into my home computer using the following command:
$ ssh myusername@myhostname.mydomainname.com

My ssh clients are configured with my home computer’s host key signature beforehand, so that man-in-the-middle attacks can be detected.

Manipulating Raspberry Pi GPIO Ports with C#

September 18th, 2021
Posted in 日本語 | No Comments

Quarantine and working from home because of COVID-19 has provided an opportunity for me to take up Japanese again. I studied Japanese for years in high school and college, but I was unable to consume media intended for a Japanese audience. I hope that I can practice reading Kanji with posts like these.

This is the first post in which I try to translate snippets of technology articles written in Japanese. I hope that I can provide translations for longer snippets as my Japanese language skills improve. The following snippet is from Let’s Manipulate the Raspberry Pi GPIO Ports Using C# by Ken Takae:

C#とえば、Windows環境かんきょうだけとおもわれがちですが、.Net CoreをLinux環境にインストールすれば、C#で開発かいはつしたアプリケーションが動作どうさします。また、Raspberry Pi(ラズベリーパイ)でも、C#を使つかってIoT開発をおこなうことができます。

My translation:

Although when speaking of C# one tends to think about only the Windows environment, if .Net Core is installed in the Linux environment, applications developed in C# operate [in the Linux environment]. Moreover, even with a Raspberry Pi, it is possible to use C# and carry out IoT development.

Notes:
~がち: a suffix to express an undesirable tendency in someone or something. Formed by Verb-masuがちだ or Nounがちだ.

Source: C#でラズパイのGPIOを操作しよう~LEDを点灯させる
Reference: Makino, Seiichi and Michio Tsutsui. A Dictionary of Intermediate Japanese Grammar. The Japan Times, 2001, pp. 47-50.

~/.ssh/config: Preferring IPv6 SSH Connections

September 12th, 2021

I was interested in forcing ssh to use IPv6 if the connection is available. I considered writing a bash script that would test connectivity and would invoke ssh with the appropriate command line arguments. After reviewing the ssh configuration file documentation, I determined it was possible to implement what I wanted without standalone scripts.

I updated my ~/.ssh/config file with the following:

IdentityFile ~/.ssh/id_ed25519

Match host stevedoria.net, exec "nc -6z -w 2 stevedoria.net 22"
AddressFamily inet6
User myusername

Host stevedoria.net
AddressFamily inet
User myusername

The above configuration file provides an example of using the ssh_config Match keyword with the host and exec criteria keywords. The configuration file specifies an identity file to use for public key authentication. If the specified host server is “stevedoria.net” and nc is able to connect using the IPv6 address, then IPv6 is used for the SSH connection. Otherwise, if the specified host server is just “stevedoria.net”, then the IPv4 address is used.

With the ssh client configuration file above, I can then log into my web server with the following command from the command line:
$ ssh stevedoria.net

Logging into my server this way is convenient and confirms that I am IPv6-ready.