Skip to content

Instantly share code, notes, and snippets.

@fabrizioc1
fabrizioc1 / calico.yaml
Last active May 23, 2020 11:50
kubernetes calico network config
# Calico Version v3.4.4
# https://docs.projectcalico.org/v3.4/releases#v3.4.4
# This manifest includes the following component versions:
# calico/node:v3.4.4
# calico/cni:v3.4.4
# calico/kube-controllers:v3.4.4
# This ConfigMap is used to configure a self-hosted Calico installation.
kind: ConfigMap
apiVersion: v1
@fabrizioc1
fabrizioc1 / n_armed_bandit.py
Created June 3, 2019 06:34
Reinforcement Learning: N-Armed Bandit
from __future__ import division
import random
import numpy as np
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
# epsilon values
EPSILON_VALUES = [0.0, 0.01, 0.1]
@fabrizioc1
fabrizioc1 / Stemmer.py
Created February 12, 2019 00:01
Example of scala Spark transformer with python wrapper
from pyspark import since, keyword_only
from pyspark.ml.param.shared import HasInputCol, HasOutputCol, Param
from pyspark.ml.util import JavaMLReadable, JavaMLWritable
from pyspark.ml.wrapper import JavaTransformer
class Stemmer(JavaTransformer, HasInputCol, HasOutputCol, JavaMLReadable, JavaMLWritable):
@keyword_only
def __init__(self, inputCol=None, outputCol=None):
super(Stemmer, self).__init__()
@fabrizioc1
fabrizioc1 / permutations.scala
Created January 4, 2019 13:54
Calculate permutations of a sequence
// Permutations are using all elements in the sequence
import scala.collection.mutable.ArrayBuffer
// Mutable version
def permutationsM[T](s: Seq[T]): Seq[Seq[T]] = {
if (s.length < 2) {
Seq(s)
}
else if (s.length == 2) {
@fabrizioc1
fabrizioc1 / concurrent.scala
Last active January 4, 2019 13:52
Comparing different concurrency methods using Scala
import requests._
import org.json4s._
import org.json4s.jackson.{JsonMethods => Json}
import org.json4s.JsonDSL.WithBigDecimal._
import scala.concurrent._
import scala.concurrent.duration._
// import ExecutionContext.Implicits.global
import java.lang.Runtime
@fabrizioc1
fabrizioc1 / emr_exec.py
Created August 10, 2018 18:16
Execute script in each EMR cluster node
import os
import boto3
import subprocess
import configargparse
SSH_USER = 'hadoop'
SSH_TEMPLATE = 'ssh -o StrictHostKeyChecking=no -i {ssh_key} {ssh_user}@{host} "{cmd}"'
SSH_KEY_PATH = os.path.expanduser('~/.ssh')
def find_ssh_key(emr, config):
@fabrizioc1
fabrizioc1 / expand_hadoop_path.py
Created May 26, 2018 05:10
Expand hadoop path
import re
def expand_hadoop_path(path):
brace_patterns = re.findall('{{[^}]+}}', path)
brace_patterns_values = [(brace_pattern, brace_pattern.replace('{{','').replace('}}','').split(',')) for brace_pattern in brace_patterns]
replacements = []
for (brace_pattern, values) in brace_patterns_values:
if replacements:
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.