Instantly share code, notes, and snippets.

View list_established_ports.ps1
# List established IPs and ports with DNS resolved names and program names
$nfo = @()
ForEach ($c in Get-NetTCPConnection -State Established) {
if ($c.LocalAddress -eq $c.RemoteAddress) {
# skip same IP's
Continue
}
$prog = (Get-Process -Id $c.OwningProcess)
View esxi_lldp_control.sh
#!/bin/sh
# Enable/Disable LLDP on vSwitch ports on VMWare ESXi
# Tested with ESXi 6.0.0 3620759
# Doesn't need vCenter, only SSH access to the ESXi machine
# (c) Pekka "raspi" Jarvinen 2016 http://raspi.fi/
SWITCH=$1
OPERATION=$2
if [ "$SWITCH" = "" ] || [ "$OPERATION" = "" ]; then
View gettext_update.sh
#!/bin/bash -e
# generate file list
echo -e "" > files.txt
find ../application -type f \( -iname "*.php" -or -iname "*.phtml" \) -exec readlink -f "{}" \; > files.txt
# scan files
xgettext --force-po --add-comments --from-code=UTF-8 --language=php --package-name=app --package-version=1.0 --msgid-bugs-address=noreply@example.com -o base.pot -f files.txt
# base pot -> <lang>.po update
View list_user_directories.ps1
$items = Get-ItemProperty -Path 'Registry::HKey_Local_Machine\Software\Microsoft\Windows NT\CurrentVersion\ProfileList\*'
Foreach ($item in $items) {
$objUser = New-Object System.Security.Principal.SecurityIdentifier($item.PSChildName)
$objName = $objUser.Translate([System.Security.Principal.NTAccount])
$item.PSChildName = $objName.value
}
Write-Output $items | Select-Object -Property PSChildName, ProfileImagePath
View own_path.ps1
takeown /f "$path"
icacls "$file" /grant administrators:F
View dir_match_move.py
#!/bin/env/python
# -*- encoding: utf8 -*-
#
# Move files based on directory match list
#
# Example:
# /sorted directory has following directories:
# - foo
# - bar
#
View md5move.py
#!/bin/env/python
# -*- encoding: utf8 -*-
# Move files based on file list in a md5 checksum file
# (c) Pekka Järvinen 2017-
import logging
log = logging.getLogger(__name__)
import os
View freebsd_dump_sysctl.sh
#!/bin/sh
# Function for printing
p()
{
KEY=$1
TYPE=$2
DESCR=$3
# last character is '.'
View freebsd_sysctl.md

Settable via /etc/sysctl.conf:

integer kern.maxvnodes

Target for maximum number of vnodes

integer kern.maxfiles

Maximum number of files

integer kern.securelevel

Current secure level

View Microsoft.PowerShell_profile.ps1
$Shell=$Host.UI.RawUI
$size=$Shell.WindowSize
$size.width=120
$size.height=35
$Shell.WindowSize=$size
# buffer
$size = $Shell.BufferSize
$size.width=[system.console]::BufferWidth