Skip to content

Instantly share code, notes, and snippets.

View greister's full-sized avatar
🎯
Focusing

greister

🎯
Focusing
View GitHub Profile
@greister
greister / Export-ExcelCSV.ps1
Created June 26, 2017 13:32
Export-ExcelCSV.ps1 #powershell #excel
# Author: Miodrag Milic <[email protected]>
# Last Change: 12-Feb-2016.
param(
# Path to Excel file
[string] $Path
)
if (!(Test-Path $Path)) { throw Path not found: $Path }
ps excel -ea 0| kill
@greister
greister / dnsmasq.conf
Created April 4, 2017 09:23 — forked from aa65535/dnsmasq.conf
dnsmasq config
# 并发查询所有上游DNS服务器
all-servers
# 本地DNS缓存最小有效期
min-cache-ttl=3600
# 本地DNS缓存数目
cache-size=65535
# 上游DNS服务器, 可设置多个
server=8.8.4.4
#server=8.8.8.8
server=114.114.114.114

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
def f(num:Int,arr:List[Int]):List[Int] = {
if (!arr.isEmpty)
for ( i <- 1 to num) println(arr.head)
f(num, arr.tail)
}
@greister
greister / gist:a1fe07b71d961e8937d208e20d98fa93
Created February 9, 2017 14:13 — forked from osipov/gist:c2a34884a647c29765ed
Install Scala and SBT using apt-get on Ubuntu 14.04 or any Debian derivative using apt-get
sudo apt-get remove scala-library scala
sudo wget www.scala-lang.org/files/archive/scala-2.10.4.deb
sudo dpkg -i scala-2.10.4.deb
sudo apt-get update
sudo apt-get install scala
wget http://scalasbt.artifactoryonline.com/scalasbt/sbt-native-packages/org/scala-sbt/sbt/0.12.4/sbt.deb
sudo dpkg -i sbt.deb
sudo apt-get update
sudo apt-get install sbt
@greister
greister / PomToSbt.scala
Created February 6, 2017 07:48 — forked from mslinn/PomToSbt.scala
Convert pom.xml to build.sbt
import scala.xml._
// To convert a Maven pom.xml to build.sbt:
// 1) Place this code into a file called PomToSbt.scala next to pom.xml
// 2) Type scala PomtoSbt.scala > build.sbt
// The dependencies from pom.xml will be extracted and place into a complete build.sbt file
// Because most pom.xml files only refernence non-Scala dependencies, I did not use %%
val lines = (XML.load("pom.xml") \\ "dependencies") \ "dependency" map { dependency =>
val groupId = (dependency \ "groupId").text
val artifactId = (dependency \ "artifactId").text
(defun re-seq (regexp string)
"Get a list of all regexp matches in a string"
(save-match-data
(let ((pos 0)
matches)
(while (string-match regexp string pos)
(p
(car (replace-regexp-in-string "\\n" "" (shell-command-to-string
"node -e 'console.log(module.paths)'")))
--------------------------------------
error:
Debugger entered--Lisp error: (wrong-type-argument listp
@greister
greister / ffap-nodejs-module.el
Created December 2, 2016 12:45 — forked from davazp/ffap-nodejs-module.el
Find node module at point
;;; Try to find the string at point as a NodeJS module
(require 'ffap)
(defun ffap-nodejs-module (name)
(unless (or (string-prefix-p "/" name)
(string-prefix-p "./" name)
(string-prefix-p "../" name))
(let ((base (locate-dominating-file
default-directory
@greister
greister / article.md
Created August 29, 2016 13:27 — forked from punmechanic/article.md
static-vs-dynamic-dispatch.md

Static vs Dynamic dispatch

AKA: Why is consuming an Iterator from glutin so damn hard?


In Rust, like many other languages, there are two different ways to call a function: static and dynamic dispatch. They're used in different scenarios and each have their own pros and cons, which are summarised thusly:

  1. Static calls tend to be faster because they do not require the use of a lookup table, which incurs overhead as the compiler has to 'find' the function it is calling at runtime.
  2. Dynamic calls tend to be more conservative of space as they can be re-used. This isn't so much an issue with functions like strcpy, but with functions that have multiple types of arguments (generics, for example), the code for the function must be duplicated.