Skip to content

Instantly share code, notes, and snippets.

View Gueka's full-sized avatar
🎯
Focusing

Marco Gueka

🎯
Focusing
View GitHub Profile
@Gueka
Gueka / xlsx_to_insert.py
Last active February 22, 2018 14:00
I use this gist to parse large xlsx file to get the inserts for my database
import xlrd
from tkinter import filedialog
from tkinter import Tk
import os
Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
print("Start .xlsx parser")
path = filedialog.askopenfilename(initialdir = os.getcwd(),title = "Select an spreedsheet to parse ",filetypes = (("Excel files","*.xlsx"),("all files","*.*"))) # show an "Open" dialog box and return the path to the selected file
print("Opening file: " + path)
@Gueka
Gueka / rund-docker-cassandra.sh
Created August 1, 2019 01:05
Start a docker instance of Cassandra database
docker run -e DS_LICENSE=accept --memory 3g -p 9042:9042 --name my-cassandra -d datastax/dse-server -g -s -k
@Gueka
Gueka / docker-cassandra-console.sh
Last active September 6, 2019 21:28
Get into cassandra console inside docker container
docker exec -it my-cassandra bin/cqlsh
@Gueka
Gueka / create-keyspace.cql
Created August 1, 2019 01:10
Create a keyspace named tutorial with a simple strategy and 1 replicator
CREATE KEYSPACE IF NOT EXISTS tutorial WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
@Gueka
Gueka / create-table.cql
Created August 1, 2019 01:12
Select tutorial keyspace and create a custom type 'location' and a table using location named 'users'
USE tutorial;
CREATE TYPE location (city TEXT, zip_code TEXT, address TEXT);
CREATE TABLE users (id UUID PRIMARY KEY, name TEXT, surname TEXT, creation_timestamp TIMESTAMP, tags list<TEXT>, location LOCATION);
@Gueka
Gueka / Configuration.java
Created August 1, 2019 17:32
Used to configure Cassandra database with spring boot
package net.gueka.user.configuration;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.cassandra.config.AbstractCassandraConfiguration;
import org.springframework.data.cassandra.config.CassandraClusterFactoryBean;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.SimpleUserTypeResolver;
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;
@Gueka
Gueka / build.gradle
Created August 1, 2019 17:33
Dependencies for a spring boot web project using cassandra
buildscript {
ext {
junitVersion = '5.3.2'
cassandraUnit = '2.1.9.2'
}
}
plugins {
id 'org.springframework.boot' version '2.1.5.RELEASE'
id 'java'
@Gueka
Gueka / User.java
Created August 1, 2019 17:35
Cassandra model for spring boot using lombok
package net.gueka.user.model;
import java.util.List;
import java.util.UUID;
import com.datastax.driver.core.DataType.Name;
import org.springframework.data.cassandra.core.mapping.CassandraType;
import org.springframework.data.cassandra.core.mapping.PrimaryKey;
import org.springframework.data.cassandra.core.mapping.Table;
@Gueka
Gueka / UserRepository.java
Created August 1, 2019 17:36
An Spring boot Cassandra repository example
package net.gueka.user.repository;
import java.util.UUID;
import org.springframework.data.cassandra.repository.CassandraRepository;
import org.springframework.stereotype.Repository;
import net.gueka.user.model.User;
@Repository
@Gueka
Gueka / IntegrationTest.java
Created August 1, 2019 17:37
An integration test example for Spring boot with Cassandra embedded database
package net.gueka.user;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;