Skip to content

Instantly share code, notes, and snippets.

@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

function LoadAssembly {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
[string[]]$asmNames,
[string]$baseDir = $PSScriptRoot
)
begin {
$domain = [System.AppDomain]::CurrentDomain
[Reflection.Assembly[]]$asms = $domain.GetAssemblies()
@ritalin
ritalin / FsFormatProto.fs
Last active August 29, 2015 14:23
Excercising F# Formatting Prototype from F# Deep Dives
type MarkdownDocument = MarkdownBlock list
and MarkdownBlock =
| Heading of int * MarkdownSpans
| Paragraph of MarkdownSpans
| CodeBlock of string list
| BlockQuote of MarkdownBlock list
and MarkdownSpans = MarkdownSpan list