Skip to content

Instantly share code, notes, and snippets.

@joshbooks
joshbooks / multiLineMatch.sh
Created April 29, 2019 01:06
multiline matching without pcregrep
#/bin/bash
# avoid adding pcregrep as dependency for simple matching across
# not too many lines (I'd guess performance is going to start degrading
# at around 100??)
# returns number of lines of input for which we didn't find a contiguous
# match in the file provided
# emits the lines in the file that were matched by the multi line pattern
# provided
multiLineMatch() {
@joshbooks
joshbooks / noPDAInTheWorkplace.sh
Last active May 18, 2019 00:12
push down automaton wrapped in some crazy bash magic
serviceDefinition=`sed -f "remccoms3.sed" "$file" | sed '/^[[:space:]]$/d' | uniq | awk '/service[[:space:]]*'"$service"'/ {beginLine=NR} beginLine > 0 && NR >= beginLine {depth += gsub("{",""); depth -= gsub("}","")} depth > 0 && beginLine < NR {print} beginLine > 0 && depth == 0 {exit}'`
@joshbooks
joshbooks / viewMyPRs.sh
Created May 28, 2019 19:00
view your pull requests for the git repo in the current directory assuming you have GITHUB_USERNAME set
#!/bin/bash
read -ra gitUrls <<< `git remote -v | awk '{print $2}' | sort -u`
if [[ ${#gitUrls[@]} -eq 1 ]]
then
selection=0
else
selections=0
for gitUrl in ${gitUrls[@]}
@joshbooks
joshbooks / postgresTableToKotlinDataClass
Last active August 7, 2019 20:36
turn a postgres table into a kotlin data class
psql "$postgresDb" -c "\pset pager off" -c "\d $postgresTable" | perl -pe 's/(_)./uc($&)/ge;s/_//g' | awk -F '|' '
BEGIN {shouldPrint = 0} / id / {shouldPrint = 1} /Indexes/ {shouldPrint = 0}
shouldPrint != 0 {printf "val "$1": "}
shouldPrint != 0 && $2~/integer/ {printf "Long"}
shouldPrint != 0 && $2~/boolean/ {printf "Boolean"}
shouldPrint != 0 && $2~/character varying/ {printf "String"}
shouldPrint != 0 && $2~/text/ {printf "String"}
shouldPrint != 0 && $2~/timestamp with time zone/ {printf "java.sql.Timestamp"}
shouldPrint != 0 && $4~/not null/ {print ","} shouldPrint != 0 && $4~/^ *$/ {print "?,"}'
This is a cool way to add a gist!
This is a cool way to add a gist!
This is a cool way to add a gist!
This is a cool way to add a gist!
This is a cool way to
add
a gist!
@joshbooks
joshbooks / makeKotlinFileFromJavaPath
Last active March 29, 2021 21:00
create new kotlin file corresponding to existing java path
#!/bin/bash
javaPath=$1
kotlinPath=`echo "$javaPath" | sed 's|/java/|/kotlin/|' | sed 's|\.java|.kt|'`
echo "creating $kotlinPath"
parentDir=`echo "$kotlinPath" | sed 's|[^/]*$||'`