Skip to content

Instantly share code, notes, and snippets.

@yashb042
yashb042 / sample_subscribe
Last active May 6, 2024 10:55
Subscribe request to ONDC
{
"context": {
"operation": {
"ops_no": 1
}
},
"message": {
"entity": {
"address_of_authorised_signatory": "LP",
"callback_url": "/",
<!-- From here the AOP dependencies start&ndash;&gt;-->
<dependency>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-aspects</artifactId>
<version>0.22.6</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
package org.example;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import java.lang.reflect.Method;
@Aspect
@yashb042
yashb042 / NoobDeveloperCode.java
Last active October 17, 2023 05:07
Noob Developer Execution Time logging
package org.example;
public class NoobDeveloperCode {
public void f1() {
long startTime = System.currentTimeMillis();
// This is the code that we want to measure
System.out.println("I am doing some basic tasks");
// The code ends here
#!/bin/bash
mkdir dependencies
#Download all required dependencies
python3 -m pip install -t dependencies/python/lib/python3.7/site-packages selenium==3.8.0
curl -SL https://chromedriver.storage.googleapis.com/2.37/chromedriver_linux64.zip > dependencies/chromedriver.zip
curl -SL https://github.com/adieuadieu/serverless-chrome/releases/download/v1.0.0-41/stable-headless-chromium-amazonlinux-2017-03.zip > dependencies/headless-chromium.zip
unzip dependencies/chromedriver.zip -d dependencies
@yashb042
yashb042 / lambda_function.py
Last active July 7, 2023 12:21
Selenium Lambda Function
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
def lambda_handler(event, context):
options = Options()
options.binary_location = '/opt/headless-chromium'
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--single-process')
options.add_argument('--disable-dev-shm-usage')
public class BasicApp {
public static void main(String[] args) {
long l = System.currentTimeMillis();
for (int i = 0; i < 100_000_000; i++) {
}
long l2 = System.currentTimeMillis();
System.out.println("Time(in millis) taken to run empty for-loop, 1 Billion iterations - " + (l2 - l));
System.out.println("File end Reached");
}
void runVirtual() throws Exception {
for (; ; ) {
long start = System.currentTimeMillis();
try (var executor = Executors.newVirtualThreadPerTaskExecutor()) {
for (int i = 0; i < 100_000_0; i++) {
executor.submit(() -> {
callExternalService();
return null;
});
}
void runConventional() throws Exception {
for (; ; ) {
long start = System.currentTimeMillis();
try (var executor = Executors.newFixedThreadPool(1000)) {
for (int i = 0; i < 100_000_0; i++) {
executor.submit(() -> {
callExternalService();
return null;
});
}