This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def df_to_html_table(df): | |
css = """ | |
<style> | |
table { | |
border-collapse: collapse; | |
width: 50%; | |
margin: 20px auto; | |
font-family: Arial, sans-serif; | |
} | |
th { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cronstrue = require("cronstrue"); // https://www.npmjs.com/package/cronstrue | |
const cronparser = require("cron-parser"); // https://www.npmjs.com/package/cron-parser | |
const timeDiff = require("js-time-diff"); // https://www.npmjs.com/package/js-time-diff | |
let cronExpression = "5 * * * SUN"; | |
let currentDate = new Date(); | |
try { | |
let nextDate = cronparser.parseExpression(cronExpression).next().toDate(); | |
let cronMeaning = cronstrue.toString(cronExpression); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def convert_bytes(num): | |
for x in ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']: | |
if num < 1024.0: | |
return f"{num:.2f} {x}" | |
num /= 1024.0 | |
print(convert_bytes(1000_000_000_000)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.math.BigInteger; | |
import java.security.MessageDigest; | |
import java.security.NoSuchAlgorithmException; | |
class Hash { | |
public static void main(String[] args) throws NoSuchAlgorithmException { | |
String message = "Hello World"; | |
Hash hash = new Hash(); | |
System.out.println("MD5: " + hash.getMD5(message)); | |
System.out.println("SHA-1: " + hash.getSHA1(message)); |
NewerOlder