Skip to content

Instantly share code, notes, and snippets.

Source Drive

If using a batch script, you can obtain the drive letter by using the 0 argument.

echo %~d0

Though if using folder mounts, you will want to keep the folder name as well.

wmic volume where label='Knox' get name

@davidruhmann
davidruhmann / launcher_profiles.json
Last active August 29, 2015 14:12
forge10.13.2.1230 launcher_profiles.json
{
"profiles": {
"Forge": {
"name": "Forge",
"lastVersionId": "1.7.10-Forge10.13.2.1230"
},
"1.7.10": {
"name": "1.7.10",
"lastVersionId": "1.7.10"
}
@davidruhmann
davidruhmann / launcher_profiles.json
Created December 29, 2014 21:37
Minecraft 1.7.10 Base Launcher Profile
{
"profiles": {
"1.7.10": {
"name": "1.7.10",
"lastVersionId": "1.7.10"
}
},
"selectedProfile": "1.7.10"
}
@davidruhmann
davidruhmann / imdb.bat
Created December 19, 2014 01:15
[Batch] [Powershell] IMDB Info Retriever
@echo off
:Main <Title> [Destination=CD]
call :DownloadIMDB %1 %2 "%CD%"
exit /b
:DownloadIMDB <Title> <Destination> ~UI/IO
PowerShell -NoProfile -ExecutionPolicy RemoteSigned -Command "$c = New-Object System.Net.WebClient; $c.DownloadString('http://www.omdbapi.com/?t=%~1&plot=full&r=json').Split(',') | ForEach { $_.Split('{') | ForEach { $_.Split('}') | ForEach { $l = $_.ToLower(); If ($l.Contains(([char]0x0022).ToString() + 'title' + ([char]0x0022).ToString())) { $env:_title = $_.Split(([char]0x0022).ToString())[3] } ElseIf ($l.Contains(([char]0x0022).ToString() + 'year' + ([char]0x0022).ToString())) { try { $env:_year = $_.Split(([char]0x0022).ToString())[3].Substring(0,4) } catch { } } ElseIf ($l.Contains(([char]0x0022).ToString() + 'poster' + ([char]0x0022).ToString())) { $env:_poster = $_.Split(([char]0x0022).ToString())[3] } ElseIf ($l.Contains(([char]0x0022).ToString() + 'rated' + ([char]0x0022).ToString())) { $env:_rated = $_.Split(([char]0x0022).ToString())[3] } } } }; Write-Host "$env:_title ($env
@davidruhmann
davidruhmann / DownloadGists.bat
Last active March 27, 2024 14:25
[Batch] [PowerShell] Download Gists
@echo off
:Main <Username> [Destination=CD]
call :DownloadGists %1 %2 "%CD%"
exit /b
:: TODO Support duplicate file names.
:: Current pagination limit set to 1000
:DownloadGists <Username> <Destination> ~UI/IO
PowerShell -NoProfile -ExecutionPolicy RemoteSigned -Command "$c = New-Object System.Net.WebClient; $c.Headers.Add('user-agent', 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2;)'); $c.DownloadString('https://api.github.com/users/%~1/gists?per_page=1000').Split(',') | ForEach { $_.Split('{') | ForEach { $_.Split('}') | ForEach { If ($_.Contains('filename')) { Write-Host ($f = $_.Split([char]0x0022)[3].Replace(([char]0x0022).ToString(), '')) } ElseIf ($_.Contains('raw_url')) { $c.DownloadFile($_.Split([char]0x0022)[3].Replace(([char]0x0022).ToString(), ''), '%~2\' + $f) } } } };"
exit /b
# Shell script to download Oracle JDK from command prompt / terminal.
# You can download all the binaries one-shot by just giving the BASE_URL.
## Features:
# Resumes a broken [previous] download, if any.
# Renames the file to a proper name with platform adding platform info.
# Downloads all the following from Oracle Website with one shell invocation.
# a. Windows 64 and 32 bit;
# b. Linux 64 and 32 bit; and
# c. API Docs.
@davidruhmann
davidruhmann / SO26787012.bat
Created November 6, 2014 20:00
SO26787012.bat
@echo off
setlocal EnableDelayedExpansion
call :Input MyVar "Enter your string "
call :Write MyVar
echo !MyVar!
set MyVar
endlocal
exit /b 0
:Input <Var> [Prompt]
@davidruhmann
davidruhmann / SO26614571.bat
Last active August 29, 2015 14:08
SO26614571.bat
@echo off
call :DisplayRecursiveSubDirectoryInformation %1
exit /b 0
@echo off
setlocal disableDelayedExpansion
if "%~1"=="" (call :recurse ".") else call :recurse %1
@davidruhmann
davidruhmann / SO26181747.bat
Created October 3, 2014 17:44
SO26181747.bat
@echo off
:: usage: script.bat [username=%username%]
call :AnyActiveRemoteSessions %~1 %username% && echo Yes || echo No
exit /b 0
:AnyActiveRemoteSessions [Username]
for /f "skip=1 tokens=2,4" %%A in ('query user %~1 ^| find ">"') do call :IsActiveRemoteSession "%%~A" "%%~B" && exit /b 0
exit /b 1
@davidruhmann
davidruhmann / Expand.bat
Last active August 29, 2015 14:00
[Batch] My Expand Routine
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: This works by exploiting the set and defined commands. If the Var is null,
:: then the set command will fail, the error message is caught, and the defined
:: command will fail because there should NEVER exist a variable named =.
:: Usage: call :Expand A %~1 0
:: The default works by exploiting how commands are parsed. If parameter 1 is
:: empty, then 0 will be passed to the routine as Value.
:: Author: David Ruhmann
:Expand <Var> [Value] [Default]
2>nul set "%~1=%~2"