Skip to content

Instantly share code, notes, and snippets.

View irajhedayati's full-sized avatar

Iraj Hedayati irajhedayati

View GitHub Profile
@irajhedayati
irajhedayati / EricssonCorporation.java
Last active January 4, 2016 00:34
Ericsson Corporation
package ir.iraj.ericsson;
import ir.iraj.ericsson.exceptions.IllegalBasePayException;
import ir.iraj.ericsson.exceptions.OverWorkException;
public class EricssonCorporation {
/**
* Minimum legal base pay
*/
@irajhedayati
irajhedayati / cassandra-as-rdd-spark-sehll.scala
Last active August 13, 2020 20:20
Deploy a local multi-node Cassandra cluster using Docker
/*
Run Spark shell using spark-shell --packages datastax:spark-cassandra-connector:2.4.0-s_2.11 command
Check the versions compatibility on https://github.com/datastax/spark-cassandra-connector#version-compatibility
*/
import com.datastax.spark.connector._
import org.apache.spark.sql._
val spark = SparkSession.builder().
appName("Spark SQL practice").master("local[*]").
config("spark.cassandra.connection.host", "localhost").
@irajhedayati
irajhedayati / raining.csv
Last active August 25, 2020 20:33
Data engineering course datasets
month rainfall umbrellas_sold
Jan 82 15
Feb 92.5 25
Mar 83.2 17
Apr 97.7 28
May 131.9 41
Jun 141.3 47
Jul 165.4 50
Aug 140 46
Sep 126.7 37
@irajhedayati
irajhedayati / setup.sh
Last active September 9, 2020 13:13
MCIT VM preparation
# Install SSH on the machine
sudo apt install openssh-server
sudo systemctl enable ssh
sudo systemctl start ssh
# Create a new user
sudo useradd -m -d /home/iraj/ -s /bin/bash -G sudo iraj
sudo passwd iraj
## pick a password
@irajhedayati
irajhedayati / logger.sh
Created November 10, 2020 15:33
A simple library in implementing bash scripts
#!/usr/bin/env bash
if [[ -f /etc/lsb-release ]]; then
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
NO_COLOUR=$(tput sgr0)
else
RED="\033[91m"
GREEN="\033[92m"
@irajhedayati
irajhedayati / resultset-iteartor.scala
Last active November 19, 2020 21:48
Scala cheatsheet
// How to convert a JDBC iterator to a Scala iterator
/* A data model to reflect the content of ResultSet */
case class Movie(mId: Int, title: String, rId: Int, ratingDate: String)
import java.sql.{ ResultSet, Statement }
val stmt: Statement = ???
val rs: ResultSet = statement.executeUpdate("SELECT * FROM movie".stripMargin)
@irajhedayati
irajhedayati / 1.Kafka-tutorial-topic.sh
Last active November 24, 2020 23:16
A set of tutorials on Kafka
# Section 1: topic
# To see different options and help on a command, just run it without any parameter
kafka-topics
# To create a topic with one partition and replication factor of 1
kafka-topics --zookeeper localhost:2181 --create --topic test --partitions 1 --replication-factor 1
# To get a list of existing topics
kafka-topics --zookeeper localhost:2181 --list
@irajhedayati
irajhedayati / register-avro-schema.sh
Created December 17, 2020 14:11
Register an Avro schema using command line
#!/bin/bash
set -e
usage() {
echo " Register Avro schema from a file in a Schema Registry"
echo ""
echo " Usage:"
echo " register-avro-schema.sh <Options>"
echo ""
echo " Options:"
echo " -r the URL of the Schema Registry e.g. http://localhost:8081"
@irajhedayati
irajhedayati / hive-basic.sql
Created March 5, 2021 23:33
Tutorial for HiveQL basics
/* How to create a database */
CREATE DATABASE test_db;
-- Show the query in the history
/* If try to create a database that already exists, it fails */
CREATE DATABASE test_db;
-- Explain the query result
-- Show the query in the history and that indicates the failure
/* In order to avoid failure in scripting, we can use IF NOT EXISTS keyword */
@irajhedayati
irajhedayati / hive-encoding.sql
Last active March 10, 2021 04:56
A set of tutorials for Hive encodings
CREATE DATABASE fall2019_iraj;
-- Encoding; CSV table
CREATE TABLE test (
name STRING,
age INT
);
/* Check the structure */
-- Note the location
DESCRIBE test;