Skip to content

Instantly share code, notes, and snippets.

View kuntalchandra's full-sized avatar
🎯
Focusing

Kuntal Chandra kuntalchandra

🎯
Focusing
View GitHub Profile
@kuntalchandra
kuntalchandra / trap-error
Created August 23, 2017 11:51
bash: Trap error and exit
#!/bin/bash
trap "exit 1" TERM
TOP_PID=$$
function alert()
{
echo "Do something"
kill -s TERM $TOP_PID
}
@kuntalchandra
kuntalchandra / check-premium.bash
Created September 11, 2017 12:42
Basic program to send desktop notifications in Ubuntu
#!/bin/bash
COUNT=`php /etc/checkDuePremium.php`
if [ $COUNT -gt 0 ]
then
notify-send 'Hello Kuntal!' "$COUNT premium is due. Check your inbox for details" --icon=dialog-information
echo insurance reminder job ran at `date` >> /var/log/custom.log
fi
@kuntalchandra
kuntalchandra / mysqlCsvConverter.php
Created September 11, 2017 13:18
MySQL to CSV Converter
<?php
$exportData = [
'db0' => ['table0', 'table1'],
'db1' => ['table0']
];
$user = 'test';
$password = 'test123';
$host = '127.0.0.1';
@kuntalchandra
kuntalchandra / branchPredictionPerformance.php
Created September 12, 2017 08:42
Why if/else block should be avoided in loop, if possible.
<?php
$sortedSet = range(1, 10000000);
$randomSet = $sortedSet;
shuffle($randomSet);
$cnt = count($sortedSet);
$filter = $cnt / 2;
$sortedSetChunks = array_chunk($sortedSet, $filter);
$randomSetChunks = array_chunk($randomSet, $filter);
@kuntalchandra
kuntalchandra / referenceTest.php
Created September 14, 2017 13:19
How variable reference works in PHP: Deep or shallow copy
<?php
//example of shallow copy
$arr = array(1, 2);
$arr1 = &$arr;
$arr1[0]++;
echo "\nCopied by reference\n";
echo $arr[0], "\n";
echo $arr1[0], "\n";
@kuntalchandra
kuntalchandra / convert-mkv-avi.sh
Last active January 12, 2018 05:20
Convert mkv file to avi file. Applicable to a list of files. Uses xargs for parallel processing.
#!/bin/bash
shopt -s nullglob
source_files=(/home/kuntal/Videos/Tom.and.Jerry.The.Golden.Collection.Volume.One.720p.BluRay/*.mkv)
convert() {
source_file=$(echo $0 | cut -f1 -d:)
target_file=$(echo $0 | cut -f2 -d:)
echo "source file: $source_file"
ffmpeg -i $source_file $target_file
echo "converted file: $target_file"
@kuntalchandra
kuntalchandra / image_resizer.py
Last active June 4, 2019 20:24
Parallel processing using multiprocessing and multithreading
import concurrent.futures
from PIL import Image
from resizeimage import resizeimage
from os import listdir, getpid
from os.path import isfile, join
SOURCE_DIR = '/var/tmp/source/'
TARGET_DIR = '/var/tmp/target/'
MAX_PROCESSES = 4
MAX_THREADS = 2
@kuntalchandra
kuntalchandra / DiamondProblemRevisited.java
Created August 22, 2019 08:20
How the diamond problem is handled when Java 8 introduced the default method implementation in interface
interface Poet {
default void write() {
System.out.println("Poet writes poems");
}
}
interface Writer {
default void write() {
System.out.println("Writer writes stories");
}
@kuntalchandra
kuntalchandra / pull_request_template.md
Last active August 22, 2019 10:46
Pull request template

PR Checklist

A self-explanatory title describing what the pull request does. If possible, provide the link of the epic in the description, will be helpful to the reviewer e.g.

  • 1. Does the design meet the expectation?
  • 2. Do we have the required test coverage?
  • 3. Have domain-oriented test cases been reviewed by an analyst?
  • 4. Does the PR address the targetted issue and not a mix of multiple issues etc.?

Motivation

  • Explain the context and purpose e.g. Does the design follow OCP so that in near future it can be extended easily?
@kuntalchandra
kuntalchandra / recursion.c
Last active December 3, 2019 12:50
How does recursion work. Guess the output :)
#include <stdio.h>
void print_recursive(int n);
int main() {
print_recursive(7);
}
void print_recursive(int n) {
if (n <= 0) {