Skip to content

Instantly share code, notes, and snippets.

View jcefoli's full-sized avatar

Joe Cefoli jcefoli

View GitHub Profile
@jcefoli
jcefoli / edithosts.bat
Last active August 29, 2015 14:03
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 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
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 July 8, 2014 18:56
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 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.
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 January 16, 2015 23:53
[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 January 28, 2015 03:00
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 February 18, 2015 07:34
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 September 22, 2015 20:19
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 November 2, 2015 20:37
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
@jcefoli
jcefoli / gist:867db8bef87442744092
Created December 3, 2015 18:54
Tar and gzip a directory's files and subfolders only (without storing the full path to the files in the archive)
View gist:867db8bef87442744092
tar -cvzf filename.tar.gz -C /path/to/archive .