Skip to content

Instantly share code, notes, and snippets.

View krablak's full-sized avatar

Michal Ráček krablak

View GitHub Profile
@krablak
krablak / MicroAssert.md
Last active November 19, 2022 16:31
MicroAssert

MicroAssert

Minimal composable test assert utility.

Usage

Asserting Complex Data Model

Following code sample asserts complex application state model including:

@krablak
krablak / reading-args-showcase.java
Created April 10, 2016 19:23
Reading command line arguments in kemo
public static void main(final String[] args) throws Exception {
// Read command line parameters
CommandLineParams params = read(args);
// Get bind address
String bindAddress = params.get("-b", "--bind").orElse("localhost");
// Get production/development mode flag
Boolean isProductionMode = params.getBool("-m", "--mode").orElse(Boolean.FALSE);
...
<@common.small_avatar_icon initials="JR" color="#62CB31"/>
<#macro avatar_icon initials color>
<svg width="100" height="100">
<circle cx="50" cy="50" r="40" stroke="#62CB31" stroke-width="0" fill="${color}" />
<text x="50" y="57" fill="#ffffff" font-weight="bold" font-size="18px" font-family='"Open Sans","Helvetica Neue",Helvetica,Arial,sans-serif' text-anchor="middle">${initials}</text>
</svg>
</#macro>
@krablak
krablak / HazecastStoreSample.java
Created February 8, 2015 09:36
Coinfgure Hazelcast with our queue store implementation
Config config = new Config().addQueueConfig(queueConfig);
HazelcastInstance hazelInst = Hazelcast.newHazelcastInstance(config);
@krablak
krablak / MailQueueStoreConfig.java
Last active August 29, 2015 14:15
MailQueueStore Hazelcast java configuration
// Create queue store configuration and set the queue store class name
QueueStoreConfig storeConfig = new QueueStoreConfig().setClassName(MailQueueStore.class.getName());
storeConfig.setEnabled(true);
// Configure queue store properties
// All properties are described in hazecast documentation at https://github.com/hazelcast/hazelcast/blob/master/hazelcast-documentation/src/Queue-Persistence.md
storeConfig.setProperty("memory-limit", 100);
// Create config for queue which will be using our queue store
QueueConfig queueConfig = new QueueConfig().setName(MailorRemoteAPIConstants.Queues.MAIL_INPUT);
// Set previously created store configuration to queue configuration
queueConfig.setQueueStoreConfig(storeConfig);
@krablak
krablak / MailQueueStore.java
Last active August 29, 2015 14:15
Sample Hazelcast QueueStore implementation powered by MapDB
public class MailQueueStore implements QueueStore<InputMessageDto> {
private static final Logger logger = LoggerFactory.getLogger(MailQueueStore.class);
/**
* Reference to MapDB database connection isntance.
*/
private DB database;
public MailQueueStore() {
@krablak
krablak / delayedAssert.java
Last active August 29, 2015 14:14
POC of delayedAssert experiments
package com.mailor.app.test.util;
import static java.lang.String.format;
import static org.junit.Assert.fail;
/**
* Provides support for testing code executed asynchronously.
*
* @author krablak
*
@krablak
krablak / AsyncUtilExample.java
Last active August 29, 2015 14:11
AsyncUtil Example
// Following sample shows simple case of executing task asynchronously without blocking current thread.
// This is extremely handy for tasks which are not so important to block the execution of main program
// and we do depend on their execution results.
AsyncUtil.with(message).plan(MailSerializerUtil::toTempDir).async();
// It's also posible to chain async tasks plans
AsyncUtil.with(message)
.plan(MailSerializerUtil::toTempDir)
.plan(MailSerializerUtil::logMessage)
.async();
global_semaphore = asyncio.Semaphore(5)
def download(links=[], root_url="", download_loc="/tmp/"):
# Prepare root url
root_url_fixed = utils.peck_url_start(root_url)
# Prepare download futures for each link
down_futures = asyncio.wait([download_file(cur_link, root_url_fixed, download_loc) for cur_link in links])
# Execute prepared futures with download operations
down_futures_res =asyncio.get_event_loop().run_until_complete(down_futures)
# Return the futures result as array of downloaded files