Skip to content

Instantly share code, notes, and snippets.

View ioleo's full-sized avatar
🌊
Fighting the tide...

ioleo ioleo

🌊
Fighting the tide...
View GitHub Profile
@ioleo
ioleo / yell.sh
Last active January 25, 2016 20:39
#!/bin/sh
# Pretty yellow message in a box
# Usage:
# yell "My message"
yell() {
dash=$(printf '=%.0s' $(seq 1 ${#1}))
echo $(echo -e "\e[33m.=$dash=.\e[0m" | sed 's/=/-/g')
echo -e "\e[33m| $1 |\e[0m"
@ioleo
ioleo / Main.scala
Created October 12, 2016 18:23
Sparkathon @ Warsaw 2016-10-12
import org.apache.spark.sql.SparkSession
object Main extends App {
val spark = SparkSession.builder().master("local[*]").getOrCreate()
spark.experimental.extraOptimizations = Seq(MyRule)
import spark.implicits._
val numbersDS = Seq(0,1,2,3,4,5,6,7,8,9).toDS()
println(numbersDS.map(_+2).explain(true))
@ioleo
ioleo / Main.scala
Last active October 13, 2016 09:04
Scala future sequence
import scala.concurrent.{Await, Future}
import scala.concurrent.duration.Duration
import scala.concurrent.ExecutionContext.Implicits.global
object Main extends App {
val seq = Future.sequence(Seq(
Future { Thread.sleep(7000); println("doing 1"); 1 },
Future { println("doing 2"); 2 },
Future { Thread.sleep(3000); println("doing 3"); 3 },
Future { println("doing 4"); 4 },
@ioleo
ioleo / CassandraAsyncContextTest
Created January 18, 2017 06:27
Quill CassandraAsyncContext with stubbed underlaying Cluster - does not try to connect on init. Useful as a mock in tests.
// this is a disabled version of CassandraAsyncContext which does not connect to Cassandra DB on init
package loostro.scala.gist
import collection.JavaConverters._
import com.datastax.driver.core.Cluster
import com.datastax.driver.core.Configuration.Builder
import io.getquill.{CassandraAsyncContext, SnakeCase}
import java.net.InetSocketAddress
import org.scalatest.{FlatSpec, Matchers}
@ioleo
ioleo / SparkathonMarch2017.scala
Last active March 22, 2017 20:31
Hacking Spark internals to add custom Rules for Logical Plan
package org.apache.spark.sql
import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.sql.catalyst.CatalystConf
import org.apache.spark.sql.catalyst.analysis.Analyzer
import org.apache.spark.sql.catalyst.catalog.SessionCatalog
import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
import org.apache.spark.sql.catalyst.rules.Rule
import org.apache.spark.sql.internal.{SQLConf, SessionState}

Advanced Functional Programming with Scala - Notes

Copyright © 2017 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
object OneWayImplicits extends App {
//outside implicits visible, but T is not visible inside
case class Outwards[T](value: T) extends AnyVal
//outside implicits invisible, T is visible inside
case class Inwards[T](value: T) extends AnyVal
implicit def outwardsFromT[T](implicit t: T): Outwards[T] = Outwards(t)
implicit def tFromInwards[T](implicit inw: Inwards[T]): T = inw.value
@ioleo
ioleo / DefinedValuesMapExtension.sc
Last active August 5, 2017 21:42
DefinedValuesMapExtension
object workspace {
implicit class DefinedValuesMapExtension[K >: Null, V](map: Map[K, Option[V]]) {
def toDefinedValuesMap: Map[K, V] = map.collect { case (key, value) if value.isDefined => (key, value.get) }
}
val mapWithOptionalValues: Map[String, Option[Int]] = Map(
"foo" -> Some(20),
"bar" -> None,
@ioleo
ioleo / moment.workdays.js
Last active September 8, 2017 12:02
introduce 'workdays' mode to moment.js add/subtract methods (PL national holidays)
(function (undefined) {
/**
* moment.easter
* Source: https://github.com/zaygraveyard/moment-easter
* License: MIT
*/
moment.easter = function Easter20ops(year) {
var a = (year / 100 | 0) * 1483 - (year / 400 | 0) * 2225 + 2613;
var b = ((year % 19 * 3510 + (a / 25 | 0) * 319) / 330 | 0) % 29;
var c = 148 - b - ((year * 5 / 4 | 0) + a - b) % 7;
@ioleo
ioleo / sparkathon-agenda.md
Created September 12, 2017 18:05 — forked from jaceklaskowski/sparkathon-agenda.md
Sparkathon in Warsaw - Development Activities