This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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) | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
println "ls -l".execute().text |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ----------------------------------------------------------------------------------- | |
# 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 |