Skip to content

Instantly share code, notes, and snippets.

View lure's full-sized avatar

Alex Shubert lure

  • JetBrains, LLC
View GitHub Profile

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
@lure
lure / docker-log-gist.md
Created January 13, 2017 09:58 — forked from afolarin/docker-log-gist.md
docker-logs
@lure
lure / SocialProviders.scala
Created November 21, 2015 21:57
Scala enumeratio
abstract class JEnum extends Enumeration {
case class JVal(name: String, url: Option[String]) extends Val(name) {
lazy val successUrl: String = {
// Should have protocol specification or YAHOO will fail
url.getOrElse(Props.get("public.domain").getOrElse("") + "/socialauth/rest/" + this.name + "/action")
}
}
protected final def JValue(name: String, url: String = null): Value = JVal(name, Option(url))
implicit def valueToJValue(v: Value): JVal = v.asInstanceOf[JVal]
@lure
lure / organizer.rb
Last active December 17, 2015 06:49
ruby, files organizer
# Being executed in the dir with a list of files with names formed as
# 'AuthorName BookTitle.ext' or 'AuthorName,BookTitle.ext'
# creates dirs named by Author and moves author's books there
require 'fileutils'
PATH_D = File.expand_path(File.dirname(__FILE__)) + '/' #absolute path to current dir
FILE_BASE = File.basename(__FILE__) #script's filename
Dir.foreach("./") do |entry|
next if entry.start_with?('.') or entry == FILE_BASE
@lure
lure / Eratosthene.java
Created August 27, 2012 07:29
Byte array sieve of Eratosthene
import java.util.Arrays;
public class Eratosthene{
public static int[] byteEratosthenes(int cap) {
int[] result = new int[(int) Math.ceil(1.25 * cap / Math.log(cap))];
int pos = 1;
result[0] = 2;
byte[] primes = new byte[(cap - 2 >> 4) + 1];