Skip to content

Instantly share code, notes, and snippets.

View tzach's full-sized avatar

Tzach Livyatan tzach

View GitHub Profile
@tzach
tzach / Advance_Data_Modeling.cql
Last active December 5, 2023 15:56
Advance Data Modeling
DROP KEYSPACE mykeyspace ;
CREATE KEYSPACE mykeyspace WITH replication = {'class': 'NetworkTopologyStrategy', 'replication_factor' : 3} AND durable_writes = true;
USE mykeyspace;
CREATE TABLE heartrate_v10 (
pet_chip_id uuid,
owner uuid,
time timestamp,
heart_rate int,
@tzach
tzach / LWT example
Last active December 27, 2020 15:39
CREATE KEYSPACE mykeyspace WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '3'} AND durable_writes = true;
USE mykeyspace;
CREATE TABLE guards (firstname text, lastname text, state boolean, room_temp int, PRIMARY KEY ((firstname, lastname)));
INSERT INTO guards (firstname, lastname, state, room_temp) VALUES ('tzach', 'livyatan', false, 25);
INSERT INTO guards (firstname, lastname, state, room_temp) VALUES ('tzach', 'livyatan', false, 24);
INSERT INTO guards (firstname, lastname, state, room_temp) VALUES ('guy', 'Guy Shtub', false, 25);
INSERT INTO guards (firstname, lastname, state, room_temp) VALUES ('laura', 'novich', false, 23);
INSERT INTO guards (firstname, lastname, state, room_temp) VALUES ('avishai', 'Ish Shalom', true, 24);
INSERT INTO guards (firstname, lastname, state, room_temp) VALUES ('ivan', 'Prisyazhnyy', true, 25);
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
(let ((default-directory "~/emacs/"))
(normal-top-level-add-subdirs-to-load-path))
(require 'better-defaults)
@tzach
tzach / sync-upstream.sh
Created October 11, 2020 07:46
Automated Github sync with upstream
#!/bin/bash
git fetch upstream
git checkout master
git merge upstream/master
@tzach
tzach / CDC example
Last active March 26, 2020 17:39
Scylla CDC Example
docker run --name some-scylla-night -d scylladb/scylla-nightly --experimental 1
docker exec -it some-scylla-night cqlsh
cqlsh>
CREATE KEYSPACE ks WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'} AND durable_writes = true;
CREATE TABLE ks.t (pk int, ck int, v int, PRIMARY KEY (pk, ck, v)) WITH cdc = {'enabled':true};
INSERT INTO ks.t (pk,ck,v) VALUES (1,2,3);
INSERT INTO ks.t (pk,ck,v) VALUES (1,2,4);
# Installing Guile on Fedoa 30 from source file does not work as documented
# here are the extra steps I did
# Download tar from https://ftp.gnu.org/gnu/guile/
tar -xvf guile-3.0.0.tar.gz
# install missing libs
sudo dnf install libffi-devel
sudo dnf install gc-devel
CREATE KEYSPACE mykeyspace WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'} AND durable_writes = true;
USE mykeyspace;
CREATE TABLE tbl (
k int,
v int,
x int,
PRIMARY KEY (k,v)
);
INSERT INTO tbl (k,v,x) VALUES (1,2,0);
INSERT INTO tbl (k,v,x) VALUES (1,2,3) IF NOT EXISTS;
CREATE KEYSPACE mykeyspace WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'} AND durable_writes = true;
USE mykeyspace;
CREATE TABLE tbl (
k int,
v int,
x int,
PRIMARY KEY (k,v)
);
INSERT INTO tbl (k,v,x) VALUES (1,2,0);
INSERT INTO tbl (k,v,x) VALUES (1,2,3) IF NOT EXISTS;
@tzach
tzach / calcInterest.clj
Created December 1, 2019 14:12
calcInterest
(defn round100 [n] (-> n (* 100) (Math/floor) (/ 100)))
(defn calcInterest [& {:keys [initialAmount interestRate years roundInterestYearly]}]
(nth (iterate
(fn calcInterestOneYear [amount]
(cond-> (* interestRate amount)
roundInterestYearly round100))
initialAmount) years))
@tzach
tzach / core.clj
Last active June 14, 2019 13:21
create a large cell in Scylla using Clojure alia
(ns cassandra-project.core
(:require [qbits.alia :as alia]))
(def cluster (alia/cluster {:contact-points ["172.17.0.2"]}))
(def session (alia/connect cluster))
(alia/execute session "USE mykeyspace;")
(dotimes [n 2000000]
(alia/execute session (str "UPDATE mykeyspace.gr SET link = link + {" n " : 'ABC'} WHERE id=1 AND r=1;")))