Skip to content

Instantly share code, notes, and snippets.

View kannangce's full-sized avatar

Kannan Ramamoorthy kannangce

View GitHub Profile
@kannangce
kannangce / FeignSSLUtils.java
Last active April 3, 2024 09:11
Feign client for 1 or 2-way TLS with self signed certificates when javax.net.ssl.keyStore / javax.net.ssl.trustStore cannot be overridden.
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.AccessController;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
@kannangce
kannangce / StringUtils.java
Last active December 21, 2023 15:31
Custom string utilities.
/**
* Meant to contain the custom utilities related to string. Could be handy in common use cases.
**/
public class StringUtils{
/**
* Searches the given pattern in the given src string and applies the txr to
* the matches.
* <br/>
* <b>Note:</b> Ex, To convert snake case to camel case make the call,
@kannangce
kannangce / gist:0a121cff1c6b40cd72dbd6ab0511e23b
Created November 11, 2023 15:01
Bash script to get the created time of a file.
get_crtime() {
for target in "${@}"; do
inode=$(stat -c '%i' "${target}")
fs=$(df --output=source "${target}" | tail -1)
crtime=$(sudo debugfs -R 'stat <'"${inode}"'>' "${fs}" 2>/dev/null |
grep -oP 'crtime.*--\s*\K.*')
printf "%s\t%s\n" "${target}" "${crtime}"
done
import java.util.function.Function;
import java.util.function.Supplier;
import static java.util.Objects.requireNonNull;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
import static java.util.Collections.emptySet;
/**
* Class containing the functional utils
{
"token": "adsfsadfssfdsdfs"
}
@kannangce
kannangce / utils.clj
Last active September 20, 2022 17:45
Handy Clojure utils functions.
(defn create-matrix
"Creates a multi-dimensional vector with dimensions given in dims
with the given default value"
([default-value & dims]
(loop [val default-value remaining dims]
(if (empty? remaining)
val
(recur (vec (repeat (first remaining) val))
(rest remaining)))
))
@kannangce
kannangce / utils.sh
Last active August 25, 2022 07:36
Handy utility scripts
## Handy utility scripts.
retry_with_timeout () {
# Retries the given command until it returns the given value for the given number of times.
# Usage retry_with_timeout 'Command to be executed with quotes' <expected value> <number of times to retry>
local command_to_try="$1"
local expected_value="$2"
local expected_timeout="$3"
local total_time=0
[
{
"id": "f1",
"name": "Restel Site Contact form",
"description": "Contact us form in restel site.",
"integrations": [
"Mail",
"Telegram"
]
},
;; The below macro could have been simple function. Keeping it for reference though
(defmacro create-matrix
"Clojure macro to create a matrix with any number of dimension"
([x & dim]
(loop [ex ['->> x] d dim]
(if (empty? d)
(apply list ex)
(recur (into ex [`(repeat ~(first d)) 'vec])
(rest d)))
))
@kannangce
kannangce / GenericResultSetExtractor.java
Created August 27, 2018 10:22
A generic ResultSetExtractor to be used with Spring's JdbcTemplate for any simple beans.
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Supplier;
import org.springframework.dao.DataAccessException;