Skip to content

Instantly share code, notes, and snippets.

Avatar

Joe Cefoli jcefoli

View GitHub Profile
@jcefoli
jcefoli / spaceinput.bat
Last active Aug 29, 2015
Batch File User Input: Convert Spaces to %20
View spaceinput.bat
@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 Aug 29, 2015
Edits Hosts File in Notepad++ With Admin Elevation
View edithosts.bat
@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 Aug 29, 2015
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
View switchpages.php
<?
//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 Jul 8, 2014
Enable QuickEdit mode in the Windows Command Line (copy/paste without using mark)
View quickedit
REG.EXE add HKCU\Console /v QuickEdit /t REG_DWORD /d 1 /f
@jcefoli
jcefoli / checkVPSandReboot.py
Created Aug 15, 2014
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.
View checkVPSandReboot.py
#!/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 Aug 15, 2014
Template for Yes/No Choice input in batch files
View choice.bat
@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 Aug 28, 2014
This snippet calculates a start time, end time and total duration for your batch script
View timer.bat
@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 Jun 19, 2021
Powershell: Move Files & Folders In Directory Recursively to Another Directory
View move-recursive.ps1
<#
The Windows move command is not recursive. Powershell's Move-Item moves the entire directory.
Robocopy /MOVE copies and deletes, which is slow.
This snippet takes files and folders in a directory (C:\SourceDir) and recursively moves them out of the dir and into another one C:\Destination.
#>
Get-ChildItem -Path "C:\SourceDir" -Recurse | Move-Item -Destination "C:\Destination"
@jcefoli
jcefoli / allkeys.php
Last active Jun 3, 2021
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
View allkeys.php
<?
//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 Jan 16, 2015
[MSSQL] Checks Status of a DB Restore
View restoretime.sql
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,