Lazy Diary @ Hatena Blog

PowerShell / Java / miscellaneous things about software development, Tips & Gochas. CC BY-SA 4.0/Apache License 2.0

Entries from 2017-01-01 to 1 year

Format operator with string contains "{" and "}"

Context In PowerShell, you can format a string with -F operator like: Get-Content foo.csv | ConvertFrom-Csv -Header Name,Code,Address | ` ForEach-Object { "{0} `n {1} {2}" -F $_.Name,$_.Code,$_.Address } Problem -F operator returns error l…

私は如何にして心配するのを止めて年賀状の宛名を手書きするようになったか

ポエムです。 背景 年賀状の宛名なんて、筆まめやら何やらで印刷すればいいとも思うんですよ。特に、私はコンピュータ・ソフトウェア・エンジニアなので、自動化はまさに自分の存在意義に関わる訳です。 でも、そういう訳にもいかない事情があるわけです。主…

There are no properties for ordinary characters in PropList.txt

Problem When run the script in next URL with PropList.txt on unicode.org, result file did not contain character properties for ordinary characters like 'x', 'y', or 'z'. http://satob.hatenablog.com/entry/2017/11/21/002957 Reason PropList.t…

Get CodePoint-Property Pair from Scripts.txt on Unicode.org

Context You want to make a list of pair of unicode codepoint and its character property, like below: 00009,Cc 00020,Zs 00021,Po 00024,Sc ... Solution with PowerShell You can make the list from ftp://ftp.unicode.org/Public/UNIDATA/PropList.…

Ordinaly SELECT clause returns ORA-00904 error on Oracle in SQL Fiddle

SQL

Context The "Text to DDL" feature on SQL Fiddle generates DDL like below for Oracle 11g R2. CREATE TABLE Table1 ("value1" int) ; INSERT ALL INTO Table1 ("value1") VALUES (1) SELECT * FROM dual ; Problem This ordinal SELECT clasuse returns …

Return value of comparison operator in SELECT clause

SQL

Background Some RDBMS can contain the result of comparison operator in SELECT clause. However, the returned values are different between RDBMS. Result MySQL I used MySQL 5.6 on SQL Fiddle. DDL (MySQL) CREATE TABLE Table1 (`value1` int, `va…

Convert deeply nested hash or array to JSON with ConvertTo-Json

Context You can read a JSON file like below with ConvertFrom-Json, and write with ConvertTo-Json properly. PS > Get-Content ./foo.json { "outerHash": { "innerHash": { "key": "value" } } } PS > Get-Content ./foo.json | ConvertFrom-Json | Co…

Convert an array to CSV with PowerShell

Problem You cannot convert an array with just pipeline the array to ConvertTo-Csv. PS > $array = ("a", "b", "c", "a", "d") PS > $array | ConvertTo-Csv "Length" "1" "1" "1" "1" "1" ... or just passing the array to ConvertTo-Csv. PS > Conver…

XmlNode.SelectNodes() always returns List in PowerShell 2.0

Problem: In PowerShell, by using XML DOM API in .NET, you can access to a child element in XML as a ordinary property. PS > $xml = New-Object System.Xml.XmlDocument PS > $xml.LoadXml('<a><b id="1">foo</b></a>') PS > $xml.SelectNodes('//a').b id #text -- ----- …

How to get a #text in XML even if the tag doesn't have attributes

Background: In PowerShell (even in C# or VB.NET?), you can get a body of the tag (text content) with '#text#' property. > $xml = New-Object System.Xml.XmlDocument > $xml.LoadXml('<a><b id="1">foo</b></a>') > $xml.SelectNodes('//a').b.'#text' foo Problem: If a …

Who does recommend to encrypt the attachments in email

In Japan, so many companies have their own security policy like "When you send email with attachments, you must zip all the attachments with password, and send the password in another email". Some say this policy is pointless, but on the o…

What can you do with account lockout and its unlock

Purpose of account lockout These are some purpose for account lockout, such as: Detect login attempts 1 Example: Logging 2 Slow down login attempts Example: Duration-based lockout, scrypt, Argon2 Interrupt login attempts Example: Requires …

日本における貧困率(相対的貧困)と世界貧困線(絶対的貧困)

日本における貧困率のカウントには、相対的貧困が用いられる。日本における貧困率にカウントされるのは、2017年の国民生活基礎調査の場合、年間の等価処分所得が122万円未満の世帯。 世界における貧困率のカウントには、絶対的貧困が用いられる。世界単位で…

iOS 11ではリマインダーに保存したツイートのURLからTwitterのアプリを開けない

iOS 10.3では、リマインダーに保存したツイートのURLはTwitterのアイコンで表示される。また、TwitterのアイコンをタップするとTwitterのアプリが起動し、対応するツイートが表示される。 iOS 11.0では、リマインダーに保存したツイートのURLはアイコンなし…

A List of What Cannot JCache do

JCache cannot save the order of insertion. You should use LinkedHashMap for that purposes. JCache cannot update whole entries in a cache atomically. You should use AtomicReference or some locking mechanisms for that purpose. (Ofcourse you …

The meanings of word "cache" in software engineering

I think the word "cache" has so many different meanings in different contexts like below. Note: In this list, the word "invalidated" means the source of cached value might be changed. Something like the cache in web browsers. The cache sto…

Difference of GitHub API and GitLab API

Format of Personal Access Tokens In GitHub, personal access tokens are hex string, like e72e16c7e42f292c6912e7710c838347ae178b4a. In GitLab, personal access tokens are like Base62 string, like 9koXpg98eAheJpvBs5tK. Personal Access Tokens a…

You should disable Adblock Plus (Chrome) in Alfresco

Context: You are using Alfresco Community v5.2.0. You are using Chrome with Adblock Plus. Problem: “New Topic” button on the discussion forum disappear. Reason: Adblock Plus added “display: none” to the area that has the “New Topic” button…

Chrome sends another request for "View page source"

Context: You are developing a web application that has anti-CSRF function (transaction tokens). You are using Chrome to test and debug the application. Problem: Once you had viewed the HTML source with “View page source” on the context men…

三重は中部か近畿か、静岡は東海か関東かみたいな表

三重県のサイトに「三重県は中部地方?近畿地方?」という面白い情報があった。 同様の話は静岡県などにも言える(警察庁としては関東管区警察局の管轄区域だが、国土交通省としては中部地方整備局の管轄区域)。 他にも、Chakuwikiには「もし道州制の境界線…

How to reduce the size of monochrome almost-binary image from scanners

I scanned a B4-size monochrome paper document with Epson EP-805A through Epson iPrint iOS app, and resulted a 1.9MB jpeg file (It’s too big, isn’t it?). You can reduce the size of monochrome almost-binary image with Imagemagick convert com…

How to join nested collections with Stream API

For example, in PushOperation.java in EGit, PushOperationSpecification contains LinkedHashMap<URIish, Collection<RemoteRefUpdate>>. So you can join all remote name with Stream API like: String specs = this.specification.getURIs().stream() .map(uri -> this.specification.getRe</uriish,>…

You cannot wrap checked exceptions with lambda in Java

Context You can use lambda as lazy evaluation syntax in Java. Problem You can wrap RuntimeException with lambda like (it shows "omit exception"): import java.util.function.Supplier; public class OmitRuntimeException { public static void ma…

Run a command with specific user priviledge in Windows (like sudo in Unix)

Problem: You can use runas command to run a command with specific user privilege. (Note: You have to type password into command prompt): C:\>runas /user:domain\username cmd Enter the password for domain\username: Attempting to start cmd as…

You cannot have two forks from one repository in GitHub

Problem: “Fork” button in GitHub forks a repository into your account. You cannot rename the repository when you fork it. You cannot have two repositories with identical name. So, you cannot have two forks from one repository simultaneousl…

ISO/IEC 12207 (JIS X 0160:2012) ソフトウェア構成管理プロセスのうちバージョン管理システム、GitHub/GitLab/etc、git-flow/GitHub Flowでカバーできる内容

(In English: What can you do for ISO/IEC 12207 (JIS X 0160:2012) Software Configuration Management Process with VCSs, GitHub/GitLab/etc, and git-flow/GitHub Flow) ISO/IEC 12207 (JIS X 0160:2012)では、ソフトウェア開発におけるソフトウェア構…

Rounding strategy in Java/JavaScript/PowerShell

tl;dr Java: Floor in type casting. Round half up for Math.round(). You can choose rouding strategy for BigDecimal. JavaScript: Round half up for Math.round(). Round half away from zero for toFixed(). PowerShell (.NET CLR): Round half to ev…

PowerShell does banker's rounding in type casting to int

Problem: PowerShell rounds 0.5 to 0 (banker’s rounding) in type casting to int. PS > @(-3.5,-2.5,-1.5,-0.5,0.5,1.5,2.5,3.5) | ForEach-Object { "{0} -> {1}" -F $_, [int]$_ } -3.5 -> -4 -2.5 -> -2 -1.5 -> -2 -0.5 -> 0 0.5 -> 0 1.5 -> 2 2.5 -…

Supported character encodings in Get-Content and Import-Csv (in PowerShell 2.0/4.0)

Tested in Windows 7 (Japanese). Import-Csv does not have -Encoding option in PowerShell 2.0. There are no option for UTF-32BE in PowerShell 2.0. (note: PowerShell ISE can handle UTF-32BE Files) Import-Csv does not support Unknown and Strin…

Who does recommend changeing password periodically and who doesn't

Who recommends changeing password periodically Some say you should change password periodically. PCI DSS version 3.2 8.2.4 Change user passwords/passphrases at least once every 90 days. プライバシーマーク制度 (JIPDEC)(In Japanese) based on…