Skip to content

Instantly share code, notes, and snippets.

View hitenpratap's full-sized avatar
🎯
Focusing

Hiten Pratap Singh hitenpratap

🎯
Focusing
View GitHub Profile
@hitenpratap
hitenpratap / csv-splitter.sh
Created November 8, 2023 14:16
A bash script to split a CSV file into equals part, it also put the headers automatically into each of the newly generated file
#!/bin/bash
# Check if a file path is provided
if [ -z "$1" ]; then
echo "Usage: $0 <csv_file>"
exit 1
fi
csv_file="$1"
@hitenpratap
hitenpratap / jobrunr-requeue-failed-jobs.kt
Created November 8, 2023 14:14
A code snippet to requeue all the failed jobs in JobRunr
import org.jobrunr.jobs.states.StateName
import org.jobrunr.storage.PageRequest
import org.jobrunr.storage.StorageProvider
import org.springframework.stereotype.Service
@Service
class FailedJobEnqueuer(
private val storageProvider: StorageProvider,
) {
fun requeueFailedJobs(): List<String> {
@hitenpratap
hitenpratap / td-agent.conf
Created June 30, 2020 15:08
Fluentd Config File
<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 March 3, 2020 18:47
A code snippet to show how custom jinja2 filters can be registered with the template engine
from util.template_filters import calculate_date_date
app.add_template_filter(calculate_date_date)
@hitenpratap
hitenpratap / custom_filters.py
Created March 3, 2020 18:42
Custom jinja2 filter to calculate age based on the date provided
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 January 16, 2020 10:43
Custom Log4J Appender with file deletion feature
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 July 3, 2018 09:36
Download Latest Blob from a container using Azure CLI
#!/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 12:16
Take Backup of folders (e.g.. Tomcat, MySQL and MongoDB etc.) to Azure Storage
#!/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 October 19, 2016 14:28
Script to remove MySQL completely from Mac(If being installed using non-homebrew method)
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 July 22, 2016 07:06
How to use variables with $scope in angularjs
//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]
]);