Skip to content

Instantly share code, notes, and snippets.

@jatin-lab49
jatin-lab49 / image-base64.md
Created June 23, 2021 13:13
TIL-Lab49/Get a base64 version of image file locally

Maybe this is common knowledge. For most cases whenever I needed a base64 version of an image to use in a webpage, I used one of those online sites to get it.

Recently on a client project I wasn't sure if I wanted to upload their images on an unknown site. So I did a quick Google (fine, stackoverflow) and found that we can just run this on most Linux style systems.

cat image-file.jpg | base64

Also works on macOS and for other image types

@jatin-lab49
jatin-lab49 / apache-tika-basics.md
Created June 4, 2021 15:10
TIL-Lab49/Using Apache Tika for file type validation

We recently had a security team ask us to validate that the file being uploaded was indeed a plain text file. To do this, we decided to use Apache Tika.

The code itself is fairly straightforward:


import org.apache.tika.config.TikaConfig;
import org.apache.tika.exception.TikaException;
import org.apache.tika.io.TikaInputStream;
import org.apache.tika.mime.MediaType;
import org.apache.tika.metadata.MetaData;
@jatin-lab49
jatin-lab49 / quartz-one-job.md
Created November 24, 2020 19:27
TIL-Lab49/Ensuring only one Quartz scheduled job runs at one time

With the advances in Lambda and ECS task scheduling, I have not needed to use the trusty Quartz library for the past few years. I recently had to use it though in a project, and realized that the next job was starting when the current job was still running.

Thankfully with Spring, Quartz 2 makes this really easy. Just add the @DisallowConcurrentExecution to your job.

package com.lab49.example;

import org.quartz.DisallowConcurrentExecution;
import org.quartz.job;
@jatin-lab49
jatin-lab49 / unzip-with-jar.md
Last active September 3, 2020 20:51
TIL-Lab49/Unzip jar file without unzip command inside a docker image

While triaging a running docker container, I was trying to check if a jar file had the correct properties file inside it.

I found the jar file and when I ran the handy unzip command, I got this error:

service@3f50ceae48d2:/tmp$ unzip micro-service.jar 
bash: unzip: command not found

Now, usually I would just go ahead and apt-get install unzip in a Ubuntu container like this. But I was not root, so ran into another issue:

@jatin-lab49
jatin-lab49 / shared-symlink.md
Created August 17, 2020 14:47
TIL-Lab49/Symlink errors in NodeJS projects on shared folders in Virtualbox
@jatin-lab49
jatin-lab49 / git-rebase-onto.md
Last active December 26, 2023 09:19
TIL-Lab49/Rebase --onto to avoid dependent branch conflicts after squash merge

So, I love to squash commits for a feature branch when it is merged to develop (and then eventually to master). This works well if your Pull Requests (or Merge requests on Gitlab) are accepted and merged relatively quickly. Often though, I end up in this scenario:

  1. develop -> on commit A
  2. featureOne -> commit B-C-D added
  3. Pull request opened for featureOne against develop
  4. Need to start working on featureTwo branch which depends on featureOne
  5. featureTwo -> commit E-F-G added
  6. Pull request for featureOne against develop gets merged and squashed
@jatin-lab49
jatin-lab49 / intellij-thread-dump.md
Created June 22, 2020 20:40
TIL-Lab49/Stop IntelliJ printing Java thread dump to console

On a new Ubuntu VM, I noticed my fresh install of IntelliJ was printing a lot of logs to the console. After playing around with the existing projects logging configuration etc, I still could not squelch logs that began with:

2020-06-18 16:07:08
Full thread dump OpenJDK 64-Bit Server VM (25.252-b09 mixed mode):

I finally realized IntelliJ was attaching itself to the process, and this issue helped me figure out how to stop that: https://youtrack.jetbrains.com/issue/IDEA-203543

The trick is to disable the debugger.attach.to.process.action registry key in IntelliJ. You can do this as follows:

  1. Open IntelliJ Help menu and click on Find Action...
@jatin-lab49
jatin-lab49 / gradle-compilecache-error.md
Created June 22, 2020 20:32
TIL-Lab49/Recovering from Gradle "Cannot lock Java compile cache"

Ran into a weird issue today where I was refactoring a lot of Java classes. Trying to run Gradle build via IntelliJ kept failing.

The error was:

> Task :compileJava FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
@jatin-lab49
jatin-lab49 / docker-image-pull.md
Last active June 22, 2020 20:34
TIL-Lab49/Docker image pull with private registry

Sometimes, if you are behind a corporate proxy - docker pull fails to download images from dockerhub with an error like below:

$ sudo docker pull swaggerapi/swagger-codegen-cli
Using default tag: latest
Error response from daemon: Get https://registry-1.docker.io/v2/: read tcp 10.0.2.15:50136->3.223.220.229:443: read: connection reset by peer

You can check if the image is in your private registry by prepending the private docker hub before the image and checking if it works.

@jatin-lab49
jatin-lab49 / multi-artifact-gradle.md
Last active June 2, 2020 20:25
TIL-Lab49/Upload Multiple Artifacts via Gradle

Upload Multiple file artifacts with one Gradle file

I ran into an issue where the deploy process needed to download multiple configuration files from artifactory. To upload these files to artifactory, I used the artifacts block in the build.gradle file as below:

project.group='com.lab49.example'
version='0.0.1-SNAPSHOT'

def devFile = file("./environments/dev/redirects.config.json")