This file contains hidden or 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 { Worker, isMainThread, parentPort, workerData } from 'worker_threads'; | |
// Worker thread | |
if (!isMainThread) { | |
const workerFunction: (input: any) => any = eval(workerData.workerFunction); | |
const result = workerFunction(workerData.input); | |
parentPort?.postMessage(result); | |
} | |
// Main thread |
This file contains hidden or 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
#!/bin/sh | |
main() { | |
check_exists "$local_dir" "local directory" | |
check_exists "$ssh_key" "ssh key file" | |
log_message "starting backup of $local_dir to $remote_server:$remote_dir" | |
rsync -avz \ | |
-e "ssh -i $ssh_key" --delete --log-file="$log_file" \ | |
--progress "$local_dir" "$remote_server:$remote_dir" \ | |
|| handle_error "backup failed" |
This file contains hidden or 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 std::collections::HashMap; | |
pub fn create_patch(original: &str, modified: &str) -> String { | |
let original_lines = original.lines().collect::<Vec<_>>(); | |
let modified_lines = modified.lines().collect::<Vec<_>>(); | |
let mut longest_common_subsequences = HashMap::new(); | |
longest_common_subsequences.insert((0, 0), vec![]); | |
for (i, &original_line) in original_lines.iter().enumerate() { | |
for (j, &modified_line) in modified_lines.iter().enumerate() { |
This file contains hidden or 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 crate::linkedlist::LinkedList; | |
use std::sync::{Arc, RwLock}; | |
pub struct Queue<T> { | |
queue: RwLock<LinkedList<T>>, | |
} | |
impl<T> Queue<T> { | |
pub fn new() -> Arc<Self> { | |
Arc::new(Queue { |
This file contains hidden or 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
class BTreeNode { | |
keys: number[]; | |
children: BTreeNode[]; | |
numKeys: number; | |
constructor(private minDegree: number, public isLeaf: boolean) { | |
this.keys = new Array(2 * this.minDegree - 1); | |
this.children = new Array(2 * this.minDegree); | |
this.numKeys = 0; | |
} | |
findKey(key: number): number { |
This file contains hidden or 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
CREATE TABLE workspaces ( | |
id SERIAL PRIMARY KEY, | |
name VARCHAR(255) NOT NULL | |
); | |
CREATE TABLE users ( | |
id SERIAL, | |
workspace_id INT NOT NULL, | |
email VARCHAR(255) NOT NULL, | |
PRIMARY KEY (workspace_id, id), |
This file contains hidden or 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 { randomBytes, createCipheriv, createDecipheriv } from 'crypto'; | |
import { createConnection, Socket } from 'net'; | |
import { promisify } from 'util'; | |
type SessionData = { | |
userId: string; | |
expiresAt: number; | |
}; | |
interface IConfigService { |
This file contains hidden or 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
/* | |
[dependencies] | |
tokio = {version="1", features=["full"]} | |
*/ | |
use std::collections::HashMap; | |
use std::sync::{Arc, Mutex}; | |
use std::time::Duration; | |
use tokio::time::sleep; |
This file contains hidden or 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 { SyncService } from './SyncService'; | |
import type { | |
EventId, | |
UserId, | |
EventFromA, | |
} from './types'; | |
import { describe, beforeEach, it, expect } from '@jest/globals'; | |
import { QueueService, LogService, BService, MonitorService, CacheService } from './mock-services'; | |
This file contains hidden or 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; | |
async fn async_fn_with_async_cb<T: Future>(f: fn(String) -> T) -> T::Output { | |
// we do some shit here and then end up with a string | |
let x = "`this is the result of something`".to_string(); | |
f(x).await | |
} | |
#[tokio::main] |