Skip to content

Instantly share code, notes, and snippets.

View stsatlantis's full-sized avatar

Barnabás Oláh stsatlantis

View GitHub Profile
@stsatlantis
stsatlantis / ancientTempleLocation.scala
Last active September 24, 2016 22:16
CodeFights - ancientTempleLocation
def ancientTempleLocation(r: Int, sa: Array[Int], p: Array[Int]): Array[Int] = {
val xMin = math.min(sa(0),sa(2))
val yMin = math.min(sa(1),sa(3))
val xMax = math.max(sa(0),sa(2))
val yMax = math.max(sa(1),sa(3))
case class CoordValue(x:Int, y:Int, value: Int,c:Int){
def this(x:Int,y:Int,cv:(Int,Int)) = this(x,y,cv._1,cv._2)
@stsatlantis
stsatlantis / codeCharCount.scala
Created September 22, 2016 08:44
CodeFight - Counting characters
def shortestSolutionLength(source: Array[String]): Int = {
sealed abstract class State
case class Counting() extends State
case class Dash() extends State
case class SingleLineComment() extends State
case class Astrix() extends State
case class MultiLineComment() extends State
var count: Int = 0

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
@stsatlantis
stsatlantis / htmlToLuna.scala
Last active September 19, 2016 07:30
CodeFight - htmlToLuna
def htmlToLuna(html: String): String = {
abstract class HtmlElement{def print(): String}
case class Div(elems: List[HtmlElement]) extends HtmlElement{
def print() = "DIV(["+ elems.map(_.print).mkString(", ") +"])"
}
case class P(elems: List[HtmlElement]) extends HtmlElement{
def print() = "P([" + elems.map(_.print).mkString(", ") +"])"
}
private DateTime getDateTime(String time) {
DateTime result = null;
final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss";
if (time != null) {
try {
DateTimeFormatter DATETIME_FORMATTER = DateTimeFormat.forPattern(DATE_FORMAT);
DateTimeZone dateTimeZone = DateTimeZone.forID("GMT+0");
DateTime date = DATETIME_FORMATTER.withZone(dateTimeZone).parseDateTime(time);
package slicks.docs.dao
import scala.slick.driver.PostgresDriver.simple._
import scala.slick.driver._
trait Profile {
val profile: JdbcProfile
}
## HMTL:
<span class="label" ng-style="vm.decorateLabel(entity)">{{entity.name}}</span>
## JavaScript:
vm.decorateLabel = decorateLabel;
function decorateLabel(entity) {
return {
@stsatlantis
stsatlantis / play2SetupInIntelliJ.md
Created May 28, 2016 21:54
Setting up your Play 2 Application in IntelliJ

Prerequisites

  • Having IntelliJ Installed

This example uses IntelliJ 2016.1

Setting up IntelliJ for Scala project

  • File -> Settings -> Plugins
  • Search for "Scala" and Install the plugin
  • Restart IntelliJ
package hu.stsatlantis.fun.adventofcode2015
import scala.annotation.tailrec
/**
* Created by Barni on 2015.12.06..
*/
case class Coordinate(x: Int, y: Int)
def task1(str: String): Boolean = {
val vowelR = """[a,e,i,o,u]"""
@tailrec
def processTask1(arr: List[String], prevChar: String, vowelCount: Int, hasDouble: Boolean): Boolean = {
arr match {
case Nil => vowelCount >= 3 && hasDouble;
case "a" :: "b" :: xs => false
case "c" :: "d" :: xs => false