Skip to content

Instantly share code, notes, and snippets.

View kruttik-lab49's full-sized avatar

kruttikaggarwal kruttik-lab49

View GitHub Profile
@kruttik-lab49
kruttik-lab49 / spring-value.md
Last active August 3, 2021 17:47
TWL-Lab49/Spring - Injecting properties as a list with default value using value annotation

Suppose you want to inject a list of values in your bean. You can do-

#prop file
mylist=x,y,z

#bean
@Value("${myList}")
String[] myList;
@kruttik-lab49
kruttik-lab49 / tg-refactor-state.md
Last active January 29, 2021 20:41
TWL-Lab49/Terraform & Terragrunt folder refactoring & state management trick

Suppose you have a terraform/terragrunt directory that you have already applied. Now you want to move the directory to some other destination.

Here's what you can do-

  • Ensure the to-be-refactored module has no pending changes terragrunt plan should output No Changes
  • Pull the current state into a temp file terragrunt state pull > /tmp/local.tfstate
  • Move (or Copy) the terragrunt module folder to the desired location
  • Run terragrunt plan in the new folder. This should show you all the changes that terragrunt will make to your infrastructure. This makes sense since you haven't yet migrated the terraform state and terraform therefore thinks its a new infrastructure
  • Upload the state. Run terragrunt state push /tmp/local.tfstate. you should notice that the command outputs successfully. At this point the state is committed to terraform remote state bucket
  • Run terragrunt plan to ensure that this time it shows No Changes
@kruttik-lab49
kruttik-lab49 / test.md
Last active January 20, 2021 17:15
This is a test

This is a test

@kruttik-lab49
kruttik-lab49 / pydiagrams.md
Last active January 7, 2021 23:34
TWL-Lab49/Python Diagrams - An Alternative to plantuml

There have been quiet a few posts on plantuml(1, 2) and don't get me wrong I quiet liked it myself (here's one I wrote). But let's face it, the diagrams aren't pretty, and it lacks visual componants from popular platforms like AWS icons, SASS providers etc. And while you can add custom features to plantuml using stylesheets, it's really not fun.

In comes Diagrams, a python library which is feature rich.

Here's an exmaple, lifted right out of the documentation-

sample

from diagrams import Cluster, Diagram
@kruttik-lab49
kruttik-lab49 / sqs-activemq.md
Last active November 20, 2020 14:49
TWL-Lab49/Swapping AWS SQS with ActiveMQ for sandbox using spring profile

When working with messaging (Queue/Topic) applications based on AWS SQS, it is often desirable to run sandbox (local development machine) at parity with the real environment. Since it is operationally challenging to create AWS SQS resources from both costing and planning perspectives, what usually ends up happening is that local instances of applications (producers and consumers) start using the same queue as those by the deployed instances (usually dev). This leads to many problems including the most obvious one where messages are processed by random listeners.

This can easily be solved by declaring conditional beans in spring and swapping the JMS provider based on properties (e.g. spring profile)

Here's a before-

//App A (producer)
@Configuration
public class JMSConfig {
  @Bean
@kruttik-lab49
kruttik-lab49 / iframe-onload.md
Last active November 18, 2020 22:09
TWL-Lab49/ Iframe onload event for attachments

I had to write a javascript function that on-click of a button downloads a pdf file and on-success shows a message. I followed the usual pattern-

const download = (url) -> {
  $(`<iframe src=${url} frameborder=0 scrolling="no" id="someid"`)
    .load(() -> {
      //show the success message
      $(this).remove;
    }).appendTo('body')
}
@kruttik-lab49
kruttik-lab49 / artifactmgmt.md
Last active October 23, 2020 21:21
TWL-Lab49/ Open source artifact management tools

When setting up an enterprise CI/CD, we have to setup an artifact management platform in addition to the standard CI/CD tools like Jenkins, TeamCity, Gitlab CI etc. Unfortunately, unlike the CI/CD tools where there are a veriety of options; the artifact repository options are insanely limited, esp. if you add the additional constraint of open source.

Note that the repositories have to be private for most enterprises which rules out SaaS providers

Options

@kruttik-lab49
kruttik-lab49 / how-to-post.md
Last active September 30, 2020 21:45
TWL-Lab49/How to post a TWL using Github gists

logo

TWL posts are fetched from the GitHub API, and the visibility of posts is based on a few parameters:

  1. The author is part of the Lab49 GitHub organization, or is whitelisted as a guest or alumnus
  2. The title of the Gist starts with "TWL-Lab49/"
  3. The Gist is public

Post guidelines

Start your post title with "TWL-Lab49/". Your post title should look something like this:

@kruttik-lab49
kruttik-lab49 / pr-suggestion.md
Last active September 29, 2020 16:17
TWL-Lab49/code review comments vs suggestion

Suppose, you see a typo or logic error in a PR-

if(str == "somevalue"){
  // do something
}

Clearly, this is a forgivable (some might say unforgivable) developer oversight. Generaly, we add a comment to such PRs as follows-

Logic error. Change to str.equals()
@kruttik-lab49
kruttik-lab49 / blacklist-test.md
Last active September 30, 2020 18:24
TWL-Lab49/Blacklist Example

This should never show up because this is blacklisted