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
| #!/usr/bin/env bash | |
| declare -A board | |
| for ((i=1; i<=7; i++)); do | |
| for ((j=1; j<=6; j++)); do | |
| board[$i,$j]=' ' | |
| done | |
| done | |
| check_winner() { |
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
| fn main() { | |
| // create a new binary tree | |
| let mut root = TreeNode::new(1); | |
| let left_child = TreeNode::new(2); | |
| let right_child = TreeNode::new(3); | |
| root.set_left(left_child); | |
| root.set_right(right_child); |
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
| async function processItems(items, fn) { | |
| const errs = []; | |
| let i = 0; | |
| const workers = Array(25) | |
| .fill() | |
| .map(async () => { | |
| while (i < items.length) { | |
| await fn(items[i++]).catch((e) => errs.push(e)); | |
| } | |
| }); |
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 { |