Event Sourcing – Kafka as an event source article.

https://www.confluent.io/blog/event-sourcing-cqrs-stream-processing-apache-kafka-whats-connection/

Advertisements
Posted in Programming | Leave a comment

CRDT – Conflict-Free Replicated Data Types

Eventually consistency mechanism in distributed systems.

View story at Medium.com

Posted in Programming | Leave a comment

Rust – Enum serialization example


use serde::ser::{ Serialize, Serializer };
use serde::de::{ Deserialize, Deserializer };

pub enum EnumTestType {
    Type1,
    Type2,
    UNKNOWN,
}

impl EnumTestType {
    pub fn value(&self) -> &'static str {
        match *self {
            EnumTestType::Type1 => "T1",
            EnumTestType::Type2 => "T2",
            EnumTestType::UNKNOWN => "?",
        }
    }
}

impl Serialize for EnumTestType {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
        where S: Serializer,
    {
        serializer.serialize_str(self.value())
    }
}

impl <'a> Deserialize<'a> for EnumTestType {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
        where D: Deserializer<'a>,
    {
        let s = String::deserialize(deserializer)?;
        let result = match s.as_str() {
            "D" => EnumTestType::Type1,
            "I" => EnumTestType::Type2,
            _ => EnumTestType::UNKNOWN,
        };

        Ok(result)
    }
}

Posted in Programming, Rust | Leave a comment

Rust – using error-chain to report stack traces on errors occurred.

Github
https://github.com/rust-lang-nursery/error-chain

Example)
https://github.com/rust-lang-nursery/error-chain/blob/master/examples/quickstart.rs

Posted in Programming, Rust | Leave a comment

Rust – Index, mut Index operator example

use std::ops::{Index, IndexMut};
#[derive(Debug)]
pub struct ImageArray2 {
    data: Vec<u8>,
    rows: usize,
    cols: usize,
}

impl ImageArray2 {
    pub fn new(rows: usize, cols: usize) -> ImageArray2 {
        let data = Vec::with_capacity(rows * cols);
        ImageArray2 {
            data: data,
            rows: rows,
            cols: cols,
        }
    }
}

impl Index<usize> for ImageArray2 {
    type Output = [u8];
    fn index(&self, index: usize) -> &Self::Output {
        &self.data[index * self.cols .. (index + 1) * self.cols]
    }
}

impl IndexMut<usize> for ImageArray2 {
    fn index_mut(&mut self, index: usize) -> &mut Self::Output {
        &mut self.data[index * self.cols .. (index + 1) * self.cols]
    }
}
Posted in Programming, Rust | Leave a comment

Cassandra – Cassandra tuning guide

https://tobert.github.io/pages/als-cassandra-21-tuning-guide.html

Posted in cassandra, Programming | Leave a comment

Cassandra – Save a table in CSV and loading a CSV to a table in CQLSH

cqlsh:test_keyspace> COPY test_table TO 'test_table.csv' WITH HEADER=true;
cqlsh:test_keyspace> COPY test_table FROM 'test_table.csv' WITH HEADER=true;
Posted in cassandra, Programming | Leave a comment