Skip to content

Instantly share code, notes, and snippets.

Stream.eval(Task(new InetSocketAddress(InetAddress.getByName(null), 8123))).flatMap { ia =>
Stream.resource(tcp.client[Task](ia)).flatMap { sock =>
Stream
.chunk(Chunk.bytes("hello\n".getBytes))
.to(sock.writes())
.drain
.onFinalize(sock.endOfOutput) ++
sock
.reads(128, Some(15.seconds))
.chunks
/*
Copyright 2017 Bryan Keller (https://github.com/widget-)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
2018.09.22 03:46:25.789787 [ 43 ] {5402eaba-269f-467a-b8ba-2a31fe7f2adb} <Debug> executeQuery: (from 172.17.0.1:46684) select d from (select d from dstr all inner join (select d from sharded) using d)
2018.09.22 03:46:25.790062 [ 43 ] {5402eaba-269f-467a-b8ba-2a31fe7f2adb} <Debug> MemoryTracker: Peak memory usage (total): 47.00 B.
2018.09.22 03:46:25.851345 [ 43 ] {5402eaba-269f-467a-b8ba-2a31fe7f2adb} <Error> executeQuery: Code: 60, e.displayText() = DB::Exception: Table default.sharded doesn't exist., e.what() = DB::Exception (from 172.17.0.1:46684) (in query: select d from (select d from dstr all inner join (select d from sharded) using d)), Stack trace:
0. /usr/bin/clickhouse-server(StackTrace::StackTrace()+0x16) [0x9467606]
1. /usr/bin/clickhouse-server(DB::Exception::Exception(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)+0x22) [0x2fff8e2]
2. /usr/bin/clickhouse-server(DB::Context::getTableImpl(std::__cxx11::basic_string<char, std::char_traits<char>, std::
<?xml version="1.0"?>
<lotusflare>
<logger>
<level>debug</level>
<log>/var/log/clickhouse-server/clickhouse-server.log</log>
<errorlog>/var/log/clickhouse-server/clickhouse-server.err.log</errorlog>
<size>1000M</size>
<count>10</count>
</logger>
#!/bin/bash
set -x
curl clickhouse0:8123 -d "CREATE TABLE shard_1.foo_replicated(day Date, id String, x UInt32) ENGINE = ReplicatedMergeTree('/clickhouse/tables/1/foo_replicated', 'node1', day, (id), 8192)"
curl clickhouse0:8123 -d "CREATE TABLE shard_2.foo_replicated(day Date, id String, x UInt32) ENGINE = ReplicatedMergeTree('/clickhouse/tables/2/foo_replicated', 'node1', day, (id), 8192)"
curl clickhouse1:8123 -d "CREATE TABLE shard_0.foo_replicated(day Date, id String, x UInt32) ENGINE = ReplicatedMergeTree('/clickhouse/tables/0/foo_replicated', 'node2', day, (id), 8192)"
curl clickhouse1:8123 -d "CREATE TABLE shard_2.foo_replicated(day Date, id String, x UInt32) ENGINE = ReplicatedMergeTree('/clickhouse/tables/2/foo_replicated', 'node2', day, (id), 8192)"
curl clickhouse2:8123 -d "CREATE TABLE shard_0.foo_replicated(day Date, id String, x UInt32) ENGINE = ReplicatedMergeTree('/clickhouse/tables/0/foo_replicated', 'node0', day, (id), 8192)"
// before:
// A is some domain object,
// Typeclasses/behavior:
// Codec is for JSON <->,
// DbWriter is to write to DB
// maybe some other
case class Foo(x: Int, s: String)
object Foo {
implicit val codec: Codec[A] = ???
@tkroman
tkroman / less-known-traverse-example-2.scala
Last active February 28, 2018 01:07
less-known-traverse
object TravFil {
def main(args: Array[String]): Unit = {
// source data
val xs: List[Int] = List(2, 4, 6, 8, 10)
// ==============================
// Problem: given a list of ints,
// if there is an odd number (or more) -
// return Left(s"$FIRST_ODD_NUMBER is odd")
// if all the numbers are even:
// given: Seq[(Int, Int)] = value -> weight
// and W = max weight
// find max value
object Main {
type Weight = Int
type Value = Int
type Item = (Value, Weight)
def solveRec(items: Seq[Item], maxWt: Weight): Weight = {
@tkroman
tkroman / yay_me.scala
Last active November 26, 2017 04:24
shapeless: deriving typeclass instances for ScalaPB-generated oneof-style hierarchies
import shapeless._
object Typeclasses {
// 3 proto messages
case class A(x: Int)
case class B(s: String)
case class C(x: Int, s: String)
@tkroman
tkroman / build.sbt
Last active November 17, 2017 14:52
haha
enablePlugins(JmhPlugin)