Skip to content

Instantly share code, notes, and snippets.

View jcefoli's full-sized avatar

Joe Cefoli jcefoli

View GitHub Profile
@jcefoli
jcefoli / spaceinput.bat
Last active June 23, 2023 00:03
Batch File User Input: Convert Spaces to %20
@ECHO OFF
REM This snippet will take an input string with spaces and replace them with %20
SET /p input=Input string:
SETLOCAL ENABLEDELAYEDEXPANSION
SET input=!input: =%%20!
ECHO.
ECHO %input%
PAUSE
@jcefoli
jcefoli / edithosts.bat
Last active August 29, 2015 14:03
Edits Hosts File in Notepad++ With Admin Elevation
@echo off
REM Note - this will not work if npp is already running without admin privledges
:checkPrivileges
NET FILE 1>NUL 2>NUL
if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )
:getPrivileges
if '%1'=='ELEV' (shift & goto gotPrivileges)
@jcefoli
jcefoli / switchpages.php
Last active August 29, 2015 14:03
Simple way to get the document name of the page and file extension and uses a switch statement to do something unique based on which page you're on
<?
//Gets the document name of the page. For example, index.php
$getDocument = explode('/', $_SERVER["PHP_SELF"]);
$currentPage = $getDocument[count($getDocument) - 1];
//Switch statement
switch ($currentPage) {
case "index.php":
//do something unique on index.php
break;
@jcefoli
jcefoli / quickedit
Created July 8, 2014 18:56
Enable QuickEdit mode in the Windows Command Line (copy/paste without using mark)
REG.EXE add HKCU\Console /v QuickEdit /t REG_DWORD /d 1 /f
@jcefoli
jcefoli / checkVPSandReboot.py
Created August 15, 2014 22:30
This python script will reboot your DigitalOcean droplet if the hostname is unreachable or returns a status 500 or 503. All you have to do is edit the variables. Can be scheduled as a cron job.
#!/usr/bin/python
import httplib
import subprocess
############################## Site To Check #################################
VAR_hostname = "yoursite.com"
VAR_path = "/"
######################### DigitalOcean Variables #############################
VAR_dropletID = "123456"
VAR_Token = "YOUR_API_TOKEN_HERE"
@jcefoli
jcefoli / choice.bat
Created August 15, 2014 22:33
Template for Yes/No Choice input in batch files
@ECHO OFF
:start
SET choice=
SET /p choice=Do something? [N]:
IF NOT '%choice%'=='' SET choice=%choice:~0,1%
IF '%choice%'=='Y' GOTO yes
IF '%choice%'=='y' GOTO yes
IF '%choice%'=='N' GOTO no
IF '%choice%'=='n' GOTO no
IF '%choice%'=='' GOTO no
@jcefoli
jcefoli / timer.bat
Created August 28, 2014 14:37
This snippet calculates a start time, end time and total duration for your batch script
@ECHO off
SET STARTTIME=%TIME%
REM DO THINGS HERE TO TIME
timeout 5
REM DO THINGS HERE TO TIME
REM Final Calculations
@jcefoli
jcefoli / move-recursive.ps1
Last active May 23, 2023 15:14
Powershell: Move Files & Folders In Directory Recursively to Another Directory
<#
Recursively move all files in C:\SourceDir into C:\Destination
Assumes C:\Destination exists already, or there could be problems
#>
Move-Item -Path "C:\SourceDir\*" -Destination "C:\Destination"
@jcefoli
jcefoli / allkeys.php
Last active November 21, 2022 11:11
List All Key/Value Pairs in Redis using the Predis Library. Assumes that Redis is running locally on default port 6379 with no password auth
<?
//Include Predis library. See https://github.com/nrk/predis for more info
require "Predis/Autoloader.php";
//Connect to Redis
Predis\Autoloader::register();
try {
$redis = new Predis\Client();
$redis = new Predis\Client(array(
"scheme" => "tcp",
@jcefoli
jcefoli / restoretime.sql
Created January 16, 2015 23:53
[MSSQL] Checks Status of a DB Restore
declare @sql_text char(255);
declare @total_time_so_far int;
declare @total_percent float;
declare @seconds_per_percent float;
declare @total_time time;
declare @time_left time;
SELECT @sql_text = sqltext.TEXT,
@total_time_so_far = req.total_elapsed_time,