Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
echo "Hello World! This is my first shell script"
NAME="Ashutosh"
SPORT="Power"
echo "My name is $NAME, he likes ${SPORT}lifting"
# User input comment
# read -p "Enter your favourite food & carb source: " DISH CARB
# echo "$NAME likes $DISH & $CARB"
# count employees with department IT
awk -F '|' 'tolower($3) == "it" {count++} END {if(count==0) {print 0} else {print count}}'
# print found if college1
awk -F '-' 'tolower($1)=="college1" {print "Found"}'
# print total
awk -F '-' '
NR >= 1 {total+=$2} END {print total}
'
import java.util.*; // at top line
public static List<Integer> getTotalExecutionTime(int n, List<String> logs){
int[] result = new int[n];
Stack<Integer> stack = new Stack<>();
int prevTimestamp = 0;
for (String log : logs) {
String[] logParts = log.split(":");
int functionId = Integer.parseInt(logParts[0]);
SELECT
CONCAT("*.", ft.extension) AS extension,
SUM(CASE WHEN qd.filetype_id IS NOT NULL THEN 1 ELSE 0 END) AS quantumsafe_total_detections,
SUM(CASE WHEN wd.filetype_id IS NOT NULL THEN 1 ELSE 0 END) AS webguardian_total_detections
FROM file_types ft
LEFT JOIN quantumsafe_detections qd ON ft.id = qd.filetype_id
LEFT JOIN webguardian_detections wd ON ft.id = wd.filetype_id
WHERE YEAR(qd.dt) = 2023
AND MONTH(qd.dt) = 7
GROUP BY ft.extension
public static String filter(List<String> passwords) {
List<String> validPasswords = new ArrayList<>();
List<String> invalidPasswords = new ArrayList<>();
for (String password : passwords) {
if (isInvalidLength(password) || hasOnlyNumbers(password) || hasOnlyCharacters(password)) {
invalidPasswords.add(password);
} else {
validPasswords.add(password);
}
static int DifferenceSumOfDigits(int[] arr){
int f1=0, f2=0;
for(int i=0;i<arr.length;i++){
f1+=sumDigit(arr[i]);
f2+=arr[i];
}
f1 %= 10;
f2 %= 10;
return f1 - f2;
const port = 4000;
/**
*
* NOTE: PLEASE COMMENT ONE SERVER AS BOTH CAN'T WORK SIMULTANEOUSLY.
*/
/** FASTIFY SERVER */
const fastify = require('fastify')({ logger: true });
static String solve(String s1, String s2, String s3) {
if (s1.length() != s2.length() || s1.length() != s3.length() || s2.length() != s3.length()) {
return "NO";
}
HashMap<Character, Integer> firstFreq = countFrequency(s1);
HashMap<Character, Integer> secondFreq = countFrequency(s2);
HashMap<Character, Integer> thirdFreq = countFrequency(s3);
boolean areEqual = firstFreq.equals(secondFreq) && secondFreq.equals(thirdFreq);
import java.util.Arrays;
/**
* MergeSort
*/
class MergeSort {
public static void main(String[] args) {
int[] arr = { 2, 4, 1, 6, 8, 5, 3, 7 };
mergeSort(arr, arr.length);
System.out.println(Arrays.toString(arr));
import java.util.Arrays;
public class QuickSort {
public static void main(String[] args) {
int[] arr = { 2, 4, 1, 6, 8, 5, 3, 7 };
quickSort(arr, 0, arr.length - 1);
System.out.println(Arrays.toString(arr));
}
static void quickSort(int[] arr, int start, int end) {