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 { | |
Worker, | |
isMainThread, | |
parentPort, | |
workerData | |
} = require("worker_threads"); | |
if (isMainThread) { | |
// create new threads from the main thread | |
const thread1 = new Worker(__filename, {workerData: 'thread 1'}); |
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
/** | |
* PROBLEM: Given a sentence reverse each word and print it back. | |
* For example if the given sentence is "Mother India" | |
* then output would be "rehtoM aidnI" | |
* If given sentence is "hare-krishna hare-rama" | |
* then output would be "erah-anhsirk erah-amar" | |
*/ | |
// define a list by chars that we need to split the string with |
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
use futures::future::{BoxFuture, FutureExt}; | |
#[tokio::main] | |
async fn main() { | |
println!("Hello, world!"); | |
let db = AppDatabase(0); | |
let r = db.execute_transaction(transaction).await; | |
println!("{:?}", r); | |
} |
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
// transfer balance from one account to another | |
const transferBalance = async (fromAccount, toAccount, amount) => { | |
// get database client | |
const client = await database.getClient(); | |
// create a database session | |
const session = client.startSession(); | |
// define transaction options | |
const transactionOptions = { | |
readPreference: 'primary', |
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
// compose a Higher Order Function with two function as input parameter | |
// so the compose function takes two parameters f1, f2 and returns a function f3 | |
// f1, f2 & f3 - all functions takea one parameter i32 and returns a value i32 | |
#[allow(dead_code)] | |
fn compose(f1: impl Fn(i32) -> i32, f2: impl Fn(i32) -> i32) -> impl Fn(i32) -> i32 { | |
move |x: i32| f2(f1(x)) | |
} | |
#[cfg(test)] |
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
use flate2::read::GzDecoder; | |
use flate2::write::GzEncoder; | |
use flate2::Compression; | |
use std::fs::File; | |
use tar::Archive; | |
const TEST_DIR: &str = "test"; | |
const TAR_FILE_NM: &str = "test.tar.gz"; | |
// compress input directory into a _.tar.gz file |
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
// URL Parser | |
#![allow(dead_code, unused_imports)] | |
use std::io; | |
use std::num::ParseIntError; | |
use std::str::FromStr; | |
#[derive(Debug, PartialEq, Eq)] | |
enum CustomError { |
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
fn fibonacci(term: u64) -> u64 { | |
let (_, tot) = (0..=term).fold((0_u64, 1_u64), |acc, t| { | |
match t { | |
0 => (0_u64, 0_u64), | |
1 => (0, 1_u64), | |
2 => (1, 1_u64), | |
_ => { | |
let (prev, tot) = acc; | |
(tot, tot + prev) |
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
fn modPow(base: u64, exponent: u64, modulus: u64) -> u64 { | |
if m == 1 { | |
return 0; | |
} | |
let mut r = 1; | |
let mut pow = exponent; | |
let mut num = base % modulus; | |
loop { | |
if pow == 0 { | |
break; |
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 main | |
import ( | |
"encoding/base64" | |
"fmt" | |
"net/http" | |
"strings" | |
"github.com/gin-gonic/gin" | |
) |
NewerOlder