Skip to content

Instantly share code, notes, and snippets.

View c.kt
@OptIn(
ExperimentalStdlibApi::class,
ExperimentalCoroutinesApi::class,
ExperimentalTime::class,
ExperimentalUnsignedTypes::class,
ExperimentalTypeInference::class
)
fun <T> Flow<T>.chunked(n: UInt, t: Duration): Flow<List<T>> {
val maxChunkSize = n.toInt()
View ioapp.scala
package com.lotusflare.chmiddleman
import cats.effect.ExitCase.Canceled
import cats.effect.{ ExitCode, IO, IOApp, Resource }
import cats.implicits._
import monix.eval.Task
import monix.execution.Scheduler.Implicits.global
import scala.concurrent.duration._
object Resources extends IOApp {
@tkroman
tkroman / homedir.c
Created Mar 10, 2019
cross-platform home dir in pure C
View homedir.c
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define PATH_LEN 256
int main(void)
{
char path[PATH_LEN];
FILE *pipe;
View loeb.scala
// http://blog.sigfpe.com/2006/11/from-l-theorem-to-spreadsheet.html
import cats._
import cats.implicits._
object Foo {
def main(args: Array[String]): Unit = {
// loeb :: Functor f => f (f x -> x) -> f x
// loeb x = fmap (\a -> a (loeb x)) x
View bar.cql
cqlsh:ks> delete from collection_table where k = 1;
Tracing session: 58c21de0-edaa-11e8-99e2-399d8477c401
activity | timestamp | source | source_elapsed | client
-------------------------------------------------------------------------+----------------------------+------------+----------------+------------
Execute CQL3 query | 2018-11-21 18:27:32.414000 | 172.17.0.6 | 0 | 172.17.0.1
Parsing delete from collection_table where k = 1; [SharedPool-Worker-1] | 2018-11-21 18:27:32.415000 | 172.17.0.6 | 1093 | 172.17.0.1
Preparing statement [SharedPool-Worker-1] | 2018-11-21 18:27:32.416000 | 172.17.0.6 | 1383 | 172.17.0.1
Determining replicas for mutation [SharedPool-Worker-1] | 2018-11-21 18:27:32.416000 | 172.17.0.6 | 1950 | 172.17.0.1
View foo.cql
cqlsh:ks> CREATE TABLE collection_table( k int primary key, l list<text>, s set<text>, m map<text, int>);
cqlsh:ks> insert into collection_table (k, l, s, m) values (1, ['a','b','c'], {'a','b','c'}, {'a':1,'b':2,'c':3});
cqlsh:ks> select * from collection_table;
@ Row 1
---+--------------------------
k | 1
l | ['a', 'b', 'c']
m | {'a': 1, 'b': 2, 'c': 3}
s | {'a', 'b', 'c'}
@tkroman
tkroman / c1.xml
Last active Nov 20, 2018
fuckfuckfuck
View c1.xml
<yandex>
<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>
<console>1</console>
</logger>
<http_port>8123</http_port>
@tkroman
tkroman / DisplacementJoin.scala
Last active Nov 4, 2018
ch join builder from homegrown ast
View DisplacementJoin.scala
def join(queries: NonEmptyList[TopLevelQuery]): TopLevelQuery = {
val size: Int = queries.size
if (size == 1) {
queries.head
} else {
queries
.reduceRight { case (q, acc) =>
acc.map { acc =>
val fiels: List[String] =
View AsString.scala
import AstElem._
class AsString extends QueryAstVisitor[String] {
override def visitFromTable(from: From.Table): String = {
s"FROM ${from.name}"
}
override def visitFromNested(from: From.NestedQueryTree): String = {
s"FROM (${visitTopLevelQuery(from.tree)})"
@tkroman
tkroman / crow.scala
Last active Nov 1, 2018
cassandra writer typeclass with support for field annotations to customize column names using shapeless
View crow.scala
import scala.annotation.StaticAnnotation
import com.datastax.driver.core.BoundStatement
import shapeless._
import shapeless.labelled._
import shapeless.ops.hlist.Zip
case class ColName(v: String) extends StaticAnnotation
sealed trait CRow[A] {