The HTML5 Herald| Relentless Coding
Sometimes it comes in handy to have a Linux box act as a router. You might nothave a switch lying around. You might want to monitor all traffic coming andgoing to some device. In this post, we will set up Linux to act as a simple IPv4NAT router. We will call the Linux machine linux and the machine using the Linux box forinternet breakout remote. You need 2 NICs on your Linux. They can be 2 ethernet ports. But you couldalso use your wireless interface for this. In this post, we assume they are...| Relentless Coding
How to back up your servers with borg? One way to do it, as documented by the fine borg documentation, is to use a pull backup using sshfs. The idea is to mount the remote filesystem in a local directory, chroot into it, and run borg inside the chroot.| Relentless Coding
I have a Purism Librem 5 Linux phone. The Evergreen batch has 32 GiB offlash storage. In this post I will show how to run SpinRite on that drive. Since this is a rather large post, a table of contents seems in order.1 Tools Used Prerequisites Step 1: Buy SpinRiteStep 1.1: Install Wine Step 1.2: Extract Bootable SpinRite ISO from SpinRite WindowsBinary Step 2: Run SpinRite in VirtualBoxStep 2.1a: Using the GUI Step 2.1b: Using the CLI Step 2.2: Start the VirtualMachine Step 3: Use Jumpdrive to...| Relentless Coding
I recently got my hands on a second-hand Cisco 4321 router. First things first,I want to upgrade to the latest IOS version so I have the latest securitypatches. Having no experience at all with IOS, these are some things I learnedalong the way. Conventions Used in This Post Router> is a command prompt that indicates the user in currently in EXEC mode.Router# indicates that the user is in privileged EXEC mode. You get from EXECto privileged EXEC mode by: Router>enableRouter#disableRouter> Depe...| Relentless Coding
How to query an OCSP responder to check the validity of a certificate?| Relentless Coding
What to do when you use Vim to open a zip file, but the file extensionis not .zip or one of the other extensions known to Vim’s zip plugin? Displaying ZIP File Content With Vim Out of the box, Vim is able to open zip files and display its contents.You can even edit zipped files and save them. Vim recognizes the following file extensions as containing zippedcontent: :echog:zipPlugin_ext*.aar,*.apk,*.celzip,*.crtx,*.docm,*.docx,*.dotm,*.dotx,*.ear,*.epub,*.gcsx,*.glox,*.gqsx,*.ja,*.jar,*.kmz,...| Relentless Coding
In this post, we will look at how to set up the Maven infrastructure so we canbenchmark Kotlin code with JMH (the Java Microbenchmarking Harness). This post does not look in-depth on how to write JMH benchmarks, but rather howto build and run them. Create a Sample JMH Project Helpfully, the JMH project has a Maven archetype for Kotlin: $ mvn archetype:generate \ -DinteractiveMode=false\ -DarchetypeGroupId=org.openjdk.jmh \ -DarchetypeArtifactId=jmh-kotlin-benchmark-archetype \ -DgroupId=com.r...| Relentless Coding
This post looks at how to migrate a Postgres Docker image to a newer version. Iwill dump all databases contained in a container and migrate them all into a newcontainer. The process outlined works for any Postgres container, but I discussit in the context of my Nextcloud setup. My Setup I have Nextcloud running in containers, with the composition detailed in adocker-compose.yml file: Nextcloud PostgreSQL 11 Redis Nginx (reverse proxy) Postgres 11 was EOL for over a year, so it was time to mig...| Relentless Coding
In this post we will take a look at how to set up a shared Git repository. The goal is to have multiple different users be able to push to and pull from this repository. Security is provided by using Unix users and groups.| Relentless Coding
When you have a Docker container with a user that has a different UID from the one on your host, mounting a volume and accessing the files can result in permission issues.| Relentless Coding
How much storage does a single row in a Postgres table take?| Relentless Coding
On Security Now! podcast #951, Steve told us that 7organizations in the PKI are responsible for minting upwards of 99% ofall existing certificates. (Possible original source.) His suggestion was that we can remove all CAs except for those 7 andstill be able to browse the web normally. I wanted to try that, so Idisabled almost all CAs in Firefox by hand (about:preferences#privacyand then “View Certificates…”). After allowing some other CAs that Iencountered on web sites and that I though...| Relentless Coding
Under what circumstances cookies are accepted or rejected by user agentsand send back to web servers can be a bit confusing. Let’s experiment abit. TL;DR Actually, it is pretty simple: The origin domain is the domain you’re visiting. An origin domain canset cookies for its own domain and any higher-level domains. A clientwill send cookies for the origin domain and any higher-level domains.Conversely, a higher-level domain can read nor write cookies forsubdomains. So: example.com can read ...| Relentless Coding
Let’s create a self-signed certificate that contains a wildcard SubjectAlternative Name (SAN). $ openssl req -x509 \ -subj "/C=NL/L=Utrecht/O=Relentless Coding/CN=*.example.com"\ -addext "subjectAltName = DNS:example.com, DNS:*.example.com"\ -newkey rsa:2048 \ -noenc \ -keyout key.pem \ -out cert.pem -addext allows us to add X509 extensions to the certificate from thecommand line. In older versions of openssl(1) you needed to use aconfiguration file (--config openssl.cnf) to achieve the sam...| Relentless Coding
In Bash, when you open a file for writing, the file gets truncated.However, there is a way to open a file for both reading and writing atthe same time. Who hasn’t made the mistake of creating a process that tries to bothread and write to the same file? $ wc -c file17 file$ sed s/foo/FOO/ <file >file$ wc -c file0 Oops. That’s why for sed(1) in particular you use the-i[SUFFIX], --in-place[=SUFFIX] switch, and in general can usesponge(1) from moreutils (e.g. grep foo <file | sponge >file). B...| Relentless Coding
This is a quick look at Bash’s exec builtin with a simple example. bash(1) explains exec [command]: If command is specified, it replaces the shell. No new process iscreated. This is mainly useful for wrapper scripts, where wedo not want to have a Bash process lingering around. Take this scriptnamed test: #!/bin/bashsleep inf When run as ./test, the current shell creates a new Bash instance (theinterpreter specified in the first line of the script with the shebang#!/bin/bash), and then creat...| Relentless Coding
In this post, we are going to make a Bash script interact with an HTTPserver and have multiple exchanges using the same connection byleveraging named pipes/FIFOs. My first, naive approach was to first create named pipes i (for“input”) and o (for “output”). I ran openssl s_client with its stdinreading from i and its stdout writing to o and backgrounded it.Then, I used the shell builtin printf and cat to write and read fromi and o respectively: #!/bin/bashmkfifo i oh=bol.comopenssl s_cl...| Relentless Coding
When you’ve been using the same Linux system for a while, you might wantto upgrade the password hashing methods used. This article explains howto discover the methods supported by your system, set the preferredmethod and then upgrade the password hashes to make use of the newhashing method. You can see the supported hashing methods by looking at man 5 crypt. (Note that man section 5 indicates “Fileformats and conversions, e.g. /etc/passwd”.) Currently, onmy system, yescrypt is favored a...| Relentless Coding
Maven is modular. It uses plugins to achieve its goals. These pluginsare downloaded when they are invoked. For example, executing mvn wrapper:wrapper will make Maven first lookin your local repository (~/.m2/repository), and, if it cannot findit, download the wrapper plugin from the repository defined in yoursettings.xml. (If no custom repository is defined, the default Maven“central” repository will be used.) How does mvn know what to download, though, based only on a prefix(wrapper:)? B...| Relentless Coding
When a program that is part of a pipeline quits, it closes its stdin andstdout. Programs that produce the input for the quitted process may still tryto write to its stdin. Since they cannot, they will receive a SIGPIPE from thekernel. You can see this in action: $ seq 110000| head -11$echo"${PIPESTATUS[@]}"141 0 Conventionally, an exit status N greater than 128 indicates the programwas terminated by signal N - 128. Since SIGPIPE is signal 13, 141 - 128 = 13 indicates your program was ended by...| Relentless Coding
I’m going to show how to create the smallest possible MacOS app bundle we can:one that simply executes a Bash script. Then, I’m going to expand a bit on thatand add an icon to it. I’ll also show how open a Terminal app window so we cansee the script’s output in it. A MacOS app bundle is a directory that is interpreted in a special way byMacOS. It is an application name followed by the suffix .app (e.g.foo.app). A minimal app bundle would look like: $ mkdir foo.app$ cat > foo.app/foo#!...| Relentless Coding
Let’s take a look at how to use a GUI pinentry for one program, and cursesfor everything else. I’m on Arch Linux using i3wm as a window manager and pass as my passwordmanager. pass comes with a handy script, passmenu, that allows you to findyour password from within the status bar, dmenu. This way you won’t have toopen a terminal every time you want to copy a password. However, I had instructed gpg-agent to use /usr/bin/pinentry-curses. Thismeant that every time I invoked passmenu and m...| Relentless Coding
These are some of my favorite readline tweaks. To make changes to readline’s behavior, you have to put configuration in a filein your home directory called .inputrc. To include commands from/etc/inputrc, put the following first: $include /etc/inputrc Variables to customize readline behavior can be set in this file by statementsof the form: set variable-name value Restart your terminal emulator for the changes to take effect, or execute incurrent window: $bind -f ~/.inputrc Briefly Move to O...| Relentless Coding
I’ve recently finished “Sudo Mastery” by Michael W. Lucas.He’s a great and fun author that writes both technical guides and novels. Ibought his "$ git commit murder" some years agoand was sold. This post is basically a write-down of what I learned about sudo from hisbook. Why Use sudo? The most common reason to use sudo is to not hand out the root password toevery person that logs on to a server. The problem with handing everyone theroot password is that: They would be able to arbitra...| Relentless Coding
You have a file and you want to convert the contents into a JSON list. How canwe leverage jq to do that? $ cat fileonetwothree$ jq --null-input --raw-input '[inputs]'[ "one", "two", "three"] --raw-input (short -R) takes each line in the input as a string and passesit to the filter, instead of interpreting the file as containing JSON. --null-input (short -n) is important: $printf'%s\n' one two three | jq --raw-input '[inputs]'[ "two", "three"] --null-input doesn’t read the input at all. Inst...| Relentless Coding
Sometimes it’s handy to filter the output of a command (with grep, forexample) while still having the column names (the first line) available. How dowe go about that? One example of this would be when filtering the output of ps. What does thefollowing output mean, after all? $ ps -ef | grep logd 0 124 1 0 7:45AM ?? 0:01.46 /usr/sbin/syslogd 0 146 1 0 7:45AM ?? 0:09.44 /usr/libexec/logd 1000 17263 14631 0 10:36AM ttys010 0:00.01 grep --color=auto logd It would be much more readable if the ou...| Relentless Coding
It’s a good habit to use the latest versions of the dependencies youuse. Not only because the updated version might contain new features orbetter performance (one can hope), but also because bugs are fixed andsecurity issues are tackled. If you go about it by hand, however,updating dependencies is a boring and tedious task. Luckily for us,there is the Maven versions plugin to help us. Table of Contents Check Which Dependencies/Plugins/Properties NeedUpdating Update Parent Update To Latest V...| Relentless Coding
When you only need Sql*Plus, it’s good to have a small Docker image that youcan use. This post will look at how to create this Docker image. Table of Contents Introduction How to Build Your Own Image Optional: Add tnsnames.ora to theImage Introduction Some time back I wrote a blog post about SQL*Pluscommands. To run those commands, I woulduse a 15 GiB image of Oracle XE (Express Edition) just to be able to use acommand-line tool. Today I stumbled upon Oracle’s Docker images, that are awho...| Relentless Coding
Put@Transactionalon your test class or methods and test-managed transactions willautomatically be rollbacked. Table of Contents The Antipattern Difference Between Test-, Spring- and Application-ManagedTransactions What Does @Transactional Do? Beware: Only Test-Managed Transactions Are RolledBack Set Up or Tear Down Outside of aTransaction Spring Boot Version The Antipattern When looking at system test in Spring, it is not uncommon to see thispattern: importorg.junit.jupiter.api.Assertions.ass...| Relentless Coding
Problem When working on making a small application with a ZenityGUI,I ask the user for input. I need to somehow sanitize this input, or Iwill leave the gates wide open for two problems: SQL injection. Command injection. In this blog post, I’m going to look at a solution for the firstproblem. Disclaimer Of course, you shouldn’t write SQL queries in a programming languagethat doesn’t provide a way to supply parameterized queries. Also, when auser is executing a shell script themselves on ...| Relentless Coding
You might not always want to execute all tests. Sometimes you only want to runa single unit test, or only integrations tests that start with Foo. Let’s lookat how to make this happen in Maven. Table of Contents Skip Unit or Integration Tests Execute a Single Unit or Integration TestClass Execute a Single Unit or Integration Test Within a TestClass Further Reading Skip Unit or Integration Tests Skip the execution of unit tests: $ mvn compile -DskipTests This will still compile the unit tests...| Relentless Coding
This post talks a little bit about DATE and TIMESTAMP in Oracle and some oftheir pitfalls. TL;DR: Representing dates and timestamps correctly is a very hardproblem (required viewing). Table of Contents Intro DATEs Plain TIMESTAMPs TIMESTAMP WITH LOCAL TIME ZONE TIMESTAMP WITH TIME ZONE Conclusion Using Oracle DATEs in Java Sources Intro When I was tasked with putting some data in BigQuery, Google Cloud’sdata warehouse implementation, I had to look at the data we currentlystore in our local ...| Relentless Coding
In this post, I’m going to aggregate all those Oracle commands that I can neverremember but are very useful to have somewhere written down. Table of Contents Intro Getting Help With sqlplus Connecting to an Oracle Database UsingSQL*Plus Show the Connected User Show All Schema’s Show All Tables/Views in a ParticularSchema Describe a Table Show DDL of a Table Show the Privileges of YourUser Get More Decent Output From aCommand Get and Alter DatabaseTimezones Select DATE Rows in the LastHour...| Relentless Coding
How can we securely provide a password to mysql without exposing it to theworld by just putting it directly in the command? How to Provide a Password to mysql? Recently, I was writing a small Bash program with a GUI (usingzenity) that would promptthe user for their MariaDB credentials and then retrieve someinformation. Passing username and password to the mysql program lookslike: $ mysql -u user -h host -ppassword mydatabase -e 'select 1;' (Note that there cannot be a space between -p and the...| Relentless Coding
I always kind of knew there was a difference between login and non-login shells,but when I couldn’t explain the difference properly to a coworker, I knew Ineeded to spend some time on figuring it out. The difference is addressed nicely in the book Unix Power Tools (Oreilly): When you first log in to a Unix system from a terminal, the systemnormally starts a login shell. A login shell is typically the top-levelshell in the “tree” of processes that starts with the init process.Many charac...| Relentless Coding
You have a drive that you want to encrypt and use in Linux and otherOSes. Then Veracrypt, the successor of Truecrypt, is a good choice. In thistutorial, I will show you how to quickly encrypt a drive and mount and unmountit from the command line. The prerequisite for this tutorial is that you already have created a partitionon a drive. See my previous blogpost on how to accomplish that.Creating a volume on a partition with data on it will permanently destroythat data, so make sure you are enc...| Relentless Coding
Let’s have a look at how we can make certain less preferences permanent,like -I, for example, which will make search case insensitive. The missing $HOME/.lessrc In GNU/Linux, preferences are often stored in rc files. For vim we have.vimrc, for Bash .bashrc, etc: $ find "$HOME" -maxdepth 1 -name '*rc'./.vimrc./.idlerc./.xinitrc./.lynxrc./.old_netrc./.inputrc./.bashrc./.rtorrent.rc./.sqliterc./.xdvirc Environment variable LESS So, it would make sense to expect a .lessrc. But there is none.Ins...| Relentless Coding
We want to make a backup of data, for example to an external hard drive. Rsyncto the rescue. The basic command Assuming we are in someone’s home directory and we want to copy threesource directories Music, Documents and Movies to a destinationdirectory /mnt/external-hdd: $ rsync -a Music Documents Movies /mnt/external-hdd A word on slashes Notice that we omit the trailing forward slash / on the sourcedirectories. This means the destination will look like: /mnt/external-hdd|-- Music| |-- a.m...| Relentless Coding
Say we bought an external hard drive to back up some stuff from acrashed computer. We can use a Live USB to get at the data and put thedata on the external hard drive. Because the data needs to be accessibleby Windows, we are going to use format the drive with NTFS. Create partition Connect the external hard disk to your computer. Use sudo fdisk -l tofind the device name. Output should look something like this: Disk /dev/sdb: 1.8 TiB, 2000398934016 bytes, 3907029168 sectorsDisk model: CT2000M...| Relentless Coding
Creating a Arch Linux live USB is easy. In this post, I will walk you throughdownloading and verifying the image, finding your USB drive and copying theimage onto it, all from the convenience of the command line. Download image and PGP signature Download the latest Arch Linux image from https://www.archlinux.org/download/.The preferred option is to download the image using BitTorrent, in order not toburden the Arch servers unnecessarily. Verify downloaded image $ gpg --keyserver pgp.mit.edu \...| Relentless Coding
In Spring, it’s possible to wire a bean only when some condition is met. A Use Case for Conditional Bean Wiring Suppose we want to enable caching for our web application. We areinterested to find out whether this helps our application or whether theoverhead will so big that it actually slows our application down. Wedecide we want to put the new functionality behind a feature toggle. Weadd a new property to our application calledapp.caching.enabled=false. When we are ready to enable the cach...| Relentless Coding
If we do not want to hard-code values into our source code, we can useproperties files. With the @Value annotation, Spring gives us an easymeans to get properties from properties files and inject them into ourcode. Dependencies This post was written with Spring 5.0.5.RELEASE and Java 1.8.0_181. <dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.0.5.RELEASE</version></dependency> Inject Scalars Let’s say we have the following key-value pairs i...| Relentless Coding
Let’s have a look at how to inject beans using setters with a custom methodname. In a previous blogpost we ended upwith the following XML-based configuration: <?xml version="1.0" encoding="UTF-8" ?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:util="http://www.springframework.org/schema/util"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://...| Relentless Coding
If you have to work with legacy Spring applications, chances are youwill have to know how XML-based configuration works. Although Javaconfiguration is preferred for new applications, sometimes you justdon’t have a choice, so you’d better be comfortable with it. The Code You can find the code from this blog post onGitLab. Dependencies The only dependency you need to get a Spring container running isspring-context. Add in Maven: <dependency><groupId>org.springframework</groupId><artifactId>...| Relentless Coding
privateList<String>strings; When the cursor is on the S of String, use ciW to deleteList<String> and start insert. Obviously, you can use any othercommand with that movement, for example yank the text (yiW) or deleteit (diW). From :help WORD: A WORD consists of a sequence of non-blank characters, separated withwhite space. An empty line is also considered to be a WORD.| Relentless Coding
For new projects, Java configuration is preferred over XML-basedconfiguration. In this post, we’re going to look at how to configure Spring withconfiguration in Java, instead of the traditional XML. For XML-based configuration, see a future blog post. The code You can find the code from this blog post onGitLab. Dependencies The only dependency you need to get a Spring container running isspring-context. Add in Maven: <dependency><groupId>org.springframework</groupId><artifactId>spring-conte...| Relentless Coding
If you have installed moreutils (see below), you can type vidir toopen up the current working directory in your $EDITOR. You can use allthe power of your editor to edit and/or delete filenames anddirectories. Editing a line will rename the file or directory, deletinga line will remove the file or directory. The following will list all your JPEG pictures in the current directoryin your editor: $ vidir *.jpeg vidir is not recursive by default: if you want to recursively editfilenames, you can d...| Relentless Coding
I am someone who has JavaScript disabled by default in his browser (Iuse uMatrix in Firefox for that).Only when I trust a site and I need to use functionality that trulydepends on JavaScript will I turn it on. This hopefully protects me frommost of the known and unknown bad stuff out there on the internet. Italso makes me appreciate people who go through the trouble of makingtheir webpages work without JavaScript. Until recently, I used a JavaScript plugin on this blog to format sourcecode. T...| Relentless Coding
How can remove most of the files in a directory in Bash? $ ls -1153390909910_first15339090991_second15339090992_third15339090993_fourth15339090994_fifth15339090995_sixth15339090996_seventh15339090997_eighth15339090998_nineth15339090999_tenth15339091628_do_not_deleterootroot.sql We want to delete all files that start with a timestamp (seconds sincethe epoch), except the newest file (15339091628_do_not_delete) and thefiles root and root.sql. The easiest way to do this, is enabling theshell opti...| Relentless Coding
I use tomcat7-maven-plugin to spin up a Tomcat 7 container where I canrun my web application. When I added dependencies for log4j2 (version2.11.0) to my project, I got the error: org.apache.tomcat.util.bcel.classfile.ClassFormatException:Invalid byte tag in constant pool: 19 Apparently, log4j2 is a multi-release jar and older versions of Tomcatcan’t handle that. So I needed to upgrade my Tomcat maven plugin. Solution: Update your Tomcat But how do you update your Tomcat? Its informationpage...| Relentless Coding
Ever wanted to test whether a log statement is triggered? Or whether the formatis the way you want? In this post, we’re going to create a custom log appenderso we can be sure logging is behaving the way we expect. /* package declaration, imports... */@Plugin(name="CustomListAppender",category=Core.CATEGORY_NAME,elementType=Appender.ELEMENT_TYPE,printObject=true)publicfinalclassCustomListAppenderextendsAbstractAppender{// for storing the log eventsprivateList<LogEvent>events=newArrayList<>()...| Relentless Coding
Sometimes you want to test if certain log output gets generated whencertain events happen in your application. Here is how I unit test thatusing log4j2 (version 2.11.0). Use LoggerContextRule to get to your ListAppender quickly If you are using JUnit 4, then the quickest solution would be one thatis used by log4j2itself: importorg.apache.logging.log4j.junit.LoggerContextRule;/* other imports */publicclassLogEventTest{privatestaticListAppenderappender;@ClassRulepublicstaticLoggerContextRuleini...| Relentless Coding
If you are working with microservices, you may find that you are havinga lot of dependencies on other services. If you want your tests to beautonomous, that is, running in isolation of those dependencies, you caneither use a tool like WireMock, or you can usea mocking framework. Recently, I came across JMockit, a mockingframework for Java. To mock external dependencies, you can use so-called “fakes”. Say you use aservice that knows the credentials of the customers of your e-store, and you...| Relentless Coding
Sometimes, a little feedback is appreciated when writing some of the morecomplex Bash constructs. The “magic space” is one the things that can help usget quick feedback. What does the “magic space” do? Given the following: $ find -wholename '*/path/to/file' -print -quit$ man rm$ rm -fv !-2:2 In the last line, feedback would be appreciated to see if we are indeedgoing to delete the second argument of two commands back. If you setBash’ so-called “magic space”, history expansion wi...| Relentless Coding
Let’s take a look at how we can test GORM formulas in Grails. The code for this post is part of my PomoTimer project and can befound on GitHub. The domain class We have a domain class Project that models a project that one isworking on when doing a particular work session. It records the name ofthe project (“Writing a blog post”), a status (“active”, “completed”), acreation time, the total time spent on this project and the user theproject belongs to. The total time is a derived...| Relentless Coding
In this post, we’re going to export our contacts fromGoogle in vCard version 3 format, split thecontacts file and use cadaver to upload all files individually to your addressbook. The struggle Last week, I did a fresh install of LingeageOS 14.1 on my OnePlusX and decided not to installany GApps. I have been slowly moving away from using Google servicesand, having found replacements in the form of open-source apps or webinterfaces, I felt confident I would be able to use my phone without aGo...| Relentless Coding
I was attending a meetup that was taking place in a bar in Utrecht. Thefirst thing you want to do is to make a connection to the internet andget started. The location used a captiveportal, however. Youknow: you have the name of the wireless network (SSID) and the password,but when you try to open any web page, you are directed towards a loginpage where you have to accept the terms and conditions of whoever isoperating the network. But what if you use an always-on VPN? You cannot connect to th...| Relentless Coding
Confession: I am the opposite of the lazy coder. I like doing things thehard way. Whether it’s developing Java in Vim without code completion,running JUnit tests on the command line (don’t forget to specify all 42dependencies in the colon-separated classpath!), creating a LaTeX graphthat looks “just right”, or writing sqlplus scripts instead of usingSQL Developer (GUIs are for amateurs), I always assumed that doing sowould make me a better programmer. So when I was just a fledgling pr...| Relentless Coding
Let’s use Groovy’s CliBuilder to create CLI programs that can take flags. Intro I write quite some scripts at work, either for myself or for my team. Iused to write these scripts in Bash, but since we are using Windows atwork, it made sense to switch to a more general scripting language.Because we’re a Java shop, Groovy seemed like a natural choice. Now,it’s often very convenient to have named command-line arguments (e.g.tool --output out.ext --input in.ext) as opposed to positionalar...| Relentless Coding
Need to zip or unzip files? Let’s take a look at how Groovy solves this. Suppose we need to zip a bunch of Python files (without their compiledcounterparts *.pyc). The next (admittedly contrived) example shows howwe could go about doing something like this in Groovy: FilesrcDir=newFile('/home/neftas/Downloads/scripts/')FiledestDir=newFile(srcDir,'antexample')FilezippedFile=newFile(srcDir,'antzipped.zip')defallPythonFilenames=srcDir.list().sort().findAll{it.endsWith('.py')}assert['a.py','b.p...| Relentless Coding
Invoking a method several times can easily be done in Java in a loop.But what if we have several methods that need to be executed severaltimes? Since Java does not feature pointers to functions, we cannot passfunctions around, and cannot create a generic method that takes apointer to a method and executes it. This is where Groovy shines. Suppose we want to check on the status of some external system or work.We want to check the status every half a second for a maximum of tentimes in total. //...| Relentless Coding
Sometimes during development it is useful to use a certificate whose CN(Common Name) does not match the host name in the URL, for examplelocalhost. In these cases Java will throw an SSLHandshakeException.How can we easily disable certificate checking for localhost and otherdomains of our choosing? Your own certificate checking The easiest way is to create your own class that implements theinterface HostnameVerifier: WhitelistHostnameVerifier.java packagecom.relentlesscoding.https;importjavax....| Relentless Coding
In this post, I’ll look at leveraging Intershop’s CustomTag to create customfunctionality in ISML templates. The problem I wanted to capitalize a certain value from the pipeline dictionary inan ISML template. Intershop provides ISML functions of the kind ucaseand lcase to transform a string to uppercase or lowercaserespectively. When the value of the dictionary name Product:Name isAwesomeNotebook: <isprintvalue="#ucase(Product:Name)#"> This will print AWESOMENOTEBOOK. Unfortunately, a sim...| Relentless Coding
Sometimes you need to log in to some webpage programmatically. I ran into one ofthose pages where, when the login succeeds, you’re being redirected to anotherpage, and then to another (something along the lines of ‘Please login’ -> ‘Youare successfully logged in’ -> ‘Admin panel’). So I needed to write somethingthat would store the cookies that come along with each response, and send thosecookies out with each subsequent request. With curl, I would have used: $ curl --location -...| Relentless Coding
A while ago, I needed to write a program that retrieved some information from the database by using SQL queries located in files. I wanted to add a file that would contain the settings of the app, like the port, SID, login and password for the database, but also the location of those queries. The problem was I couldn’t add those settings to a file in the standard src/groovy/resources folder, because when creating a distribution with Gradle ./gradlew distZip the file would be part of the jar...| Relentless Coding
Let’s have a look at another one of those gotchas that can bite you while scripting in Bash: processes that are part of a pipeline all run in subshells.| Relentless Coding