Skip to content

Instantly share code, notes, and snippets.

View kannangce's full-sized avatar

Kannan Ramamoorthy kannangce

View GitHub Profile
@kannangce
kannangce / Command Line utils.adoc
Last active March 15, 2019 05:25
Contains quick command line utils that will be required for some scenarios that I faced. Some times the equivalent site I used is also mentioned

Start all the docker containers

docker ps -a|tail -n +2|awk '{print $1}'|xargs docker start

Diff

This gives side-by-side diff.

diff -y file_1 file_2

@kannangce
kannangce / sieve-of-eratosthenes.clj
Last active April 11, 2019 12:48
Sieve of Eratosthenes in clojure
(defn multiple?
"Check if the number-to-check is a multiple of number."
[number-to-check number]
(= 0 (mod number-to-check number)))
(defn sieve-of-eratosthenes
"For the number ranging from 2 to the given number 'upto'(inclusive),
filters out all the numbers that are not prime and
return the prime numbers."
[upto]
@kannangce
kannangce / custom-comp.clj
Created May 4, 2019 06:14
Custom implementation of clojure 'comp'.
(defn custom-comp
"Custom implementation of clojure 'comp'.
Accepts a set of functions and returns a composite of
those functions.
ex, ((custom-comp f1 f2 f3) some-argument) = (f1(f2(f3(some-argument))))"
[& fns]
(fn [& params]
(loop [fn-list fns
@kannangce
kannangce / RespectSigPipe.java
Created October 1, 2019 20:00
Showcase on capturing and making use of SIG_PIPE
import sun.misc.Signal;
import sun.misc.SignalHandler;
/**
* Demo on making use of SIG_PIPE
*
*/
public class RespectSigPipe
{
static boolean isPipeRecieved = false;
@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;
;; 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)))
))
[
{
"id": "f1",
"name": "Restel Site Contact form",
"description": "Contact us form in restel site.",
"integrations": [
"Mail",
"Telegram"
]
},
@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
@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)))
))
{
"token": "adsfsadfssfdsdfs"
}