This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns talk | |
(:require [overtone.core :refer :all] | |
[clojure.java.io :as io])) | |
;; Overtone by Sam Aaron & Jeff Rose | |
;; https://github.com/overtone/overtone | |
(definst da-funk [freq 440 dur 1.0 amp 1.0 cutoff 1700 boost 6 dist-level 0.015] | |
(let [env (env-gen (adsr 0.3 0.7 0.5 0.3) (line:kr 1.0 0.0 dur) :action FREE) | |
filter-env (+ (* freq 0.15) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use_bpm 100 | |
ch1 = [73, 68, 61] | |
ch2 = [76, 68, 61] | |
ch3 = [73, 68, 61] | |
ch4 = [73, 69, 54] | |
ch5 = [76, 69, 54] | |
ch6 = [73, 69, 54] | |
ch7 = [73, 69, 57] | |
ch8 = [76, 69, 57] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns talk | |
(:require [overtone.core :refer :all] | |
[clojure.java.io :as io] | |
[clj-http.client :as http] | |
[clojure.test :as test])) | |
(def talk | |
{:title "Sequencing dance music with Clojure" | |
:author "Piotr Jagielski" | |
:company {:name "TouK" :what "Software house" :from "Warsaw, Poland"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun findAllBy(articleId: ArticleId): List<Comment> | |
// or | |
fun findAllByPaged(articleId: ArticleId, pageRequest: PageRequest): Page<Comment> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed class UserId : RefId<Long>() { | |
object New : UserId() { | |
override val value: Long by IdNotPersistedDelegate<Long>() | |
} | |
data class Persisted(override val value: Long) : UserId() { | |
override fun toString() = "UserId(value=$value)" | |
} | |
} | |
data class User( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class User( | |
val username: Username, | |
val password: String, | |
val email: String | |
) | |
object UserTable : Table("users") { | |
val username = text("username") | |
val email = text("email") | |
val password = text("password") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun Iterable<ResultRow>.toArticles(): List<Article> { | |
return fold(mutableMapOf<ArticleId, Article>()) { map, resultRow -> | |
val article = resultRow.toArticle() | |
val tagId = resultRow.tryGet(ArticleTagTable.tagId) | |
val tag = tagId?.let { resultRow.toTag() } | |
val current = map.getOrDefault(article.id, article) | |
map[article.id] = current.copy(tags = current.tags + listOfNotNull(tag)) | |
map | |
}.values.toList() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val ArticleWithTags = (ArticleTable leftJoin ArticleTagTable leftJoin TagTable) | |
override fun findBy(articleId: ArticleId) = | |
ArticleWithTags | |
.select { ArticleTable.id eq articleId } | |
.toArticles() | |
.singleOrNull() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun create(article: Article): Article { | |
val savedArticle = ArticleTable.insert { it.from(article) } | |
.getOrThrow(ArticleTable.id) | |
.let { article.copy(id = it) } | |
savedArticle.tags.forEach { tag -> | |
ArticleTagTable.insert { | |
it[ArticleTagTable.tagId] = tag.id | |
it[ArticleTagTable.articleId] = savedArticle.id | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object ArticleTagTable : Table("article_tags") { | |
val tagId = tagId("tag_id").references(TagTable.id) | |
val articleId = articleId("article_id").references(ArticleTable.id) | |
} |
NewerOlder