This file contains hidden or 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 llp.server | |
(:require [cljs.nodejs :as node] | |
[clojure.string :as str])) | |
(def net (node/require "net")) | |
(def events (node/require "events")) | |
(defn bufs->string [bufs] | |
(loop [acc "" | |
rst bufs] |
This file contains hidden or 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
(defn lazily-distinct [coll] | |
"Returns a lazy distinct list of possibly infinite collection. | |
Does not realize the whole collection." | |
(letfn [(lazystep [seen l] | |
(lazy-seq | |
(when (seq l) | |
(loop [next-item (first l) lazy-list (rest l)] | |
(if (get seen next-item) | |
(recur (first lazy-list) (rest lazy-list)) | |
(cons next-item (lazystep (conj seen next-item) |
This file contains hidden or 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
package demo | |
class Coder(words: List[String]) { | |
private val mnemonics = Map( | |
'2' -> "ABC", '3' -> "DEF", '4' -> "GHI", '5' -> "JKL", | |
'6' -> "MNO", '7' -> "PQRS", '8' -> "TUV", '9' -> "WXYZ") | |
private val charCode: Map[Char, Char] = | |
for ((digit, str) <- mnemonics; letter <- str) yield letter -> digit |
This file contains hidden or 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
#!/bin/bash | |
# expects filename as first arg | |
# Using jack highly recommended over alsa | |
# Make sure you set up real time priorities | |
pasuspender -- qjackctl & | |
echo Before pressing play, go into the jack GUI and \ | |
connect the source to the sink. |
This file contains hidden or 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 cljdojo.coin | |
(:require [clojure.test :refer :all])) | |
(def coins (sorted-set-by > 50 25 10 5 1)) | |
(defn min-coins [total] | |
(letfn [(step [[remaining tallies] coin] | |
(let [decrements (->> (iterate #(- % coin) remaining) | |
(take-while #(>= % coin)) | |
count) |
This file contains hidden or 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 fancie-queues | |
(:import [java.util.concurrent BlockingQueue | |
LinkedBlockingQueue])) | |
;; see queue-chain at the bottom | |
;; (queue-chain (range 20) (map (partial * 5)) (map vector) (map pr-str)) | |
;; (queue-chain (range 20) (remove odd?) (map pr-str)) | |
;; for more fun: | |
;; (queue-chain (range 20) (remove odd?) (map (fn [i] (Thread/sleep 150) (pr-str i)))) | |
;; throwing an exception in the middle will not be fun, fyi also queues don't take nil |
This file contains hidden or 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
(require '[clojure.string :as str]) | |
(defn rename-underscore [sym] | |
[(symbol (str/replace (name sym) \_ \-)) | |
(keyword sym)]) | |
(defn udestructure [[lhs expr]] | |
(if (and (map? lhs) | |
(vector? (:_keys lhs))) | |
(let [msym (gensym) |
This file contains hidden or 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
;; Reimplementation of Java's (.split Pattern) to be zero-allocation, similar | |
;; to JDK 8 splitAsStream | |
;; Discards trailing "" | |
;; respects `clojure.core.reduced` | |
(defn split-string | |
[^CharSequence s ^java.util.regex.Pattern re] | |
(reify clojure.core.protocols/CollReduce | |
(coll-reduce [_ f init] | |
(let [m (re-matcher re s) |
This file contains hidden or 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 foldtest | |
(:require [clojure.core.reducers :as r])) | |
;; redefined to parameterize the threshold to r/fold | |
(defn foldcat [n coll] | |
(r/fold n r/cat r/append! coll)) | |
(defn benchmark [n] | |
(let [x (into [] (range 1e8))] | |
(println "init vec") |
This file contains hidden or 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
-- these are for daily | |
-- generated by accompanying code | |
select * from delivery_stats where delivery_id in | |
(66124923, 66124925, 66124927, 66124929, 66124931, 66124933, 66124935, 66124937, 66124939, 66124941, 66124943, 66124945, 66124947, 66124949, 66124951, 66124953, 66124955, 66124957, 66124959, 66129249, 66129251, 66129253, 66129255, 66129257, 66129259, 66129261, 66129263, 66129265, 66129267, 66129269, 66129271, 66129273, 66129275, 66129277, 66129279, 66129281, 66129283, 66129285, 66129287, 66129289, 66129291, 66129293, 66129299, 66129301, 66129303, 66129305, 66129307, 66129311, 66124879, 66124883, 66124885, 66124887, 66124889, 66124891, 66124893, 66124895, 66124897, 66124899, 66124901, 66124903, 66124905, 66124907, 66124915, 66124919, 66124921, 66128365, 66128383, 66128255, 66128257, 66128259, 66128261, 66128263, 66128265, 66128269, 66128271, 66128273, 66128275, 66128281, 66128283, 66128285, 66128287, 66128289, 66128291, 66128293, 66128295, 66128297, 66128301, 66128305, 66128307, 66128309, 66128313, 661 |
OlderNewer