Skip to content

Instantly share code, notes, and snippets.

View alonsoir's full-sized avatar
👋
time to learn python by doing experiments with AI.

@alonso_isidoro alonsoir

👋
time to learn python by doing experiments with AI.
View GitHub Profile
@alonsoir
alonsoir / JavaDemo.java
Created September 25, 2015 14:59 — forked from jacek-lewandowski/JavaDemo.java
Java API for Spark Cassandra Connector - tutorial for blog post
package com.datastax.spark.demo;
import com.datastax.driver.core.Session;
import com.datastax.spark.connector.cql.CassandraConnector;
import com.google.common.base.Optional;
import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaPairRDD;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.FlatMapFunction;

10 Scala One Liners to Impress Your Friends

Here are 10 one-liners which show the power of scala programming, impress your friends and woo women; ok, maybe not. However, these one liners are a good set of examples using functional programming and scala syntax you may not be familiar with. I feel there is no better way to learn than to see real examples.

Updated: June 17, 2011 - I'm amazed at the popularity of this post, glad everyone enjoyed it and to see it duplicated across so many languages. I've included some of the suggestions to shorten up some of my scala examples. Some I intentionally left longer as a way for explaining / understanding what the functions were doing, not necessarily to produce the shortest possible code; so I'll include both.

1. Multiple Each Item in a List by 2

The map function takes each element in the list and applies it to the corresponding function. In this example, we take each element and multiply it by 2. This will return a list of equivalent size, compare to o

@alonsoir
alonsoir / parse_properties.scala
Created May 27, 2017 20:33 — forked from ninthdrug/parse_properties.scala
Parsing java properties files with Scala
import scala.io.Source.fromFile
def parseProperties(filename: String): Map[String,String] = {
val lines = fromFile(filename).getLines.toSeq
val cleanLines = lines.map(_.trim).filter(!_.startsWith("#")).filter(_.contains("="))
cleanLines.map(line => { val Array(a,b) = line.split("=",2); (a.trim, b.trim)}).toMap
}
@alonsoir
alonsoir / install-kafka.txt
Created May 2, 2018 11:38 — forked from jarrad/install-kafka.txt
Install Kafka on OSX via Homebrew
$> brew cask install java
$> brew install kafka
$> vim ~/bin/kafka
# ~/bin/kafka
#!/bin/bash
zkServer start
kafka-server-start.sh /usr/local/etc/kafka/server.properties
@alonsoir
alonsoir / clean_docker.sh
Created May 25, 2018 16:14 — forked from urodoz/clean_docker.sh
Cleans the old images and exited containers
# Clean the exited containers
docker rm $(sudo docker ps -a | grep Exit | cut -d ' ' -f 1)
# Clean the untagged images (or old images)
docker rmi $(docker images | tail -n +2 | awk '$1 == "<none>" {print $'3'}')
# On Docker 1.9+ you can remove the orphan volumes with the next command
docker volume rm $(docker volume ls -qf dangling=true)
@alonsoir
alonsoir / README.md
Created June 3, 2018 16:37 — forked from MoOx/README.md
How to keep in sync your Git repos on GitHub, GitLab & Bitbucket easily
title tags authors
How to keep in sync your Git repos on GitHub, GitLab & Bitbucket easily
git
github
gitlab
bitbucket
MoOx
@alonsoir
alonsoir / Operaciones-Git
Created October 15, 2018 10:16 — forked from jelcaf/Operaciones-Git
Git Tips - Mini-trucos de Git para facilitarme la tarea
#############################################
# Push de la rama actual
git push origin $rama_actual
#############################################
# Volver a un commit anterior, descartando los cambios
git reset --HARD $SHA1
#############################################
# Ver y descargar Ramas remotas
@alonsoir
alonsoir / setjdk.fish
Last active September 2, 2019 11:05 — forked from tobias/setjdk.fish
Manage multiple java versions on the mac from the fish shell
# quick way to change previous JAVA_HOME to jdk 8 version.
set -x JAVA_HOME (/usr/libexec/java_home -v 1.8)
function setjdk
if test -n "$JAVA_HOME"
removeFromPath "$JAVA_HOME/bin"
end
set -gx JAVA_HOME (/usr/libexec/java_home -v $argv[1])
set -gx PATH $JAVA_HOME/bin $PATH
end
@alonsoir
alonsoir / scala.rb
Created October 10, 2019 15:19 — forked from fabiofumarola/scala.rb
Install Scala 2.10 RC3 on OSX
# to install the latest stable version:
brew install scala --with-docs
# to install scala-2.10.0-RC3:
brew install https://raw.github.com/gist/4118557/scala.rb --with-docs
# to switch versions (from https://github.com/mxcl/homebrew/wiki/External-Commands):
brew switch scala 2.9.2
brew switch scala 2.10.0-RC3
@alonsoir
alonsoir / README-Template.md
Created July 13, 2020 19:35 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites