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
trait EnoughParticipants { | |
/** Given probabilities of each participant attending in "probabilities", | |
* calculate the probability that at least "needed" participants will participate. | |
* | |
* The probability has to be accurate to the precision of 0.001. | |
*/ | |
def calculate(probabilities: List[Double], needed: Int): Double | |
} |
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
class EnoughParticipantsMonteCarlo extends EnoughParticipants { | |
override def calculate(probabilities: List[Double], needed: Int): Double = { | |
(1 to attempts).par.map(i => probabilities.map(p => dice(p)).sum).count(successful => successful >= needed) / attempts.toDouble | |
} | |
val Precision = 0.001 | |
val attempts = Math.ceil(Math.pow(1 / Precision, 2)).toInt |
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
hazelcast.hosts={{ groups.api|zip_longest([], fillvalue=':5701')|map('join')|join(',') }} | |
endpoint.hosts={{ ['http://']|product(groups.query_gui)|map('join')|product([':8099'])|map('join')|join(',') }} |
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 rfc3339; | |
import org.junit.jupiter.api.Assertions; | |
import org.junit.jupiter.api.Test; | |
import org.junit.jupiter.api.function.Executable; | |
import java.time.ZoneOffset; | |
import java.time.ZonedDateTime; | |
import java.time.format.DateTimeFormatter; | |
import java.time.format.ResolverStyle; |
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
#[test] | |
fn test_something_interesting() { | |
run_test(|| { | |
let true_or_false = do_the_test(); | |
assert!(true_or_false); | |
}) | |
} | |
fn run_test<T>(test: T) -> () | |
where T: FnOnce() -> () + panic::UnwindSafe |
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 std::sync::{Arc, Mutex, MutexGuard}; | |
use std::collections::HashMap; | |
use std::ops::Deref; | |
pub struct Inner<'a>(MutexGuard<'a, HashMap<i32, Vec<i32>>>, i32); | |
impl<'a> Deref for Inner<'a> { | |
type Target = Vec<i32>; | |
fn deref(&self) -> &Self::Target { | |
self.0.get(&self.1).unwrap() |
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
val events = CopyOnWriteArrayList<UserSubscriptionExternalActivationEvent>() | |
val listenerContainer = rabbitConfig.bind<UserSubscriptionExternalActivationEvent>( | |
routingKey.externalActivation, | |
TopicExchange(properties.template.exchange), | |
) { | |
println("result is $it") | |
events.add(it) | |
Mono.empty() | |
} | |
listenerContainer.start() |
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
from sqlalchemy import create_engine | |
engine = create_engine("postgresql://<name>:<password>@postgres-context-slave.spb.play.dc:5433/context", echo=True, connect_args={"options": "-c TimeZone=UTC"}) |
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 psycopg2.extras | |
# del os.environ["PGTZ"] | |
# os.environ["PGTZ"]="UTC" | |
# os.environ["PGTZ"]="Europe/Moscow" | |
conn = psycopg2.connect( | |
# host="postgres-corecms-slave.spb.play.dc", | |
host="postgres-context-slave.spb.play.dc", | |
port=5433, | |
dbname="context", |
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
fun main() { | |
runBlocking { | |
repeat(10) { | |
try { | |
// CoroutineScope(coroutineContext + SupervisorJob()).run { | |
supervisorScope { | |
listOf( | |
async { | |
throw IllegalStateException("ERROR OCCURRED.") | |
}, |
OlderNewer