Skip to content

Instantly share code, notes, and snippets.

View JavierCane's full-sized avatar
🤟
Working on @CodelyTV

Javier Ferrer González JavierCane

🤟
Working on @CodelyTV
View GitHub Profile
@JavierCane
JavierCane / StandardClass.scala
Created November 22, 2017 10:00
Scala standard class example for the CodelyTV Pro Scala course 👉 https://pro.codely.tv/
package tv.codely.scala_intro_examples.lesson_09_oop
final class StandardClass(
val attributeInConstruct: String,
private val privateAttributeInConstruct: String = "Some default value"
) {
val attributeInBody = "public body attribute value"
private val privateAttributeInBody = "private body attribute value"
}
@JavierCane
JavierCane / vimeoLinksGridView.js
Last active July 20, 2020 10:11
JavaScript statement to copy all Vimeo video titles and links while in the managing page
{
// 👍 Videos folder in grid view (with video duration)
const videosInGridView = Array.from(document.querySelectorAll(".sc-jWBwVP")).reverse();
const videoSummaries = videosInGridView.map(function (video) {
const videoLink = video.querySelector("h4 > a");
const videoTitle = videoLink.getAttribute("title");
const videoUrl = 'https://vimeo.com' + videoLink.getAttribute("href").replace('/settings', '');
package tv.codely.cqrs_ddd_scala_example.acceptance
import java.util.UUID
import scala.reflect.classTag
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
import cats.implicits._
import org.joda.time.DateTime
@JavierCane
JavierCane / CurryingExample.scala
Created October 23, 2017 07:43
Currying example for the CodelyTV Pro Scala course 👉 https://pro.codely.tv/
def sum(a: Int)(b: Int): Int = a+ b
def add1(b:Int) = sum(1)(b)
def add2(b:Int) = sum(2)(b)
def add3(b:Int) = sum(3)(b)
val add4 = sum(4)(_)
add2(5)
add4(6)
@JavierCane
JavierCane / higherOrderFunctions.scala
Created October 23, 2017 07:38
Scala higher order functions example for the CodelyTV Pro Scala course 👉 https://pro.codely.tv/
def print(
value: String,
printer: String => Unit
): Unit = printer(value)
def printlnPrinter(value: String): Unit = println(value)
val printlnPrinterVal = (value: String) => println(value)
print("Playing with higher order functions", printlnPrinter)
print("Same with functions stored in values", printlnPrinterVal)
@JavierCane
JavierCane / flatMapVsFor.scala
Created October 16, 2017 06:53
Scala Future flatMap vs for comprehension CodelyTV Pro Scala course example
package tv.codely.scala_intro_examples.lesson_05_ifs_for
import scala.concurrent.{ExecutionContext, Future}
final class SandwichMaker(private val fridge: Fridge, private val fryer: Fryer)(implicit ec: ExecutionContext) {
def make(): Future[Sandwich] = {
val breadOptionFuture = fridge.takeBread()
val cheeseOptionFuture = fridge.takeCheese()
val hamOptionFuture = fridge.takeHam()
val eggOptionFuture = fridge.takeEgg()
@JavierCane
JavierCane / SimpleFor.scala
Created October 16, 2017 06:28
Scala for examples for the CodelyTV Pro Scala course
val lele = if ("Codely mola".isInstanceOf[String]) 3 else 7
var total = 0
for (value <- 1 to 10) {
total = total + value
println(value)
}
(1 to 10).foreach(value2 => {
println(value2)
@JavierCane
JavierCane / scala_if_example.scala
Created October 16, 2017 06:16
Scala if example
val lele = if ("Codely mola".isInstanceOf[String]) 3 else 7
@JavierCane
JavierCane / Introducción a Scala - 4. Val var y def.scala
Created September 28, 2017 05:53
Introducción a Scala - 4. Val var y def
import scala.util.Random
var javi = "Javi" * 10 // Inferencia de tipos
javi = "Rafa" // podemos reasignar el contenido de una variable (var)
val rafa = "Rafa" // ";" al final de línea no necesario
// rafa = "Javi" // Petaría en tiempo de compilación. No podemos reasignar el contenido de un valor (val)
def codely(name: String): String = { // función pública con tipo de retorno explícito. Se declaran con = ya que asignamos una expresión.
println("Este mensaje se imprimirá por pantalla al invocar a la función codely")
@JavierCane
JavierCane / FunctinoalFinderKata.scala
Created April 18, 2017 20:42
Functional approach for the Finder Refactoring Kata. More info: http://codely.tv/screencasts/finder-kata-scala/
// Post: http://codely.tv/screencasts/finder-kata-scala/
// Repo: https://github.com/CodelyTV/incomprehensible-finder-refactoring-kata-scala
package tv.codely.finderKata.algorithm
final class BestPeoplePairFinder() {
def find(people: Seq[Person], peoplePairCriterion: Ordering[PeoplePair]): Option[PeoplePair] = {
val canFindPeoplePairs = people.size >= 2
if (!canFindPeoplePairs) {