Skip to content

Instantly share code, notes, and snippets.

View iKunalChhabra's full-sized avatar
🚀
Working on something great !

Kunal Chhabra iKunalChhabra

🚀
Working on something great !
View GitHub Profile
@iKunalChhabra
iKunalChhabra / main.kt
Created December 9, 2024 10:43
Kotlin connect to Postgres
package org.example
import java.sql.DriverManager
fun main() {
val rows: List<Map<String, Any?>>
DriverManager.getConnection("jdbc:postgresql://localhost:5432/myapp", "myapp", "password").use { connection ->
connection.createStatement().use { stmt ->
stmt.executeQuery("select * from salesforce.account").use { rs ->
rows = generateSequence {
@iKunalChhabra
iKunalChhabra / main.kt
Created November 29, 2024 09:11
Consumer Producer in Kotlin Coroutine using channels
package com.example
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import kotlin.random.Random
fun main(){
val channel = Channel<Int>(2)
runBlocking {
launch { produceValue(channel, 5) }
@iKunalChhabra
iKunalChhabra / index.js
Created November 24, 2024 06:20
ES 6 Style import express app with websocket and data validation
import express from 'express';
import http from 'http';
import { WebSocketServer } from 'ws';
import fetch from 'node-fetch';
import Joi from 'joi';
const app = express();
const server = http.createServer(app);
const wss = new WebSocketServer({ server });
@iKunalChhabra
iKunalChhabra / index.js
Created November 24, 2024 05:23
WebSocket in Express Node JS
const express = require('express');
const http = require('http');
const WebSocket = require('ws');
const app = express();
const server = http.createServer(app);
const wss = new WebSocket.Server({ server });
const PORT = process.env.PORT || 3000;
@iKunalChhabra
iKunalChhabra / kotlin_coroutines.kt
Created June 4, 2024 12:15
kotlin_coroutines.kt
package com.kunalchhabra
import kotlinx.coroutines.*
fun main() = runBlocking {
val startTime = System.currentTimeMillis()
// Launch a new coroutine in background and continue
val result1 = async { fetchDataFromSource1() }
val result2 = async { fetchDataFromSource2() }
@iKunalChhabra
iKunalChhabra / GraphQLClient.java
Created October 11, 2023 09:10
GraphQL Client in java
package org.example;
// <dependency>
// <groupId>org.apache.httpcomponents</groupId>
// <artifactId>httpclient</artifactId>
// <version>4.5.14</version>
// </dependency>
// <dependency>
// <groupId>org.json</groupId>
// <artifactId>json</artifactId>
@iKunalChhabra
iKunalChhabra / AES.java
Last active September 25, 2023 17:15
Do AES encryption in java
package org.example;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.SecretKeySpec;
import java.security.spec.KeySpec;
import java.util.Base64;
@iKunalChhabra
iKunalChhabra / java_http_get.java
Created June 9, 2023 14:51
Get request in Java using Apache HTTP Client
package org.example;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
@iKunalChhabra
iKunalChhabra / react-markdown.js
Last active June 5, 2023 06:34
Markdown with React
import ReactMarkdown from "react-markdown";
import { PrismLight as SyntaxHighlighter } from "react-syntax-highlighter";
import { oneDark } from "react-syntax-highlighter/dist/cjs/styles/prism";
import Styled from "styled-components";
const Code = Styled.code`
color: red;
font-size: 0.8rem;
padding: 0.2rem 0.4rem;
background-color: #EDEDEB;
@iKunalChhabra
iKunalChhabra / password_generator.py
Created March 22, 2023 10:02
Generate a random password
import string
import secrets
class PasswordGenerator:
"""
Generate a random password with the following parameters:
:param length: Length of the password
:param min_digits: Minimum number of digits in the password
:param min_uppercase: Minimum number of uppercase letters in the password