Skip to content

Instantly share code, notes, and snippets.

View mavaddat's full-sized avatar
🏠
Working from home

Mavaddat Javid mavaddat

🏠
Working from home
View GitHub Profile
@mavaddat
mavaddat / Backup_cpanel.sh
Created September 29, 2017 06:05 — forked from osrecio/Backup_cpanel.sh
Get Backup Cpanel ( Files & DB's )
#!/bin/bash
LOG="/path_to_save_logs"
echo "Start backup web `date`" >> $LOG
cd /folder_to_save
FECHAF=`date +%Y.%m.%d`
mkdir $FECHAF
cd $FECHAF
FECHA=`date +%-m-%-d-%Y`
@mavaddat
mavaddat / DrizinEMLimport.vba
Last active March 31, 2023 13:13
Drizin's EML importer for Outlook Desktop
'----------------------------------------------------
' Code by Ricardo Drizin (contact info at http://www.drizin.com.br) @Drizin
'----------------------------------------------------
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Option Explicit
'---------------------------------------------------------------------
' This method closes ActiveInspectors if any.
' All importing is based on the assumption that the EML
' is opened by shell and we can refer to it through the ActiveInspector
@mavaddat
mavaddat / fixphotoshopmem.ps1
Last active June 20, 2020 20:00
Powershell script to fix Adobe Photoshop CC memory issue #2416657
# Get the ID and security principal of the current user account
$myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent()
$myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)
# Get the security principal for the Administrator role
$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator
# Check to see if we are currently running "as Administrator"
if ($myWindowsPrincipal.IsInRole($adminRole))
#Requires -RunAsAdministrator
Stop-Service -Name @("bits","wuauserv","appidsvc","cryptsvc")
del "$env:ALLUSERSPROFILE\Application Data\Microsoft\Network\Downloader\qmgr*.*"
if(Test-Path variable:global:errs) {Remove-Variable -Name @("errs") -ErrorAction SilentlyContinue } #$err = $null
$errs = [System.Collections.ArrayList](@{})
function Start-Backup {
param([string[]]$paths = @("$env:SystemRoot\system32\catroot2","$env:SystemRoot\SoftwareDistribution"))
foreach($path in $paths){
$bak = "$($path).bak"
if((Test-Path -PathType Any $bak) -and (Test-Path -PathType Any $path)){
@mavaddat
mavaddat / copyHashes.ps1
Last active December 1, 2022 22:06
A PowerShell script to copy the e-books file formats from qBittorrent to a pre-defined directory
# Requires PSParseHTML Module for ConvertFrom-HTML
# Load ConvertTo-Slug from Gist
iex (New-Object -TypeName System.Net.WebClient).DownloadString('https://gist.githubusercontent.com/mavaddat/0bbed730a4c10a066d75894a7611d730/raw/4a37c2ec4f0d33ff2bbb1a224b0b901063dce871/slugify.ps1')
mkdir "$env:TEMP\Calibre\"
foreach($file in Get-ChildItem -Path $env:USERPROFILE\Downloads\Books\ | Where-Object -Property Length -GT 0){
$libgen = Invoke-RestMethod -Method Get -Uri "https://libgen.is/book/index.php?md5=$($file.BaseName)" | ConvertFrom-HTML -Engine AngleSharp
$title = $libgen.QuerySelector("body > table > tbody > tr > td > b > a").InnerHtml
$authors = $libgen.QuerySelector("body > table > tbody > tr > td:nth-child(2) > b").InnerHtml -replace '\([^\)]+\)', '' -replace '\s*[;,]\s*',' & '
$ext = $libgen.QuerySelector("body > table > tbody > tr:nth-child(11) > td:nth-child(4)").InnerHtml
$file | Copy-Item -Destination "$env:TEMP\Calibre\$(ConvertTo-Slug -Text $title -CapitalizeFirstLetter -Delimiter ' ') -
@mavaddat
mavaddat / downloadBooks.ps1
Last active May 22, 2022 15:18
This script checks for invalid books in the calibre library by looking for empty covers and then searches for the original book file in the downloads folder
Set-Location C:\CalibrePortable\Calibre\
$calibreNS = @{ 'dc' = 'http://purl.org/dc/elements/1.1/'
'calibre' = 'http://calibre.kovidgoyal.net/2009/metadata'
}
$formatLessBookIds = [int[]](&.\calibredb.exe search 'formats:false and (identifiers:"=isbn:")' --library-path="..\Calibre Library\" | ForEach-Object { $_ -split ',' })
$formatLessBooks = Import-Clixml -Path .\formatLessBooks.xml
if($null -eq $formatLessBooks -or $null -eq $formatLessBooks.Hash -or $formatLessBooks.Hash -ne $formatLessBookIds.GetHashCode())
{
$formatLessBooks = @{ Hash = ($formatLessBookIds.GetHashCode());Books = ($formatLessBookIds | ForEach-Object { [xml](&.\calibredb.exe show_metadata --as-opf $PSItem --library-path="..\Calibre Library\") } | Where-Object { [string]::IsNullOrWhiteSpace((&.\calibredb.exe search formats:true title:`"$(Select-Xml -Xml $PSItem -Namespace $calibreNS -XPath '//dc:title' | ForEach-Object { $_.Node.InnerXml })`" author:`"$((Select-Xml -Xml $PSItem -Namespace $calibreNS -XPath '//dc:creator'

Keybase proof

I hereby claim:

  • I am mavaddat on github.
  • I am mavaddat (https://keybase.io/mavaddat) on keybase.
  • I have a public key whose fingerprint is A0F1 C894 5FA0 3F0A 40AB B121 9667 69C3 1FD6 37A1

To claim this, I am signing this object:

@mavaddat
mavaddat / deleteEmptyOrOPFOnlyDirs.ps1
Last active February 19, 2019 02:24
This script recursively deletes e-book library directories that have no books in them. It does this by checking for empty directories or directories with only OPF files in them. It then runs again to check for empty directories (to include the directories it may have just emptied).
$ebookLibraryPath = '.\OneDrive\Documents\Ebook Library\'
Function Get-Empties {
PARAM($targetPath)
Return Get-ChildItem -Path $targetPath -Recurse | Where { $_.PsIsContainer -eq $true } | Where { $_.GetDirectories().Count -eq 0 -and ($_.GetFiles().Count -eq 0) -or ($_.GetFiles().Count -eq 1 -and $_.GetFiles().Name -match "(?i)(.*?)\.opf$")}
}
$failed = @{}
$toEmpty = Get-Empties $ebookLibraryPath
Function Write-Log {
Param ( [parameter(Mandatory=$true,
@mavaddat
mavaddat / removeNumerationFromWifiNames.ps1
Last active October 5, 2021 02:25
This script removes the needless enumeration on the end of WiFi names (e.g., "Network 2", "Network 3", "Network 4", etc.) that sometimes happens in Windows when the computer does not recognize an SSID that it has connected to previously. It also logs the changes it makes in the Windows event log.
#Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; Invoke-Expression $($(Invoke-RestMethod -Method Get -Uri 'https://api.github.com/gists/30e1c0cb20f6a1800e3ed7f728a69763').files.'removeNumerationFromWifiNames.ps1'.content)
if (-not $(New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
$Host.UI.WriteErrorLine("You need to be running PowerShell as an administrator to run this script. Please open an admin PowerShell session and try again.")
exit
}
$scriptName = 'removeNumerationFromWifiNames.ps1'
try {
if (Get-Command -Name Get-EventLog -CommandType Function -ErrorAction Ignore) {
Get-EventLog -LogName Application -Source $scriptName -ErrorAction Ignore
@mavaddat
mavaddat / download-latest-release.ps1
Last active June 26, 2019 17:08 — forked from MarkTiedemann/download-latest-release.ps1
Download latest dotnet/codeformatter from GitHub release via Powershell
# Download latest dotnet/codeformatter release from github
$repo = "dotnet/codeformatter"
$file = "CodeFormatter.zip"
$releases = "https://api.github.com/repos/$repo/releases"
Write-Host Determining latest release
$tag = (Invoke-WebRequest $releases | ConvertFrom-Json)[0].tag_name