Skip to content

Instantly share code, notes, and snippets.

Applied Functional Programming with Scala - Notes

Copyright © 2016-2018 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
@khajavi
khajavi / Json4sTest.scala
Created February 25, 2016 14:10 — forked from parth-patil/Json4sTest.scala
Json4s Examples
/**
* Make sure you include the following in your build.sbt
"org.json4s" %% "json4s-core" % "3.2.10",
"org.json4s" %% "json4s-jackson" % "3.2.10"
*/
import org.json4s._
import org.json4s.jackson.JsonMethods._
import org.json4s.JsonDSL._
case class Candidate(name:Option[String], age:Option[Int], party:Option[String])
@khajavi
khajavi / Google2APi.java
Created January 4, 2016 22:16 — forked from yincrash/Google2APi.java
Google OAuth2.0 for scribe-java
package org.scribe.builder.api;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.scribe.exceptions.OAuthException;
import org.scribe.extractors.AccessTokenExtractor;
import org.scribe.model.OAuthConfig;
import org.scribe.model.OAuthConstants;
import org.scribe.model.OAuthRequest;
@khajavi
khajavi / Makefile
Last active August 29, 2015 14:27 — forked from border/Makefile
json example in golang
include $(GOROOT)/src/Make.inc
GOFMT=gofmt -spaces=true -tabindent=false -tabwidth=4
all:
$(GC) jsontest.go
$(LD) -o jsontest.out jsontest.$O
format:
$(GOFMT) -w jsontest.go
@khajavi
khajavi / blocked
Last active August 29, 2015 14:18 — forked from fzerorubigd/blocked
code.google.com
googleapis.com
googleusercontent.com
ytimg.com
youtube.com
youtube-nocookie.com
bitbucket.org
thepiratebay.se
humblebundle.com
plus.url.google.com
@khajavi
khajavi / 0_reuse_code.js
Last active August 29, 2015 14:16
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
#include<stdio.h>
#include<stdlib.h>
#include<sys/socket.h>
#include<features.h>
#include<linux/if_packet.h>
#include<linux/if_ether.h>
#include<errno.h>
#include<sys/ioctl.h>
#include<net/if.h>
#include<net/ethernet.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/io.h>
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <inttypes.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/utsname.h>
// weibo上有人说到https://github.com/joewalnes/websocketd,我想其原理大致如此(process-wrapper.c):
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int wrap_process(const char* exefile) {