Skip to content

Instantly share code, notes, and snippets.

@ritalin
ritalin / StartPester.ps1
Last active December 11, 2018 09:01
クリーンな環境でPesterによるテスト実行 (Original: Ensuring a Clean PowerShell Session for Your Pester Tests / https://mcpmag.com/articles/2018/02/01/clean-powershell-session-for-pester.aspx )
function InvokePowerShellCommand
{
[CmdletBinding()]
param
(
[Parameter()]
[ValidateNotNullOrEmpty()]
[string]$Command
)
@ritalin
ritalin / InterfaceTestDriver.dpr
Created August 17, 2018 02:45
インターフェースの委譲のオーバーライドのテスト
program InterfaceTestDriver;
{$APPTYPE CONSOLE}
uses
SysUtils;
type
IMyIntf = interface
['{D9075E8D-417D-4358-ABA0-6688B245EF6A}']
@ritalin
ritalin / GetShelLCommand.ps1
Created July 6, 2018 04:38
explorer.exeで使用できるシェルコマンドを列挙するPowershell Cmdlet.
$categories = @(
[PSCustomObject]@{Name='Menu'; Description='メニュー関連の項目'}
[PSCustomObject]@{Name='User'; Description='ユーザーフォルダー関連の項目'}
[PSCustomObject]@{Name='Public'; Description='パブリックフォルダー関連の項目'}
[PSCustomObject]@{Name='Library'; Description='ライブラリフォルダー関連の項目'}
[PSCustomObject]@{Name='System'; Description='システム関連の項目'}
)
$menuCommands = @(
@ritalin
ritalin / check-record-oracle.sql
Created June 21, 2018 04:12
Checking whether a record is existed.
select
(case when exists (
select * from T where a = A
) then 1 else 0 end)
from dual;
@ritalin
ritalin / ConvertFromCodePoint.ps1
Last active September 28, 2017 04:35
In Delphi dfm file, strings except for ASCII chars is express with the hash(#) + codepoint. This is a Powershell Cmdlet for convering the codepoint expression string.
$re = [regex]"#(?<cp>\d+)|'(?<chars>.+?)'"
function ConvertFrom-Codepoint {
[CmdletBinding()]
param (
[string]$Source
)
$matches = $re.Matches($Source).Groups | ?{ $_.Success -and ($_.Name -in ('cp', 'chars')) }
@ritalin
ritalin / wc.ps1
Last active February 16, 2017 05:29
与えられた文字列中に含まれる単語の個数を単語ごとにカウントする for Powershell
$s = "I have a pen. I have a apple. oh!! Apple pen! I have a pen. I have a pineapple. oh!! Pineapple pen! Apple pen. Pineapplepen. Pen pineapple apple pen."
$s -split(' ') | ?{ $_ -match "(\w+)[^.!]?" } | %{ $matches[1] } | group | select -Property Name,CountName   
# Name         Count
# ----         -----
# I                4
# have             4
# a                4
# pen              7
# apple            4
@ritalin
ritalin / ExcelBoulerplate.ps1
Last active November 18, 2016 06:42
A function boilerplate for Excel processing by powershell.
function BoilerplateFunction {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
[IO.FileInfo[]]$files
)
begin {
$xls = New-Object -ComObject Excel.Application
$xls.Visible = $false
$xls.DisplayAlerts = $false
@ritalin
ritalin / InvokeDcc-D7.ps1
Last active June 9, 2017 07:33
Commandline build script for delphi7
$root = "HKCU:\Software\Borland\Delphi\7.0"
$rootDir = (ls $root\.. -Include "7.0" -Recurse).GetValue("RootDir")
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
function Update-DccLib {
$reg = ls $root -Include "Environment Variables" -Recurse | select -First 1
$envVars = @{ '$(DELPHI)' = $rootDir }
$reg.Property | %{ $envVars.Add([string]::Format('$({0})',$_), $reg.Getvalue($_)) }
@ritalin
ritalin / StartProcessEx.Example.ps1
Last active March 10, 2016 08:11
Extended Start-Process Cmdlet
New-Process (Resolve-Path .\usr\bin\influxd.exe) "-config $(Resolve-Path .\etc\influxdb\influxdb.conf)" |
Enable-TextLog -RedirectStandardError access_log -Verbose |
Launch-Process
New-Process (Resolve-Path .\usr\bin\influxd.exe) "-config $(Resolve-Path .\etc\influxdb\influxdb.conf)" |
Enable-EventLog -RedirectStandardError Access -Verbose |
Launch-Process
@ritalin
ritalin / http_api.md
Created March 7, 2016 05:04
InfluxdbのHTTP APIをPoweshellから叩く例

Enter file contents here## create database

@{ q = "create database mydb" } | Invoke-WebRequest -Method Get -Uri "http://localhost:8086/query"

write data

write single data