Entries from 2017-04-01 to 1 month
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…
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 …
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…
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…
function Convert-CodePoint { Param( [Parameter(ValueFromPipeline=$true,Mandatory=$true)] [string] $CodePoint, [Parameter(ValueFromPipeline=$false,Mandatory=$true)] $From, [Parameter(ValueFromPipeline=$false,Mandatory=$true)] $To ) begin { …
Java Patten class (regexp) supports POSIX character classes like \p{XDigit}. They are very useful when you want to check hex strings. In Java API Document, POSIX character classes say (US-ASCII only). What does it mean? https://docs.oracle…
String object in .NET (PowerShell), JavaScript, and Java all have trim() method. But trimmed characters by trim() are different between these languages. # codepoint .NET JavaScript Java 1 0000-0008 ✘ ✘ ✔ 2 0009-000D ✔ ✔ ✔ 3 000E-001F ✘ ✘ ✔…
function ConvertFrom-CodePoint { Param( [Parameter(ValueFromPipeline=$true,Mandatory=$true)] [string] $CodePoint, [Parameter(ValueFromPipeline=$false,Mandatory=$true)] $From ) begin { [System.Text.Encoding]::RegisterProvider([System.Text.C…
In PowerShell, you have to use -lt and -gt, instead of < and > in comparation, like POSIX sh. Especially if you wrongly use > like below, the comparison will be silently failed (evaluated as $false) and value of left-hand operand is wrote …
When you use -like, escape character to escape “*” depends on quotation marks. # quotation escape command Result 1 “ N/A $_ -like “*” Not escaped / Match to any strings 2 “ ` $_ -like “`*” Not escaped / Match to any strings 3 “ `` $_ -like…
Context: You can set a result of cmdlets to a variable by Set-Variable. Problem: You cannot set a result of cmdlets to a property of object by Set-Variable. PS > $foo = New-Object PSObject | Select-Object Property PS > Get-ChildItem | Set-…
In a function that retrieve parameters from pipeline, if you make a parameter mandatory (Mandatory=$true), you will get error when an empty line is passed from the pipeline. If you receive parameters from the data which may contain empty l…
## Context: A mandatory parameter of a function retrieved from pipeline is defined like this: param( [Parameter(ValueFromPipeline=$true, Mandatory=$true)] [string] $foo ) A mandatory parameter of a function retrieved from argument is defin…
ConvertTo-Csv or Export-Csv always add double quote to all columns. Get-Help Export-Csv -Full shows samples of CSV with no double quotes, but it seems there are no options to suppress double quote. This behavior doesn’t depend on system lo…
Problem: Keys of hash tables are case sensitive in most languages (Java/JavaScript/Perl/Ruby/…). But in PowerShell, key of hash table is case insensitive (if you use string as key), so you will bump into errors in code like: PS > $hash = @…
When you pass chars to Sort-Object, the chars sorted in ASCII order. PS > (0x7E..0x21 | ForEach-Object { [char]$_ } | Sort-Object) -join '' !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ But …
If you want to uniq a list in PowerShell, there is more than one way to do it and these are slightly different. # Cmdlets Sort-Object -Unique Sort-Object | Get-Unique Select-Object -Unique 1 Sort elements Yes Yes No 2 Case sensitive in ded…