Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / optimize_gif.groovy
Last active February 6, 2017 15:03
Optimize Gifs with giflossy
#!/bin/groovy
import groovy.io.FileType
def optimize(inGif, outDir) {
def cmd = "gifsicle --colors 256 -O3 ${inGif.path} -o ${outDir.path}\\${inGif.name}"
//println cmd
def proc = cmd.execute()
proc.text.eachLine {println it}
def exitValue = proc.exitValue()
@damc-dev
damc-dev / TimeoutThreadPoolExecutor.java
Created February 22, 2017 22:19
ExecutorService that interrupts tasks after a timeout
import java.util.List;
import java.util.concurrent.*;
// SOURCE: http://stackoverflow.com/q/2758612
public class TimeoutThreadPoolExecutor extends ThreadPoolExecutor {
private final long timeout;
private final TimeUnit timeoutUnit;
private final ScheduledExecutorService timeoutExecutor = Executors.newSingleThreadScheduledExecutor();
@damc-dev
damc-dev / AgileBuzzwords.txt
Created March 6, 2017 14:44
Agile Buzzwords for use in Sprint Planning Bingo
Burndown chart
VersionOne
Jira
Velocity Chart
Scrum
Ideal Day
Meaningful backlogs
Prioritize epic
Agile
Tells the story
@damc-dev
damc-dev / convertToKb.sh
Created May 15, 2017 15:07
Convert a value provided to the JVM to Kb
#!/bin/bash
convertToKb() {
data="$1"
unit="${data//[0-9]/}"
value="${data//[!0-9]}"
converted="ERROR"
case $unit in
k | K)
converted="$value"
;;
@damc-dev
damc-dev / menu.sh
Created May 30, 2017 13:28
Bash menu select option
#!/bin/bash
# Bash Menu Script Example
PS3='Please enter your choice: '
options=("Option 1" "Option 2" "Option 3" "Quit")
select opt in "${options[@]}"
do
case $opt in
"Option 1")
echo "you chose choice 1"
@damc-dev
damc-dev / parallel-subshells.sh
Last active May 30, 2017 13:34
Run Bash subshells in parallel
#!/bin/bash
TMP_DIR="$(mktemp -d -t subshells.XXXXXXXXXX)"
function cleanup {
rm -rf "${TMP_DIR}"
}
trap cleanup EXIT
PIDS=()
for i in 1 2 3; do
@damc-dev
damc-dev / tmux.md
Created June 16, 2017 21:28 — forked from smhjn/tmux.md
Clean tmux cheat-sheet

Clean tmux cheat-sheet

By resources

sessions

list-sessions        ls         -- List sessions managed by server
new-session          new        -- Create a new session