Skip to content

Instantly share code, notes, and snippets.

Avatar

Joe Cefoli jcefoli

View GitHub Profile
@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 / 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 / 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 / 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,
@jcefoli
jcefoli / copytosubdirectories.bat
Created Jan 28, 2015
This script takes the contents of one directory and copies them into a newly created folder in all existing subdirectories of the destination directory.
View copytosubdirectories.bat
@ECHO OFF
REM | This script will take all files and subdirectories in
REM | C:\Source and copy them into a new folder called "Config" in
REM | all subdirectories of C:\Dest. If there are no subdirectories,
REM | nothing will happen
REM |
REM | ie - C:\Source\*.* will be copied to C:\Dest\Folder\Config\*.*
REM | assuming "Folder" was a preexisting subdirectory
REM :: Define Variables Here ::
@jcefoli
jcefoli / datetimestamp.bat
Created Feb 18, 2015
Set Date/Timestamp in Batch File Via Powershell
View datetimestamp.bat
@ECHO OFF
for /f "usebackq" %%x in (`powershell "get-date -f yyyy-MM-dd_HH:mm:ss"`) do set datetimestamp=%%x
echo %datetimestamp%
pause
@jcefoli
jcefoli / gist:e8a133639e5ff5fa5156
Created Sep 22, 2015
Convert PFX Windows Cert to Linux Public/Private Key and Chain
View gist:e8a133639e5ff5fa5156
openssl pkcs12 -in ./cert.pfx -clcerts -nokeys -out public.crt
openssl pkcs12 -in ./cert.pfx -nocerts -nodes -out private.rsa
cat public.crt ca-bundle.crt >> bundle.crt
@jcefoli
jcefoli / stopredis.sh
Created Nov 2, 2015
Stop Multiple Instances of Redis Server and Sentinel if they're Running on One Server
View stopredis.sh
for f in /etc/init.d/redis*; do $f status; done