// For shared state across tasks, these are your main tools:
struct MyService {
// Immutable shared state
config: Arc<Config>,
// Mutable shared state
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
| from requests.api import request | |
| from Crypto.Cipher import PKCS1_OAEP, PKCS1_v1_5 | |
| from Crypto.Cipher import AES | |
| from Crypto.PublicKey import RSA | |
| from Crypto.Util.Padding import pad | |
| from Crypto.Util.number import bytes_to_long | |
| import base64 | |
| import requests | |
| import string | |
| import random |
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, HashSet}; | |
| use std::hash::Hash; | |
| pub struct Collection<'a, T> { | |
| items: Vec<&'a T>, | |
| } | |
| impl<'a, T> Collection<'a, T> { | |
| pub fn new(items: &'a [T]) -> Self { | |
| Self { |
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::sync::Arc; | |
| use tokio::sync::{broadcast, Mutex}; | |
| use tokio::time::{sleep, Duration}; | |
| #[derive(Debug)] | |
| struct SharedContext { | |
| counter: i32, | |
| last_updated_by: String, | |
| } |
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::sync::Arc; | |
| use tokio::sync::Mutex; | |
| use tokio::time::{sleep, Duration}; | |
| // Our shared context that will be accessed by all workers | |
| #[derive(Debug)] | |
| struct SharedContext { | |
| counter: i32, | |
| last_updated_by: String, | |
| } |
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 rand::Rng; | |
| use std::io::{self, Write}; | |
| #[derive(Debug, Default)] | |
| struct Score { | |
| player: u32, | |
| computer: u32, | |
| } | |
| #[derive(Debug, PartialEq, Clone, Copy)] |
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 rand::Rng; | |
| use std::io::{self, Write}; | |
| #[derive(Debug)] | |
| struct Score { | |
| player: u32, | |
| computer: u32, | |
| } | |
| #[derive(Debug, PartialEq, Clone)] |
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
| defmodule RPS do | |
| defmodule Score, do: defstruct player: 0, computer: 0 | |
| defmodule Context do | |
| defstruct [ | |
| score: %Score{}, | |
| rounds_to_play: 3, | |
| valid_moves: [:rock, :paper, :scissors], | |
| win_conditions: %{rock: :scissors, paper: :rock, scissors: :paper}, | |
| io: IO |
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
| defmodule RPS do | |
| defmodule Score, do: defstruct player: 0, computer: 0 | |
| def play do | |
| %Score{} | |
| |> Stream.iterate(&play_round/1) | |
| |> Enum.at(3) | |
| |> announce_winner() | |
| |> maybe_play_again() | |
| end |
NewerOlder