Skip to content

Instantly share code, notes, and snippets.

@den-crane
den-crane / summingmergetree-arrays-nested
Last active November 30, 2018 16:39
summingmergetree-arrays-nested
truncate table logs;
truncate table agg_table;
CREATE TABLE logs(
date Date,
ts DateTime,
groupId Int8,
subGroupId Int8) ENGINE = MergeTree() PARTITION BY date ORDER BY (groupId);
@den-crane
den-crane / Clickhouse-fast-not-exists
Last active November 3, 2023 10:53
Clickhouse fast not exists
ClickHouse server version 18.14.12 revision 54409.
create table data(K Int64, V String) engine=MergeTree order by K;
insert into data select number, toString(number) from numbers(100,100000000);
optimize table data final;
create table buffer(K Int64, V String) engine=Memory;
insert into buffer select number, toString(number) from numbers(0,1000);
create table test(a Int64, b Int64, c Int64, d String)
engine=MergeTree partition by tuple() order by (a,b,c);
insert into test select 1, 0, number, toString(number) from numbers(1000000);
insert into test select 2, 2, number, toString(number) from numbers(100);
insert into test select 3, 3, number, toString(number) from numbers(1000000);
select count() from test where a=2 and c=1;
1 rows in set. Elapsed: 0.002 sec.

Thread Pools

Thread pools on the JVM should usually be divided into the following three categories:

  1. CPU-bound
  2. Blocking IO
  3. Non-blocking IO polling

Each of these categories has a different optimal configuration and usage pattern.

@tel
tel / Lenses.scala
Created April 18, 2017 04:38
Pure profunctor lenses in Scala
import scala.language.higherKinds
object Lenses {
trait Profunctor[P[_, _]] {
def dimap[A, B, C, D](f: C => A, g: B => D)(p: P[A, B]): P[C, D]
}
object Profunctor {
@travisbrown
travisbrown / queens.scala
Last active October 4, 2017 07:38
Aphyr's n-queens solution from Typing the technical interview, but Scala
class Nil
class Cons[X, Xs]
class First[List] { type X }
object First {
type Aux[List, X0] = First[List] { type X = X0 }
implicit val nilFirst: Aux[Nil, Nil] = ???
implicit def consFirst[X0, Xs]: Aux[Cons[X0, Xs], X0] = ???
}
@densh
densh / Snake.scala
Last active December 19, 2021 05:05
Snake game in 200 lines of Scala Native and SDL2 as demoed during Scala Matsuri 2017
import scalanative.native._
import SDL._
import SDLExtra._
@extern
@link("SDL2")
object SDL {
type Window = CStruct0
type Renderer = CStruct0
@edefazio
edefazio / swar.subword.SWARIntro_NoComments.java
Last active January 22, 2024 09:48
using SWAR (SIMD Within A Register) in Java using general purpose registers
package swar.subword;
public class SWAR_Intro_NoComments
{
public static void main ( String[] args )
{
int x = 12345678;
int y = 9012345;
long xyCompound = as2x32BitCompound ( x, y );
@ramondelafuente
ramondelafuente / test_sudo_and_variables.yml
Last active March 17, 2023 23:38
Testing ansible "ansible_ssh_user" and "ansible_user_id" variables with sudo
- name: Testing variables with SUDO=NO
hosts: "*"
sudo: no
tasks:
- name: "PLAYBOOK SUDO=NO, TASK SUDO=NO"
command: whoami
register: whoami_output
sudo: no
- debug: var=whoami_output.stdout
@lelandbatey
lelandbatey / whiteboardCleaner.md
Last active February 25, 2024 13:47
Whiteboard Picture Cleaner - Shell one-liner/script to clean up and beautify photos of whiteboards!

Description

This simple script will take a picture of a whiteboard and use parts of the ImageMagick library with sane defaults to clean it up tremendously.

The script is here:

#!/bin/bash
convert "$1" -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 "$2"

Results