Skip to content

Instantly share code, notes, and snippets.

@krowe
krowe / color.sh
Created August 22, 2014 12:11
Displays a table of shell color codes
#!/bin/bash
useage() {
printf "\n\e[1;4mAscii Escape Code Helper Utility\e[m\n\n"
printf " \e[1mUseage:\e[m colors.sh [-|-b|-f|-bq|-fq|-?|?] [start] [end] [step]\n\n"
printf "The values for the first parameter may be one of the following:\n\n"
printf " \e[1m-\e[m Will result in the default output.\n"
printf " \e[1m-b\e[m This will display the 8 color version of this chart.\n"
printf " \e[1m-f\e[m This will display the 256 color version of this chart using foreground colors.\n"
printf " \e[1m-q\e[m This will display the 256 color version of this chart without the extra text.\n"
@krowe
krowe / GNU_Win32.md
Last active December 14, 2021 16:15
This guide shows you how to make a more GNU friendly Windows environment

Guide to a more GNU-like Windows CLI

Note: Most of this is now outdated information. Now that WSL exists it is the prefered way to use Linux on a Windows machine. The Windows 11 command line also does a lot of the things I used ConEmu for by default. It's still better but not as much so. The Windows app store now remembers your software so that you can easily redownload it so my personal need for Chocolately is all but gone as well.

This is a guide to setting up a Windows command line environment which supports many of the commonly used features available in a GNU\Linux environment. It is most useful to people whom work in mixed environments and would like a more seamless experience when switching back and forth but is also useful to those who've never used the GNU tools before.

@krowe
krowe / jgrep.bat
Last active January 6, 2021 19:05
A RegEx match script which uses Hybrid Batch\JScript code
@set @junk=1 /*
@cscript //nologo //E:jscript %~f0 %*
@goto :eof */
var args=WScript.Arguments, argCnt=args.Length, stdin=WScript.StdIn, stdout=WScript.StdOut;
var replaceSingleQuotes=false, printMatchesOnly=false, matchString, flagString, regex, argDx=0;
if(argCnt==0) {
throw new Error("You must provide search criteria.");
}
@krowe
krowe / mkdir_tree.bat
Last active August 29, 2015 14:05
This file is used for testing various file\directory tasks. It creates a huge directory tree with some error folders very quickly.
@ECHO OFF
IF EXIST TREE (
RMDIR /S /Q TREE
ECHO Tree Removed.
GOTO :EOF
)
FOR %%A IN (1,2,3) DO (
ECHO Creating [ %%A ] and it's sub directories...
FOR %%B IN (%%A_1,%%A_2,%%A_3) DO (
@krowe
krowe / repl.bat
Created August 27, 2014 15:45
A RegEx replace script which uses Hybrid Batch\JScript code
@if (@X)==(@Y) @end /* Harmless hybrid line that begins a JScript comment
::************ Documentation ***********
::REPL.BAT version 4.1
:::
:::REPL Search Replace [Options [SourceVar]]
:::REPL /?[REGEX|REPLACE]
:::REPL /V
:::
::: Performs a global regular expression search and replace operation on
@krowe
krowe / MKDIR_RANGE.BAT
Created October 19, 2014 01:36
A batch file for creating numbered directories. Such as: dir1, dir2, dir3, dir4
@echo off
SETLOCAL
:: Help is a special type of flag which is also
:: the default which has many ways to trigger.
IF "%1"=="" ( SET hflag_help=1 ) ELSE ( SET hflag_help=0)
IF "%1"=="/?" ( SET hflag_help=1 & SHIFT )
IF "%1"=="-?" ( SET hflag_help=1 & SHIFT )
IF "%1"=="--help" ( SET hflag_help=1 & SHIFT )
:: The other flags are all similar.
@krowe
krowe / numeric_rename.bat
Last active October 24, 2018 15:27
This file will change the file title of all files is a directory so that they are all just an incremented number with the original extension still in place.
@set @junk=1 /*
@cscript //nologo //E:jscript %~f0 %*
@goto :eof */
var args=WScript.Arguments, shell=WScript.CreateObject("WScript.Shell"), bForced, nStartIndex, sFilter;
if(args.length==0||(args.length==1&&(bForced=args(0).toLowerCase()=='-f'||args(0).toLowerCase()=='--force')))
err(1, "You must provide a starting value to begin counting at.");
if(args(0)=='-?'||args(0).toLowerCase()=='--help') { showHelp(); WScript.Quit(0); }
if(isNaN(nStartIndex=parseInt(args(bForced?1:0)))||nStartIndex<0)

Apache Host Sync

This script is useful for web developers and administrators whom use Apache name based virtual hosts to host multiple websites on the same server and would like to have the Listen and NameVirtualHost directives automatically updated when they add or remove virtual hosts.

Even though these are usually easy to configure it can be tedious to keep these values updated on some setups where hosts are being added and removed frequently. In these setups you could just add these directives to your vhost configuration but, in the case of the Listen directive, you'll need to ensure that they do not conflict so it is more handy to have them all listed in the same place. This is why the default Apache setup breaks these out into a separate file called ports.conf on most setups. Using this script you'll have the best of both worlds by being able to configure only the vhost definition while still having a central definition to avoid conflicts.

It works by scanning a list of configuration files

@krowe
krowe / bcat
Last active August 29, 2015 14:10
This bash script is similar to the cat GNU tool but it will interpret escape codes as it prints. This allows for you to use bash escape codes to make rich text files.
#!/bin/bash
while read -r; do
printf "%b\n" "$REPLY"
done < $1
printf "\e[0m"
@krowe
krowe / index.php
Last active November 26, 2018 11:56
This is a handy PHP file for development machines which includes phpinfo information and a directory listing.
<?php
// BEGIN CONFIGURATION
$server_name = gethostname().' - Development Machine';
$search = dirname(__FILE__); // The directory you want to search.
// This uses a filesystem style pattern and ignores case (even on linux systems).
$ignore = array('.*','index.*','*.bak','aspnet_client'); // Files with these names are always ignored.
$usr = array( // These describe the user whom can log in and what group they are in