Skip to content

Instantly share code, notes, and snippets.

View brettrowberry's full-sized avatar

Brett Rowberry brettrowberry

View GitHub Profile
@brettrowberry
brettrowberry / isogram.clj
Last active March 17, 2022 15:22
Function to detect isograms.
(defn isogram?
"An isogram is a word in which no letters occur more than once.
Empty string is considered an isogram in this implementation."
[^String s]
(boolean
(when (string? s)
(loop [letters (sort (seq s))]
(let [[current next & _] letters]
(cond
(nil? next) true
(System/getProperty "user.dir")
debugger
#dbg
#break
;; These are equivalent expressions showing how to attempt to access a value:
(get {:a \a} :a)
({:a \a} :a)
(:a {:a \a})
;; These are equivalent ways of trying and supplying a default value:
(get {:a \a} :b \b)
({:a \a} :b \b)
(:b {:a \a} \b)
defaults write com.apple.Finder AppleShowAllFiles true
killall Finder
@brettrowberry
brettrowberry / clojure-vscode.json
Created September 15, 2021 20:00
Clojure Snippets for VS Code
// Thanks Nick Nichols
"Spy Function": {
"prefix": "spy",
"body": [
"(defn spy [x] (println x) x)"
],
"description": "Log a value and immediately return it"
}
@brettrowberry
brettrowberry / Clojure-clipboard.clj
Last active September 15, 2021 19:51
Write to and read from system clipboard in Clojure REPL
;; Credit, Nick Nichols
;; only tested on macOS Big Sur
(import '[java.awt.datatransfer DataFlavor StringSelection Transferable])
(defn clipboard []
(.getSystemClipboard (java.awt.Toolkit/getDefaultToolkit)))
(defn clipboard->str
[]
(.getTransferData (.getContents (clipboard) nil) (DataFlavor/stringFlavor)))
type Faucet =
| Hot
| Cold
[<EntryPoint>]
let main _ =
let myFaucet = Cold
match myFaucet with
| Cold -> 0
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<NoWarn>0025;</NoWarn>
</PropertyGroup>
<ItemGroup>
<Compile Include="FsAdvent2020.fs" />
// The 'compare' function from FSharp.Core returns a magic number to indicate the result
// compare : 'T -> 'T -> int when 'T : comparison
compare 0 1 //-1
compare 0 0 //0
compare 1 0 //1
// We could clarify our intent
type Leg = Less | Equal | Greater
type Comparer<'T> = 'T -> 'T -> Leg