Skip to content

Instantly share code, notes, and snippets.

@saggie
saggie / Get-ProcessList.ps1
Last active December 10, 2016 04:24
Get list of all current "titled" processes running in Windows by using PowerShell
function Get-ProcessList()
{
$ret = @()
function Simplify-ProcessInformation ([System.Diagnostics.Process]$process)
{
$ret = @{}
$ret["Id"] = $process.Id;
$ret["ProcessName"] = $process.ProcessName;
$ret["MainWindowTitle"] = $process.MainWindowTitle
@saggie
saggie / Wait-AnyKeyPressed.ps1
Last active December 21, 2016 10:56
"Press any key to continue ..." in PowerShell
Write-Host "Press any key to continue ..." -NoNewLine
[Console]::ReadKey() | Out-Null
[string]::Empty
@saggie
saggie / ActiveWindowRectGetter.cs
Last active December 17, 2016 00:47
Get active (foreground) window's position and size
using System;
using System.Runtime.InteropServices;
public class ActiveWindowRectGetter
{
[DllImport("user32.all")]
public static extern bool GetWindowRect(IntPtr hWnd, out WindowRectRaw lpRect);
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
@saggie
saggie / Wait-Noodles.ps1
Last active December 21, 2016 15:22
Wait for instant noodles get done
param([int]$Minutes = 3)
$appName = "Wait-Noodles"
# create a task tray icon
Add-Type -AssemblyName System.Windows.Forms
$notifyIcon = New-Object System.Windows.Forms.NotifyIcon
# get an icon image from powershell.exe
$psExeFilePath = Join-Path $Script:PSHOME "powershell.exe"
@saggie
saggie / Update-PasswordAsIs.ps1
Last active December 21, 2016 13:12
Change password as is (for WinNT)
param([string]$UserName = "__your_username__",
[string]$Password = "__your_password__")
$computerName = hostname
$user = [ADSI]"WinNT://$computerName/$UserName,User"
$user.ChangePassword($Password, $Password)
@saggie
saggie / とある日のコード改善メモ.md
Last active December 23, 2016 03:04
とある日のコード改善メモ(共通処理のくくり出し)

状況の解説

以下のようなユーザからの入力 (JSON payload) があったとき...

{
  "parameterA": "Enable",
  "parameterB": "Disable",
  ...
}
@saggie
saggie / app.js
Last active December 23, 2016 16:53
An example of a simple web server using Node and Express
var http = require('http');
var express = require('express');
var routes = require('./routes');
var app = express();
var server = http.createServer(app);
app.configure(function() {
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.static(__dirname + '/public'));
@saggie
saggie / Replace-SlashAndBackslash.ps1
Last active August 3, 2022 20:26
Replacing slash and backslash in the clipboard by PowerShell. ref: http://qiita.com/saggie/items/ed7ad06d2e4e1ede676d
Add-Type -AssemblyName System.Windows.Forms
$clipText = [Windows.Forms.Clipboard]::GetText()
if ($clipText.Contains('/'))
{
$replacedClipText = $clipText -replace '/', '\'
[Windows.Forms.Clipboard]::SetText($replacedClipText)
}
elseif ($clipText.Contains('\'))
{
$replacedClipText = $clipText -replace '\\', '/'
@saggie
saggie / ClipboardObserver.ps1
Last active December 28, 2016 11:14
Observing the clipboard and logging its history by PowerShell. ref: http://qiita.com/saggie/items/481461a436a1d6801bbd
# set window title
(Get-Host).UI.RawUI.WindowTitle = $MyInvocation.MyCommand
# get text from the clipboard
Add-Type -AssemblyName System.Windows.Forms
$clipText = [Windows.Forms.Clipboard]::GetText()
Write-Host $clipText
while ($true)
@saggie
saggie / ConvertTo-Grayscale.ps1
Last active January 1, 2017 09:36
PowerShell と C# で画像処理(ピクセル操作) ref: http://qiita.com/saggie/items/2cc1cc89830c1184ab75
param(
[Parameter(Mandatory = $true)]
[string]
$SourceImageFilePath
)
# 画像ファイルのパスを解決
$resolvedFilePath = Resolve-Path $SourceImageFilePath
# 画像の情報を取得