Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Hiten Pratap Singh hitenpratap

🎯
Focusing
View GitHub Profile
@hitenpratap
hitenpratap / td-agent.conf
Created Jun 30, 2020
Fluentd Config File
View td-agent.conf
<source>
type tail
format multiline
format_firstline /[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/
format1 /^(?<datetime>[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}) (?<Thread>\[(.*?)\]) (?<Log-Level>[A-Z]*) (?<Logger>(.+?(?=))) (?<separator>(-)) (?<message>.*)$/
path /log/application-backend-dev.log
pos_file /log/pos/application-backend-dev-multiline.pos
tag spring-boot-logs
</source>
@hitenpratap
hitenpratap / jinja2_filter_reg.py
Created Mar 3, 2020
A code snippet to show how custom jinja2 filters can be registered with the template engine
View jinja2_filter_reg.py
from util.template_filters import calculate_date_date
app.add_template_filter(calculate_date_date)
@hitenpratap
hitenpratap / custom_filters.py
Created Mar 3, 2020
Custom jinja2 filter to calculate age based on the date provided
View custom_filters.py
import datetime
from dateutil.relativedelta import relativedelta
def calculate_date_date(date_str, format_str):
start_date = datetime.datetime.strptime(date_str, format_str)
return relativedelta(datetime.datetime.now(), start_date).years
@hitenpratap
hitenpratap / CustomLog4jAppender.java
Created Jan 16, 2020
Custom Log4J Appender with file deletion feature
View CustomLog4jAppender.java
package com.example.package;
import org.apache.log4j.FileAppender;
import org.apache.log4j.Layout;
import org.apache.log4j.helpers.LogLog;
import org.apache.log4j.spi.LoggingEvent;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
@hitenpratap
hitenpratap / download-latest-blob.sh
Created Jul 3, 2018
Download Latest Blob from a container using Azure CLI
View download-latest-blob.sh
#!/bin/bash
echo "Downloading latest Database dump from Sandbox Server"
AZURE_STORAGE_CONNECTION_STRING=""
AZURE_CONTAINER_NAME=""
AZURE_DB_ZIP_FILE_NAME=$(az storage blob list --connection-string "$AZURE_STORAGE_CONNECTION_STRING" --container-name "$AZURE_CONTAINER_NAME" --query "reverse(sort_by([], &properties.lastModified)[*].{name: name, lastModified: properties.lastModified})[:1]" --prefix "sandbox" | jq '.[0] | {name}.name')
AZURE_DB_ZIP_FILE_NAME=${AZURE_DB_ZIP_FILE_NAME//\"/}
echo $AZURE_DB_ZIP_FILE_NAME
@hitenpratap
hitenpratap / backup_folders.sh
Last active May 28, 2018
Take Backup of folders (e.g.. Tomcat, MySQL and MongoDB etc.) to Azure Storage
View backup_folders.sh
#!/bin/bash
AZURE_STORAGE_CONNECTION_STRING=""
FOLDER_NAME="data_"$(date +'%d-%m-%Y-%H-%M-%S')
MYSQL_USER_NAME="root"
MYSQL_USER_PASSWORD=""
MYSQL_DB_NAME_ARRAY=()
MONGO_DB_NAME_ARRAY=()
FOLDER_BACKUP_ARRAY=()
AZURE_STORAGE_CONTAINER_NAME=""
AZURE_BLOB_NAME="full_backup_"$(date +'%d-%m-%Y')".zip"
@hitenpratap
hitenpratap / removeMySQLMac.sh
Created Oct 19, 2016
Script to remove MySQL completely from Mac(If being installed using non-homebrew method)
View removeMySQLMac.sh
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
rm -rf ~/Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /private/var/db/receipts/*mysql*
@hitenpratap
hitenpratap / variable_scope_angularjs.js
Created Jul 22, 2016
How to use variables with $scope in angularjs
View variable_scope_angularjs.js
//Lets assume value.questionUniqueId is coming from json response
var dataModel = $parse('data_' + value.questionUniqueId);
var dataModel1 = $parse(value.questionUniqueId + '_data');
var labelsModel = $parse('labels_' + value.questionUniqueId);
var seriesModel = $parse('series_' + value.questionUniqueId);
dataModel.assign($scope, ['1', '2', '3', '4', '5']);
dataModel1.assign($scope, ['1', '2', '3', '4', '5']);
labelsModel.assign($scope, [
[3, 0, 1, 4, 6]
]);
@hitenpratap
hitenpratap / package.json
Created Jun 24, 2016
Angular 2 Dependency And Configuration Files
View package.json
{
"name": "angular2-quickstart",
"version": "1.0.0",
"scripts": {
"start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
"lite": "lite-server",
"postinstall": "typings install",
"tsc": "tsc",
"tsc:w": "tsc -w",
"typings": "typings"
@hitenpratap
hitenpratap / sort_xsl_date.xsl
Last active Jan 27, 2016
Sort data in XSLT based on date
View sort_xsl_date.xsl
<xsl:sort select="normalize-space(substring(itpc:StartDate,1,4))" order="descending"/>
<xsl:sort select="normalize-space(substring(itpc:StartDate,6,2))" order="descending"/>
<xsl:sort select="normalize-space(substring(itpc:StartDate,9,2))" order="descending"/>
<!--Suppose date is in format: 2015-11-15T12:22:15-->