Skip to content

Instantly share code, notes, and snippets.

defmodule PhenixDisplays.EnumUtils do
@doc """
Make a sliding window of a list
## Example
iex> alias PhenixDisplays.EnumUtils
iex> EnumUtils.sliding([1,2,3], 2)
[[1, 2], [2, 3]]
iex> EnumUtils.sliding([1,2,3,4], 2)
[[1, 2], [2, 3], [3, 4]]
extends Control
var pressed = false
var offset = Vector2()
#######
func _gui_input(event):
if Input.is_action_just_pressed("left_click") and is_mouse_on_title():
pressed = true
@Cowa
Cowa / love-zhsrc.sh
Created January 8, 2016 13:35
love alias for Mac
alias love="/Applications/love.app/Contents/MacOS/love"
import scala.io.Source
object InvertedIndex {
/**
* Build an inverted index from a file with this format:
* doc0 w0 w1 ...
* doc1 w2 w4 ...
* Each elements of a line is separated by whitespaces
*
word0 document0.txt document1.txt
word1 document0.txt
word5 document0.txt document1.txt
word7 document1.txt
document0.txt word0 word1 word5
document1.txt word0 word5 word7
package controllers
import config.{EndpointConfig => Config}
import play.api.mvc._
import play.api.Play.current
import play.api.libs.ws.{WSRequest, WS}
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
object Marker {
val start = "<s>"
val end = "</s>"
}
object NGram {
def build(t: String, n: Int): NGram = {
NGram(addProbability(addCount(t.split("\n").flatMap(l =>
sliding(l.split(" ").toList, n)).toList), n), n)
}
val ngram = (List.fill(n - 1)("<s>") ++ tokens :+ "</s>")
.sliding(n)
.toList
// Same song
val ngramWithCount = ...
val ngramWithProbabilityFaster = ...
val sumIndex = ngramWithCount.groupBy { case (k, v) => k.take(n - 1) }.mapValues(_.values.sum)
val ngramWithProbabilityFaster = ngramWithCount.map { case (k, v) =>
(k, v.toDouble / sumIndex(k.take(n - 1)))
}
// Map(List(eating, the) -> 1.0, List(blue, sky) -> 1.0, List(red, koala) -> 1.0, List(near, the) -> 1.0, List(The, blue) -> 1.0, List(the, sky) -> 0.5, List(koala, eating) -> 1.0, List(sky, is) -> 1.0, List(the, red) -> 0.5, List(is, near) -> 1.0)