My efforts to port http://www.youtube.com/watch?v=f6kdp27TYZs to Clojure.
func boring(msg string) {
for i := 0; ; i++ {
fmt.Println(msg, i)
time.Sleep(time.Second)
}
import com.cloudera.crunch._ | |
import com.cloudera.scrunch._ | |
class ScrunchWordCount { | |
def wordCount(inputFile: String, outputFile: String) = { | |
val pipeline = new Pipeline[ScrunchWordCount] | |
pipeline.read(from.textFile(inputFile)) | |
.flatMap(_.toLowerCase.split("\\W+")) | |
.filter(!_.isEmpty()) | |
.count |
#include <memory> | |
#include <iostream> | |
#include <sstream> | |
#include <utility> | |
#include <algorithm> | |
#include <iterator> | |
struct sequence_tag {}; | |
struct pointer_tag {}; |
My efforts to port http://www.youtube.com/watch?v=f6kdp27TYZs to Clojure.
func boring(msg string) {
for i := 0; ; i++ {
fmt.Println(msg, i)
time.Sleep(time.Second)
}
(ns prime-sieve | |
(:require [clojure.core.async :as async :refer [chan go <! >!]])) | |
;;; concurrent prime sieve in Clojure using core.async | |
;; inspired by a similar implementation in Go | |
;; http://golang.org/doc/play/sieve.go | |
(defmacro go-forever | |
"An infinite loop that runs in a go block." |
The MIT License (MIT) | |
Copyright (c) 2013 Jamar Parris | |
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE S |
(defn flip [function] | |
(fn | |
([] (function)) | |
([x] (function x)) | |
([x y] (function y x)) | |
([x y z] (function z y x)) | |
([a b c d] (function d c b a)) | |
([a b c d & rest] | |
(->> rest | |
(concat [a b c d]) |
%% Shared Ring Buffer | |
-module(srb). | |
-export([new/2, push/2, pop/2, pop/1]). | |
-compile(export_all). | |
-record(counters, | |
{ clock :: non_neg_integer(), | |
max_size :: non_neg_integer() }). |
import com.twitter.algebird.{Aggregator, Semigroup} | |
import com.twitter.scalding._ | |
import scala.util.Random | |
/** | |
* This job is a tutorial of sorts for scalding's Execution[T] abstraction. | |
* It is a simple implementation of Lloyd's algorithm for k-means on 2D data. | |
* | |
* http://en.wikipedia.org/wiki/K-means_clustering |
object test extends App { | |
import scala.collection.JavaConversions.asJavaEnumeration | |
import java.io.{ByteArrayInputStream, SequenceInputStream} | |
val inputs = Iterator("asdf", "qewr", "wert") | |
.map(x => new ByteArrayInputStream((x + "\n").getBytes)) | |
val in = new SequenceInputStream(asJavaEnumeration(inputs)) | |
Console.setIn(in) | |
val a = readLine() | |
val b = readLine() |
One of the simplest and most recognizable type classes is the semigroup. This type class abstracts over the ability to combine values of a certain type in an associative manner.
Cats provides cats.Semigroup[A]
to model semigroups [1].
The combine
method takes two values of the type A
and returns an A
value.