Skip to content

Instantly share code, notes, and snippets.

View raspi's full-sized avatar

raspi

  • finland
  • 20:18 (UTC +03:00)
View GitHub Profile
#!/bin/bash
find . -maxdepth 1 -type f -iname "*.pdf" -exec gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dDownsampleColorImages=true -dColorImageResolution=150 -dNOPAUSE -dBATCH -sOutputFile={}.new.pdf {} \;
@raspi
raspi / smb.conf.ini
Last active March 12, 2021 16:24
FreeBSD ZFS Samba 4 config with recycle and read/write optimizations example
# Samba 4 config example
# Connected to existing remote Samba 4 Active Directory Directory Controller
# ZFS pool @ /storage
# Network is 192.168.101.0/24
# Samba is installed with:
# pkg install samba42
# and then joined to existing AD with:
# samba-tool domain join <params>
# After this /usr/local/etc/smb4.conf is edited and restarted with /usr/local/etc/rc.d/samba_server restart
@raspi
raspi / mac_list_vendors.sh
Created March 16, 2021 22:18
Get vendors from `/proc/net/arp` with systemd's OUI vendor database
#!/bin/bash
# Get vendors from /proc/net/arp with systemd's OUI vendor database
set -eu
set -o pipefail
OUIDB=/usr/lib/udev/hwdb.d/20-OUI.hwdb
while IFS=$' ' read -r ipaddr htype flags mac mask iface;
do
var nativeEndian binary.ByteOrder
func init() {
buf := [2]byte{}
*(*uint16)(unsafe.Pointer(&buf[0])) = uint16(0xABCD)
switch buf {
case [2]byte{0xCD, 0xAB}:
nativeEndian = binary.LittleEndian
case [2]byte{0xAB, 0xCD}:
@raspi
raspi / ffmpeg-cut.sh
Last active March 24, 2021 13:52
Cut a part of a video with FFMPEG
#!/bin/bash
# Cut a part of a video with FFMPEG
if [[ $# -eq 0 ]] ; then
echo "Usage:"
echo " $0 <filename> <start position timestamp> <duration> [additional params]"
echo ""
echo "Example:"
echo " Cut 50 seconds starting from timestamp 01:23:45 from file myvid.mp4"
@raspi
raspi / ffmpeg-crop.sh
Last active March 24, 2021 13:52
Crop video with FFMPEG
#!/bin/bash
# Crop a part of a video with FFMPEG
if [[ $# -eq 0 ]] ; then
echo "Usage:"
echo " $0 <filename> <left> <right> <top> <bottom>"
echo ""
echo "Example:"
echo " $0 myvid.mp4 700 600 200 400"
@raspi
raspi / censor.sh
Created March 27, 2021 01:20
Censor MAC address, IPv4 address from some output
# mac:
echo "..." | perl -pe 's@[\da-f:]{17}@xx:xx:xx:xx:xx:xx@ig'
# IPv4
echo "..." | perl -pe 's@[\d\.]{7,15}@X.X.X.X@ig'
$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
# Fetch system specific information
# -- Get Operating system name such as "Win 10 Pro"
$replaceTable = @{
"Microsoft" = ""
"Windows" = "Win"
"Professional" = "Pro"
"Ultimate" = "Ult"
"Enterprise" = "Ent"
"Edition" = "Ed"
$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