Skip to content

Instantly share code, notes, and snippets.

View DineshSolanki's full-sized avatar
:octocat:
Looking for java roles

Dinesh Solanki DineshSolanki

:octocat:
Looking for java roles
View GitHub Profile
@DineshSolanki
DineshSolanki / minIndexOfColumnsOfRow.kt
Last active November 24, 2020 13:22
Kotlin Extension function to find index of minimum value of given row of 2D array
fun Array<DoubleArray>.minIndexOfColumnsOfRow(rowNumber: Int): Int {
var minNum = this[0][rowNumber]
var minIndex = 0
repeat(this.size)
{ x ->
if (minNum > this[x][rowNumber]) {
minIndex = x
minNum = this[x][rowNumber]
}
}
@DineshSolanki
DineshSolanki / BufferedImage.getTransposed.kt
Created October 7, 2020 16:13
Kotlin BufferedImage extension function to transpose image.
fun BufferedImage.getTransposed(): BufferedImage {
val transposeImage = BufferedImage(this.height, this.width, BufferedImage.TYPE_INT_RGB)
repeat(transposeImage.width) { w ->
repeat(transposeImage.height) { h ->
transposeImage.setRGB(w, h, this.getRGB(h, w))
}
}
return transposeImage
}
@DineshSolanki
DineshSolanki / FileReaderSupport.kt
Created October 13, 2020 15:13
Gist to show implementation towards FileReader support for Kweb-core https://github.com/kwebio/kweb-core/issues/165
fun InputElement.setAccept(acceptedTypes: String): Unit = element.execute("$jsExpression.accept=\"$acceptedTypes\";")
fun InputElement.multiple(isMultiple: Boolean): Unit = element.execute("$jsExpression.multiple=\"$isMultiple\";")
//Usage-
input(InputType.file).let {
it.setAccept("audio/*")
it.multiple(true)
}
#!/bin/bash
# Ask the user for maven binary link
echo "Please input maven binary link : ex-https://archive.apache.org/dist/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz"
echo
read mavenLink
echo You entered $mavenLink
wget $mavenLink -P /tmp
sudo tar xf /tmp/apache-maven-*.tar.gz -C /opt
@DineshSolanki
DineshSolanki / killports.sh
Created May 23, 2021 11:21
Kill applications that uses given ports
#!/bin/bash
if [ $# -eq 0 ]; then
echo "No ports provided"
exit 1
fi
for var in "$@"
do
sudo kill -9 $(sudo lsof -t -i:${var})
echo "Process using port ${var} was killed"
done
@DineshSolanki
DineshSolanki / gitcommit.sh
Created May 23, 2021 11:23
Extract and commit with jira ID in commit message if jira id exist in branch name
#!/bin/bash
if [ $# -eq 0 ]; then
echo "No commit message provided"
exit 1
fi
branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
IFS='/' read -r id bname<<< "$branch"
if test -z $bname
then
IFS='_' read -r id bname<<< "$branch"
@DineshSolanki
DineshSolanki / backmerge.sh
Created May 23, 2021 11:26
Backmerge current branch with master/developer or any branch
#!/bin/bash
branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
IFS='/' read -r id bname <<< "$branch"
IFS='_' read -r id bname <<< "$bname"
git update-index -q --refresh
if ! git diff-index --quiet HEAD --; then
echo "Working directory not clean, please commit your changes first"
exit
fi
echo "-------------------------------------------------------------------------"
#!/bin/bash
if [ $# -eq 0 ]; then
echo "No jira id provided"
exit 1
fi
nohup xdg-open http://jira.yourdomain.com/browse/${1}
#usage - openJira.sh jiraid
@DineshSolanki
DineshSolanki / ZipExeInDirSeparately.ps1
Created August 4, 2021 16:09
This powershell scrip archives all exe present in directory to individual zip.
dir *.exe | ForEach-Object { & "$($env:ProgramFiles)\7-Zip\7z.exe" a -tzip "$($_.BaseName).zip" $_.Name }
@DineshSolanki
DineshSolanki / GetCountryMobileNumberMask.cs
Created September 13, 2021 09:44
Get country mobile number mask using libphone
//https://www.nuget.org/packages/libphonenumber-csharp
public static string GetMobileMask(string regionCode) // "IN"
{
try
{
var exampleNumber = PhoneNumberUtil.GetExampleNumberForType(regionCode, PhoneNumberType.MOBILE);
var formattedNumber = PhoneNumberUtil.FormatNumberForMobileDialing(exampleNumber, regionCode, true)[1..];
var mask = Regex.Replace(formattedNumber, @"\d", "0"); //change 0 to whatever you want, my controls treats 0 as any digit
return mask; //"00000 0000"
}