Skip to content

Instantly share code, notes, and snippets.

@sw1nn
sw1nn / asciidoc.el
Last active September 1, 2022 13:45
(defvar-local sw1nn/adoc-remappings nil)
(defcustom sw1nn/adoc-hide-faces
'(markup-meta-face markup-meta-hide-face)
"faces to hide in adoc"
:group 'sw1nn
:type 'list
)
(defun sw1nn/adoc-hide-meta-characters ()
(ns regroup
(:require [clojure.string :as str]
[clojure.test.check :as tc]
[clojure.test.check.generators :as gen]
[clojure.test.check.properties :as prop]
))
(defn regroup [s n]
(let [patt (re-pattern (str "(?x:\n"
@sw1nn
sw1nn / flames_repl.clj
Created May 18, 2022 13:05
Repl fns to generate a flame graph. (Not super sophisticated!)
;; Assumes https://github.com/jstepien/flames available
;; requires http://riemann.io to be installed.
(def flames (atom nil))
(defn flames-start! []
;; We resolve explicitly here, to avoid warnings when not working
;; with flamegraphs
(if-not @flames
(let [config {:port 54321, :host "localhost"}]
(reset! flames ((requiring-resolve 'flames.core/start!) config))
/*--- waitForKeyElements(): A utility function, for Greasemonkey scripts,
that detects and handles AJAXed content.
Usage example:
waitForKeyElements (
"div.comments"
, commentCallbackFunction
);
(ns euler-fizz-buzz)
;; Inspired by http://philcrissman.net/posts/eulers-fizzbuzz/
(defn mod-pow [b e m] (long (.modPow (biginteger b) (biginteger e) (biginteger m))))
(defn fizz-buzz [] (map #({6 "Fizz" 10 "Buzz" 0 "FizzBuzz"} (mod-pow % 4 15) %) (range 1 100)))
;;https://en.wikipedia.org/wiki/Euler%27s_totient_function
;;https://oeis.org/A000010
(defn parse-rfc7231-accept-charset [s]
(->> s
(re-seq rfc-7231-re)
(keep #(vector (.group % "charset")
(some-> (.group % "weight")
Float/parseFloat)))
(into {})))
(defn re-seq
"Returns a lazy sequence of successive matches of pattern in string,
using java.util.regex.Matcher.find(), each such match processed with
re-groups."
{:added "1.0"
:static true}
[^java.util.regex.Pattern re s]
(let [m (re-matcher re s)]
((fn step []
(when (. m (find))
(def input ", \t, , , UTF-8;q=0.8,shift_JIS;q=0.4,a,b")
(def rfc-7231-re #"(?x)
(?:
\s* # OWS
(?<charset>\*|[\p{Alnum}!\#\$\%\&'\*\+\-\.\^_\`\|\~]+)
(?i:
;q=
(?<weight>0\.\d{1,3}|1\.0{1,3})
)?
(def input ", \t, , , UTF-8;q=0.8,shift_JIS;q=0.4,a,b")
(def rfc-7231-re #"(?x)
(?:
\s* # OWS
(?<charset>\*|[\w\d_-]+)
(?i:
;q=
(?<weight>0\.\d{1,3}|1\.0{1,3})
)?
fn solution01() -> u64 {
INPUT.iter().fold(0, |a, line| {
let ref words: Vec<&str> = line.split_whitespace().collect();
let uniq_words: BTreeSet<&&str> = words.into_iter().collect();
if words.len() == uniq_words.len() {
a + 1
} else {
a
}
})