Skip to content

Instantly share code, notes, and snippets.

View dimosr's full-sized avatar

Dimos Raptis dimosr

View GitHub Profile
@dimosr
dimosr / model_with_race_condition.tla
Last active January 4, 2019 22:10
TLA+ model (in PlusCal) demonstrating race condition & resolving it
EXTENDS Naturals, TLC
(* --algorithm transfer
variables db_data = {}, read_db_data = {}, published_rx_data = {}, new_entry = 1, subscribed = FALSE;
fair process writer = "writer"
variables local_db_data = {}
begin
WRITER_OPEN: local_db_data := db_data; \* open transaction
WRITER_WRITE: local_db_data := local_db_data \union {new_entry}; \* write
@dimosr
dimosr / MockitoBehaviour.java
Created January 20, 2017 14:52
Mockito when/thenReturn & doReturn/when patterns behaviour
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.Map;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
@dimosr
dimosr / index.html
Last active July 8, 2016 10:39
HTML Simple Loader
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src="https://code.jquery.com/jquery-3.0.0.js"></script>
<script src="script.js"></script>
</head>
<body>
<div id="loader">
<div></div>
</div>
@dimosr
dimosr / cookiesParse.js
Created June 15, 2016 13:59
Function parsing the cookies string from the browser & creating a HashMap of cookies keys-values
function getCookiesMap(cookiesString) {
return cookiesString.split(";")
.map(function(cookieString) {
return cookieString.trim().split("=");
})
.reduce(function(acc, curr) {
acc[curr[0]] = curr[1];
return acc;
}, {});
}
@dimosr
dimosr / bitcoin_mine.py
Created February 24, 2016 14:55
A function finding suitable nonce for encryption to guarantee certain number of leading zeros (here:8) in the cipher text (mimicking bitcoin mining)
import hashlib
import random
import itertools
alphabetString = "abcdefghijklmnopqrstuvwxyz"
def doubleSHA256( plainText ):
firstEncryption = hashlib.sha256()
secondEncryption = hashlib.sha256()
firstEncryption.update(plainText)