Skip to content

Instantly share code, notes, and snippets.

@aimtiaz11
aimtiaz11 / index.js
Created April 3, 2020 01:11
NodeJS : HTTP request with content from file
const fs = require('fs');
const axios = require('axios'); // need to npm install
const https = require('https'); // need to npm install
const uuid = require('uuid'); // need to npm install
// 5.1 mb file
let fileContent = fs.readFileSync('fp_dc_setup_guide.txt', 'utf8');
console.log(`File length: ${fileContent.length} characters.\nFile Size: ${ (Buffer.byteLength(fileContent, 'utf8') / (1024*1024)) } MB`);
@aimtiaz11
aimtiaz11 / inst.md
Last active June 3, 2020 06:12
Generate SSL Cert

Generate SSL Cert

openssl genrsa -out server.key 2048
openssl req -new -x509 -key server.key -out server.cert -days 3650 -subj /CN=www.example.com
@aimtiaz11
aimtiaz11 / index.js
Created March 5, 2020 02:10
Node Axios - HTTP Request Example
var fs = require('fs');
const axios = require('axios');
const https = require('https');
const uuid = require('uuid');
// Read base64 file content
// 5.1 mb file
let fileContent = fs.readFileSync('5mb.txt', 'utf8');
@aimtiaz11
aimtiaz11 / vm-queue.xml
Last active August 1, 2019 01:15
Parallel Processing in Mule 3
<flow name="example_splitterFlow">
<inbound-endpoint exchange-pattern="one-way" host="localhost" port="8081" doc:name="HTTP" />
<set-payload value="#[['1','2','3','4']]" doc:name="Set Payload" />
<collection-splitter doc:name="Collection Splitter" />
<outbound-endpoint exchange-pattern="one-way" path="test" doc:name="VM" />
</flow>
<flow name="example_splitterFlow1">
<inbound-endpoint exchange-pattern="one-way" path="test" doc:name="VM" />
<logger message="START #[payload]" level="INFO" doc:name="Logger" />
<logger message="#[Thread.sleep(5000)]" level="INFO" doc:name="Logger" />
@aimtiaz11
aimtiaz11 / _readme.md
Last active January 27, 2022 23:21
Compare Properties Files Using Groovy

Compare application properties files in Groovy

This script below allows you to compare properties files between environments.

If you maintain your application's externalised properties file in a seperate repository with a structure similar to below, you can use this to compare properties file between different environment.

compare-properties.groovy
|- src
|	|- main
|	|	|- resources
@aimtiaz11
aimtiaz11 / java-collection-performance.md
Last active April 3, 2019 11:00
Big 0 Summary - Java Collections

Big 0 Summary - Java Collections

Collected from various sources.

LinkedList

  1. get(int index) is O(n) (with n/4 steps on average)
  2. add(E element) is O(1)
  3. add(int index, E element) is O(n) (with n/4 steps on average), but O(1) when index = 0 <--- main benefit of LinkedList
  4. remove(int index) is O(n) (with n/4 steps on average)
@aimtiaz11
aimtiaz11 / timing-code.groovy
Created March 30, 2019 00:06
Groovy Code Execution Time
long startTime = System.nanoTime()
// write some code
long endTime = System.nanoTime()
long duration = endTime - startTime
println("Code executiont ime: " + duration)
@aimtiaz11
aimtiaz11 / upload-files.sh
Last active November 10, 2018 00:03
Script to upload all (html) files of a directory to AWS S3
#!/bin/bash
# This script uploads all HTML file and uploads them in AWS s3 by including the directory structure.
# Ensure bucket is created via TF before adding to array below
envList=("mock" "dev" "test" "uat")
# Helper function to check if value exists in array
function contains() {
@aimtiaz11
aimtiaz11 / readme.md
Last active December 12, 2018 12:33
Jasypt Encryption & Decryption

Jayspt Encryption & Decryption

Add the following functions to your ~/.bash_profile:

Encrypt

encrypt(){
    /Users/ai/jasypt-1.9.2/bin/encrypt.sh \
    input="$1" \
    password="somesupersecretpassword" \
 stringOutputType="hex"
@aimtiaz11
aimtiaz11 / templating.groovy
Last active August 28, 2018 00:31
Groovy Templating
def binding = [
"id": "1",
"firstName": "John"
]
String substitute(text, map) {
def template = new groovy.text.StreamingTemplateEngine().createTemplate(text)
return template.make(map)
}