Skip to content

Instantly share code, notes, and snippets.

@pradhyu
pradhyu / pyspark submit in standalone docker pyspark image
Last active August 19, 2024 23:56
Run pyspark in standalone docker image
# create a test.py file to spark-submit
cat << EOF > test.py
# Import SparkSession
from pyspark.sql import SparkSession
# Create SparkSession
spark = SparkSession.builder \
.master("local[1]") \
.appName("SparkByExamples.com") \
.getOrCreate()
@override
public boolean equals(final Object object) {
if (this == object) {
return true;
}
if (!(object instanceof KnowledgePackageImpl)) {
return false;
}
@pradhyu
pradhyu / curryFunctions.groovy
Created February 8, 2019 03:41
Curry functions in groovy
@Grab('commons-lang:commons-lang:2.5')
import org.apache.commons.lang.RandomStringUtils as RSU
def randomClosure = { size, letters, numbers ->
// Invoke RandomStringUtils.random() method
RSU.random size, letters, numbers
}
def randomNumbers = randomClosure.rcurry(false, true) // letters = false, numbers = true
def randomLetters = randomClosure.ncurry(1, true, false) // letters = true, numbers = false
@pradhyu
pradhyu / undefinedVariable.groovy
Last active March 21, 2023 15:48
Check if a variable is undefined in groovy
// checking bindings snippets
if (binding.hasVariable('superVariable')) {
// your code here
}
An easy solution to this is the following:
if (binding.variables.containsKey("bindingVar")) {
// do something
}
Or if you’d like to get a null value for an optional binding:
@pradhyu
pradhyu / SpockConfig.groovy
Created February 8, 2019 02:45
Configure spock report ( athaydes)
spockReports {
// shows code blocks in report
set 'com.athaydes.spockframework.report.showCodeBlocks': true
// change the output dir of spock reports
set 'com.athaydes.spockframework.report.outputDir': 'target/spock-reports'
// using templates
set 'com.athaydes.spockframework.report.IReportCreator': 'com.athaydes.spockframework.report.template.TemplateReportCreator'
// Set properties of the report creator
set 'com.athaydes.spockframework.report.template.TemplateReportCreator.specTemplateFile':'/reportTemplates/spec-template.md'
set 'com.athaydes.spockframework.report.template.TemplateReportCreator.summaryTemplateFile':'/reportTemplates/summary-template.md'
@pradhyu
pradhyu / ssh-scp-groovy-grab.groovy
Created February 8, 2019 02:23
Ssh scp using groovy Grab
// https://mvnrepository.com/artifact/com.aestasit.infrastructure.sshoogr/sshoogr
@Grapes(
@Grab(group='com.aestasit.infrastructure.sshoogr', module='sshoogr', version='0.9.25', scope='runtime')
)
import static com.aestasit.infrastructure.ssh.DefaultSsh.*
/*
Consider localhost has a machine up with sshd listening to port 2222
@pradhyu
pradhyu / soap-ui-client.groovy
Created February 8, 2019 02:22
Soap ui client using groovy grab
@Grab('com.github.groovy-wslite:groovy-wslite:1.1.2')
import wslite.soap.*
def client = new SOAPClient('http://www.holidaywebservice.com/Holidays/US/Dates/USHolidayDates.asmx')
def response = client.send(SOAPAction:'http://www.27seconds.com/Holidays/US/Dates/GetMothersDay') {
body {
GetMothersDay('xmlns':'http://www.27seconds.com/Holidays/US/Dates/') {
year(2011)
}
}
@pradhyu
pradhyu / ojdbcWithGrab.groovy
Created February 8, 2019 02:20
Connect to oracle using grab in groovy
#! /usr/local/bin/groovy
@GrabConfig(systemClassLoader = true)
// change the resolver path and grab artifact details if you want ojdbc6 jar from some other repo
@GrabResolver(name = 'ojdbc6', root = 'https://mvnrepository.com/artifact/com.oracle/ojdbc6')
@Grapes(
@Grab(group = 'com.oracle', module = 'ojdbc6', version = '12.1.0.1-atlassian-hosted')
)
/*
# Spawning docker oracle xe for testing, if you already have oracle instance to test we don't need this
wget https://ftp.gnu.org/gnu/emacs/emacs-26.1.tar.gz
tar xvf emacs-26.1.tar.gz
cd emacs-26.1
./configure --without-selinux
make
sudo make install
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});