Skip to content

Instantly share code, notes, and snippets.

View gpottepalem's full-sized avatar
🏠
Working from home

Giri Pottepalem gpottepalem

🏠
Working from home
View GitHub Profile
import java.util.concurrent.atomic.AtomicInteger
import java.util.stream.IntStream
/**
* Groovy script to showcase "Iterate list with index" in both Groovy and Java
*
* @author Giri Pottepalem
*/
// Groovy
println 'Groovy - Iterate list with index'
@gpottepalem
gpottepalem / movies.xml
Last active March 21, 2022 19:25
Parses XML and displays various elements and properties - just to demonstrate the groovy XML support....
<?xml version="1.0" encoding="utf-8"?>
<movies>
<movie name="Titanic">
<year>2003</year>
<directors>
<director name="James Cameron" />
</directors>
<plotSummary><![CDATA[Incorporating both historical and fictionalized aspects, it is based on accounts of the sinking of the RMS Titanic, and stars Leonardo DiCaprio and Kate Winslet as members of different social classes who fall in love aboard the ship during its ill-fated maiden voyage.]]></plotSummary>
<box-office>
<release_date>Dec 19, 1997</release_date>
@gpottepalem
gpottepalem / SplitFile.java
Last active March 14, 2022 18:54
A Java app that splits a file into many.
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Path;
/**
* File splitter, splits a file into many with each file containing specified number of lines.
* Env. - JVM: 17.0.1 Vendor: Amazon.com Inc. OS: Mac OS X
@gpottepalem
gpottepalem / encode-decode-base64.groovy
Last active March 14, 2022 18:55
A Groovy Script to encode and decode a String using Base64.
/**
* Encode and decode a String using Base64
* Env. - Groovy Version: 3.0.9 JVM: 17.0.1 Vendor: Amazon.com Inc. OS: Mac OS X
*
* @author Giri Pottepalem
*/
String inputString = '{"name":"Giri"}'
println "inputString : $inputString"
String encodedString = Base64.encoder.encodeToString(inputString.bytes)
@gpottepalem
gpottepalem / split-file.groovy
Last active March 14, 2022 18:56
A Groovy script that splits a file into many.
/**
* File splitter, splits a file into many with each file containing specified number of lines.
* Env. - Groovy Version: 3.0.9 JVM: 17.0.1 Vendor: Amazon.com Inc. OS: Mac OS X
*
* @author Giri Pottepalem
*/
File inputFile = new File("${System.getProperty('user.home')}${File.separator}a.csv")
def (filename, extension) = inputFile.path.tokenize( '.' )
int linesPerFile = 5
@gpottepalem
gpottepalem / bootstrap.sql
Last active March 14, 2022 18:57
A sample bootstrap SQL that creates a table and inserts a record (Postgres DB).
-- postgres
-- create test table
CREATE TABLE test_json (
id varchar(36) NOT NULL,
profile json NULL,
-- age: derived column, value derived from profile json
age smallint GENERATED ALWAYS AS ((profile ->> 'age')::smallint) STORED,
CONSTRAINT pk_giri_test PRIMARY KEY (id)
);
@gpottepalem
gpottepalem / postgres.sh
Last active March 14, 2022 18:57
Shell Script that runs a Postgres Docker image, executes bootstrap.sql, and a couple of SQL commands.
#!/usr/bin/env bash
#------------------------------------------------------------------------------------
# Runs a Postgres Docker image, executes bootstrap.sql, and a couple of SQL commands
# Defaults:
# db name: a-postgres, user: user, password: pw, port: 5400
# Usage:
# ./postgres.sh // defaults
# ./postgres.sh b 5401 5 // override defaults
#------------------------------------------------------------------------------------
# ---- Optional arguments with default values
@gpottepalem
gpottepalem / execute-shell-command.groovy
Created February 25, 2022 22:13
Groovy script to execute a shell command and display the output
println "ls -l".execute().text
@gpottepalem
gpottepalem / .bash_profile
Last active February 25, 2022 22:06
.bash_profile - Multi-color custom prompt with user, host, pwd, command status emoji, and git branch name
# -----------------------------------------------------------------------------------
# Terminal prompt customized:
# "\$(command_exit_status_emoji)" - conditional emoji based on command exit status
# "$txtcyn\u@$txtpur\h $txtgrn\w" - "user@host-name pwd" in different colors
# "$txtylw\$(git_branch)" - git branch-name if pwd is git repo in yellow
# -----------------------------------------------------------------------------------
txtblk='\[\e[0;30m\]' # Black
txtred='\[\e[0;31m\]' # Red
txtgrn='\[\e[0;32m\]' # Green
txtylw='\[\e[0;33m\]' # Yellow