Skip to content

Instantly share code, notes, and snippets.

@saggie
saggie / How to compile C# files by PowerShell.md
Created January 1, 2017 05:22
How to compile C# files by PowerShell

Use Add-Type command:

PS C:\> Add-Type -Path .\File1.cs, .\File2.cs -ReferencedAssemblies System.Core, System.Drawing
@saggie
saggie / ColorPikcer.ps1
Last active January 3, 2017 06:57
PowerShellでスクリーン上の任意の位置のRGB値を取得する(カラーピッカー) ref: http://qiita.com/saggie/items/37c7f2e257d69f237585
Add-Type -AssemblyName System.Drawing, System.Windows.Forms
# Bitmap と Graphics オブジェクトを用意しておく (1x1 ピクセル)
$bitmap = New-Object System.Drawing.Bitmap(1, 1)
$graphics = [System.Drawing.Graphics]::FromImage($bitmap)
# 3 秒間の猶予を与える
Write-Host "Move the cursor to the targt position in 3 seconds..."
Start-Sleep 3
@saggie
saggie / Spin-Bar.ps1
Created January 3, 2017 09:47
Spinning bar animation by PowerShell. ref: http://sh-yoshida.hatenablog.com/entry/2016/04/07/191952
$bars = @('|', '/', '-')
while ($true)
{
[Console]::CursorVisible = $false
foreach ($bar in $bars)
{
[Console]::Write("Processing... {0}", $bar);
[Console]::SetCursorPosition(0, [Console]::CursorTop)
Start-Sleep -Milliseconds 150
}
@saggie
saggie / Validate-TargetFilePath.bat
Last active January 7, 2017 23:20
Validate (Test and Resolve) target file path by PowerShell and Batch
@echo off
if "%~1" == "" (echo Please specify the target file path. & pause & exit)
set PS_FILE_PATH=%~dpn0.ps1
set TARGET_FILE_PATH=%~1
PowerShell -Sta -File "%PS_FILE_PATH" -TargetFilePath "%TARGET_FILE_PATH%"
@saggie
saggie / TextLineBreaker.bat
Created January 31, 2017 05:00
Inserting line breaks into a text file.
@echo off
if "%~1" == "" echo Please specify the file path. & pause & exit
set PS_FILE_PATH=%~dpn0.ps1
set TARGET_FILE_PATH=%~1
PowerShell -Sta -File "%PS_FILE_PATH%" -TargetFilePath "%TARGET_FILE_PATH%"
@saggie
saggie / Get-EnvPath.ps1
Created February 8, 2017 00:03
Get path of environment variable for Windows by PowerShell
(Get-ChildItem Env:Path).Value.Split(';')
@saggie
saggie / Dockerfile
Created February 16, 2017 06:26
Simple SSH daemon container allowing root login with empty password.
FROM ubuntu:16.04
# Install sshd
RUN apt-get update
RUN apt-get install -y openssh-server
# Modify `sshd_config`
RUN sed -ri 's/PermitEmptyPasswords no/PermitEmptyPasswords yes/' /etc/ssh/sshd_config
RUN sed -ri 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed -ri 's/^UsePAM yes/UsePAM no/' /etc/ssh/sshd_config
@saggie
saggie / Clip-Guid.ps1
Created February 18, 2017 09:31
Clip GUID by PowerShell
[Windows.Forms.Clipboard]::SetText([Guid]::NewGuid().Guid)
dict = """
a, i, u, e, o,
ka, ki, ku, ke, ko,
sa, si, su, se, so,
ta, tsu, te, to,
na, ni, nu, ne, no,
ha, hi, hu, he, ho,
ma, mi, mu, me, mo,
ya, yu, yo,
ra, ri, ru, re, ro,
@saggie
saggie / .bat
Created February 20, 2017 20:29
Set clipboard string by Command Prompt
echo | set /p CLIP_STRING="foobar" | clip