Lazy Diary @ Hatena Blog

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

情報システムの受託開発中に発見されたバグの情報の行方

情報システムの受託開発で、OSSに依存するアプリを開発したとしよう。さらに、そのアプリの開発中に、当該OSSのバグを見つけたとしよう。この場合、条件によっては、発見者はパッチの投稿も、バグの報告もできず、そのバグの情報は永遠にお蔵入りになるので…

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…

How to convert from ADIF AAC to another format (ffmpeg and libav can't handle it)

Context: You have some AAC ADIF files and you want to convert them into MP3 (and the like) format. Problem: ffmpeg and libav don’t (and will never) support ADIF AAC files because it is “bad format”. see: https://lists.libav.org/pipermail/f…

You should not pass the result of Get-ChildItem into Get-Content (and the like) directly

Context: You can pass the result of Get-ChildItem into Get-Content directly: PS /home/satob/tmp> Get-ChildItem | Where-Object { $_.Name -like "*.csv" } | ForEach-Object { Get-Content $_ } "a","x" "b","2" ... Problem: You cannot pass the re…

You cannot use -Encoding option with Import-Csv in PowerShell 2.0

Context: You use PowerShell 2.0 (Windows 7 or Windows Server 2008 R2). You want to read CSV file that contain non-ASCII characters. Problem: In PowerShell 2.0, Import-Csv cmdlet doesn’t have -Encoding option. Solution: If you want to read …

Difference of acceptable parameters for -Encoding option

Acceptable parameters for -Encoding option are different for Get-Content, Set-Content, Export-Csv, Import-Csv, and Out-File. # cmdlet Default ASCII UTF-7 UTF-8 UTF-16LE UTF-16BE UTF-32LE UTF-32BE Byte Default OEM String Unknown 1 Get-Conte…

Functional limitation of The Nu Html Checker (v.Nu)

Problem: The Nu Html Checker (v.Nu) is useful HTML validator. It can be used not only from a web browser, but also from command line. But, this validator has some functional limitations (for both web interface and CLI version). v.Nu cannot…

How to write result of ConvertTo-Csv to a file in UTF-8 without BOM

Context: You want to write the result of ConvertTo-Csv in UTF-8 encoding without BOM. e.g. You need a file that can be read by a Java program (Java File API cannot handle BOM in UTF-8 encoded files). UTF-8 in PowerShell, e.g. ConvertTo-Csv…

.NET cannot distinguish Shift_JIS from MS932(Windows-31J)

Context: Japanese character encoding Shift_JIS (シフトJIS) and Microsoft Codepage 932 (a.k.a. MS932, Windows-31J in IANA) are slightly different. For example, full-width cent sign (¢) is 0x8191 in both Shift_JIS and MS932, but it is mappe…

PowerShellで法務省 戸籍統一文字情報のページからあるコードポイントの文字の情報を取得する

(In English: How to get information about a Japanese character from 戸籍統一文字情報 site (managed by The Ministry of Justice (Japan)) with PowerShell) 問題: ある漢字に関する情報(読みや、子の名に使える文字か等)を調べたければ、法務省の戸…

ConvertFrom-String is not available on PowerShell Core Edition

Problem: ConvertFrom-String is not available on PowerShell Core Edition. Reason: It seems by design. According to the source of PowerShell on GitHub, ConvertFrom-String is exported for Desktop Edition, but not exported for Core Edition for…

CharsetEncoder#canEncode() equivalent for PowerShell

Context: You want to test whether a codepoint is valid in a specific character encoding. Problem In .NET, there are no equivalent functions to CharsetEncoder#canEncode() in Java. Solution If you want to test whether a character is valid in…

Meanings of :owner, :repo, ... in GitHub API document

In GitHub API document (ex. https://developer.github.com/v3/repos/ ), examples of how to access API showed like GET /repos/:owner/:repo/contributors. Meanings of indicator variable-like valiables such as :owner, :repo are listed below: # v…

How to convert string to number with AngularJS

There is more than one way to convert string to number in JavaScript. Context: Use AngularJS to bind text boxes to variables. Sum up input values in some text boxes. Omit ng-required, ng-pattern, ng-minlength, ng-maxlength, etc., wherever …

URL of GitHub Enterprise API is different from github.com's one

Problem: I have tried to access GitHub Enterprise API with a URL like showed below, based on examples from some websites, but the response was 404 error. https://x.x.x.x/repos/Project/Repository/git/refs/heads Reason: URL of GitHub Enterpr…

System.Text.Encoding.GetEncodings() does not show all available encodings after call RegisterProvider()

Problem: If you want to use character encodings other than the default registered encodings, you have to call [System.Text.Encoding]::RegisterProvider([System.Text.CodePagesEncodingProvider]::Instance). But even if you call that method, th…

How to convert from a code point (U+xxxx) to a code point in another character encoding

function Convert-CodePoint { Param( [Parameter(ValueFromPipeline=$true,Mandatory=$true)] [string] $CodePoint, [Parameter(ValueFromPipeline=$false,Mandatory=$true)] $From, [Parameter(ValueFromPipeline=$false,Mandatory=$true)] $To ) begin { …