Skip to content

Instantly share code, notes, and snippets.

@damc-dev
damc-dev / setJdk.bat
Created January 26, 2017 17:43
Bat Script for setting Java version on Windows
@echo off
IF [%1]==[] (
echo Usage: %0 [jdk_version]
echo.
echo ** Available JDKs: **
dir "%programfiles(x86)%\Java" /b
echo.
) ELSE (
IF EXIST "%programfiles(x86)%\Java\%1" (
@damc-dev
damc-dev / CamelEmailPoller.groovy
Created January 16, 2017 18:28
Poll Email with Groovy and Apache Camel
#!/usr/bin/env groovy
import org.apache.camel.impl.DefaultCamelContext
import org.apache.camel.builder.*
@Grab(group='org.apache.camel', module='camel-groovy', version='2.11.0')
@Grab(group='org.apache.camel', module='camel-mail', version='2.11.0')
@Grab(group='org.apache.camel', module='camel-core', version='2.11.0')
@Grab(group='org.slf4j', module='slf4j-log4j12', version='1.7.5')
@damc-dev
damc-dev / bash-division.sh
Created December 7, 2016 18:21
Bash division (and cheating with Python)
#!/bin/sh
NUM1="62121"
NUM2="64000"
PERCENT=$(bc -l <<< "scale=4; $NUM1 / $NUM2")
echo $(bc -l <<< "scale=2; $PERCENT * 100")
PY=$(python -c "print '%.2f' % ((float($NUM1)/float($NUM2))*100)")
echo $PY
@damc-dev
damc-dev / dateformat.sh
Created December 7, 2016 17:20
Example date formatting
#!/bin/sh
# Datetime in local timezone
echo "* $(date +'%Z'): $(date +'%Y-%m-%dT%H:%M:%S.%N%:z')"
# Datetime in specified timezone
echo "$(TZ=UTC date +'%Z'): $(TZ=UTC date +'%Y-%m-%dT%H:%M:%S.%N%:z')"
@damc-dev
damc-dev / terminalcolors.sh
Created December 7, 2016 17:18
Check if host supports 256-color
#!/bin/sh
# 256-color mode not supported on this host
if echo $TERM | grep -q -- '-256color'; then
echo -e '\n\n256-color mode not supported on this host. Reverting TERM...\n'
export TERM=`echo -n $TERM | sed 's/-256color//'`
fi
@damc-dev
damc-dev / find-free-port.py
Last active December 7, 2016 17:09
Find Free Ports - Linux
#!/usr/bin/env python
# Source: http://unix.stackexchange.com/questions/55913/whats-the-easiest-way-to-find-an-unused-local-port#comment271991_132524
# One liner: python -c 'import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1]); s.close()'
import socket
s=socket.socket()
s.bind(("", 0))
print(s.getsockname()[1])
s.close()
@damc-dev
damc-dev / listJavaDUMemoryAsCsv.sh
Last active October 6, 2016 13:48
Create CSV of running java processes and their memory usage
#!/bin/bash
#
# Description: Create CSV of running java processes and their memory usage
# this script must be run as the same user as the java processes you want to capture
#
# Author: David McElligott<damcelli@up.com> 10/5/2016
#
user="$(whoami)"

source: vim.wikia.com - 03/21/2016

Vim: Moving around

You can save a lot of time when navigating through text by using appropriate movement commands. In most cases the cursor keys are not the best choice.

Here are some basic movement commands that may help you acquire a taste for more:

e       Move to the end of a word.

w Move forward to the beginning of a word.

@damc-dev
damc-dev / toLowerCase.sh
Created March 9, 2016 15:09
Simple Bash functions
#!/bin/sh
function toLowerCase {
local word=$1
local lowercaseWord="$(tr '[:upper:]' '[:lower:]' <<< "$word")"
echo "${lowercaseWord}"
}
lowerCaseWord="$(toLowerCase $1)"
echo "$lowerCaseWord"
@damc-dev
damc-dev / getOpenLogFileSizes.sh
Last active March 9, 2016 15:06
Print the open log files and their sizes in human readable format
#!/bin/sh
/usr/sbin/lsof +D /logs -s 2>/dev/null | sort -k 7 -g -r | while read x; do
size=`echo $x | awk '{print $7}'`
file=`echo $x | awk '{print $9}'`
SIZE=`echo $size | awk 'function human(x) {
s=" B KiB MiB GiB TiB EiB PiB YiB ZiB"
while (x>=1024 && length(s)>1)
{x/=1024; s=substr(s,5)}