Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
# script to collect input until the end then overwrite an existing file
# with the provided input. Intended to simplify this pattern:
# cat file | grep | awk | sed > temp
# rm file
# mv temp file
# into this pattern:
# cat file | grep | awk | sed | rewrite file
# need the file to overwrite
@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|[^/]*$||'`
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 / 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 "?,"}'
@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 / 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}'`