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
#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 <linux/module.h>
#include <linux/init.h>
#include <linux/kthread.h>
struct task_struct* ts;
static int thread_func(void)
{
while (1)
{
@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;
#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 <unistd.h>
#include <stdint.h>
#include <linux/fd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#define BLKSSZGET _IO(0x12,104)/* get block device sector size */
// 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) {
#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>
// Written by Pioz.
// Compile with: gcc -o autoclick autoclick.c -lX11
#include <stdio.h>
#include <string.h>
#include <X11/Xlib.h>
// Simulate mouse click
void
click (Display *display, int button)