Skip to content

Instantly share code, notes, and snippets.

View tackme31's full-sized avatar

tackme tackme31

View GitHub Profile
@tackme31
tackme31 / Initialize-CommerceLanguage.ps1
Last active October 26, 2020 07:59
A PowerShell script and its usage to add a new language to Sitecore Commerce. This script is tested on Sitecore Commerce 9.2.
#Requires -RunAsAdministrator
param (
[Parameter(Mandatory=$true)]
[string]
$IdentityServerHost
)
$OutputEncoding = "utf-8"
$ErrorActionPreference = "Stop"
@tackme31
tackme31 / Invoke-AsAdmin.ps1
Created October 27, 2020 09:25
A sudo-like command for PowerShell.
function Invoke-AsAdmin() {
if($args.count -eq 0){
Start-Process -Verb runas powershell
}
else {
Start-Process -Verb runas -ArgumentList @('-command', "cd $(Get-Location); $($args -join ' ')") powershell
}
}
Set-Alias -Name sudo -Value Invoke-AsAdmin -Option None
function Get-MediaContent {
param (
[Parameter(Mandatory=$true)]
[string]$Path
)
if (-not (Test-Path $Path)) {
return $null
}
using namespace Sitecore.Data
using namespace Sitecore.Data.Items
using namespace Sitecore.Globalization
using namespace Sitecore.Resources.Media
using namespace Sitecore.Sites
using namespace Sitecore.Security.Accounts
using namespace Sitecore.SecurityModel
using namespace System.IO
function Edit-Item {
@tackme31
tackme31 / Get-TypeInfo.ps1
Created February 23, 2021 11:56
A PowreShell script to get a type info by type name.
function Get-TypeInfo {
param (
[Parameter(Mandatory=$true)][string]$TypeName
)
$block = if ($TypeName.StartsWith("[") -and $TypeName.EndsWith("]")) {
[ScriptBlock]::Create($TypeName)
}
else {
[ScriptBlock]::Create("[$TypeName]")
@tackme31
tackme31 / Compare-WebResponse.ps1
Last active June 30, 2021 09:53
Compare HTML fetched by the Invoke-WebRequest command with each other.
function Get-HtmlContent($url)
{
Invoke-WebRequest $url `
| Select-Object -ExpandProperty Content `
| ForEach-Object {$_.Split([Environment]::NewLine, [StringSplitOptions]::RemoveEmptyEntries)}
}
function Compare-WebResponse($url1, $url2) {
$html1 = Get-HtmlContent $url1
$html2 = Get-HtmlContent $url2
@tackme31
tackme31 / certextension.md
Created July 12, 2021 02:27
証明書関連の拡張子メモ
拡張子 説明
.key 秘密鍵や公開鍵を含むファイル。鍵はPEMかDER形式で保存されている。.pem.derを使うこともある。
.pem PEM形式の証明書や秘密/公開鍵のファイル。
.der DER形式の証明書や秘密/公開鍵のファイル。
.csr 証明書署名要求(CSR)ファイル。公開鍵と組織情報を含む
.crt, .cer, .cert 証明書ファイル。.csrを署名したもの。.pem.derを使うこともある。
.pfx, .p12 秘密鍵 + 証明書。秘密鍵をパスワードで保護できる。Windowsでよく使われる。
.jks 秘密鍵 + 証明書。Javaで使用されるキーストアファイル。
@tackme31
tackme31 / hide-mute-texts.js
Last active August 23, 2021 00:57
A script to hide texts containing the specified MUTE keywords.
const MUTE_TEXTS = [
'FOO',
'BAR',
'BAZ',
];
const getText = (node) => [...node.childNodes]
.filter(n => n.nodeType === Node.TEXT_NODE)
.reduce((acc, n) => acc += n.nodeValue, '');
const shouldMute = (node) => MUTE_TEXTS.some(text => getText(node).includes(text));
@tackme31
tackme31 / Rename-Extension.ps1
Created November 20, 2021 10:04
PowerShell script to rename extension of files in a specified directory.
<#
.SYNOPSIS
PowerShell script to rename extension of files in a specified directory.
.EXAMPLE
PS> Rename-Extension -Path . -ExtensionFrom txt -ExtensionTo md -Recurse
.PARAMETER Path
Folder that contains the file to be renamed
@tackme31
tackme31 / nl.ps1
Created January 20, 2022 01:58
A PowerShell commandlet like bash's 'nl' command.
Function Join-LineNumbers {
[CmdletBinding()]
param(
[Parameter(Mandatory=$True,
ValueFromPipeline=$True)]
[string[]]$Lines
)
begin {
$private:i = 1