Skip to content

Instantly share code, notes, and snippets.

@kdabir
kdabir / README.md
Last active Aug 29, 2015
This script pulls your starred repos on github and shows some interesting stats at the end. It was created as an example demonstrating how Gstorm is useful in scripts.
View README.md

This script is created as an example to show how easy it is to use gstorm to crunch and consume data from rest apis.

Usage

Either download the script and run:

groovy ghstarred.groovy <your_github_id>

Or hotload it:

View variant.clj
(ns variant
(:require [clojure.core.typed :as t]))
(t/defalias V
(t/Rec [V]
(t/U '[':lambda t/Sym V]
'[':if V V V]
'[':val t/Any])))
(t/ann command [V -> t/Str])
View defmacro-thing.clj
(defmacro defvariant
[name [[tag & variant-binders] & other-binders] body]
`(defmethod ~name ~tag [[_# ~@variant-binders]
~@other-binders]
~body)
[name [tag & binders] body]
`(defmethod ~name ~tag [[_# ~@binders]] ~body))
; CompilerException java.lang.RuntimeException: Unable to resolve symbol: & in this context, compiling:(/tmp/form-init8620656005427572977.clj:1:1)
@stianeikeland
stianeikeland / variant.clj
Last active Aug 29, 2015
variant core.typed
View variant.clj
(ns variants-playground.core
(:require [clojure.core.typed :as t :refer [cf defalias ann U Value Str HVec HMap]]
[clojure.core.match :refer [match]]))
(defmacro Variant [& lst]
`(U ~@(for [[tag & items] lst]
`(HVec [(Value ~tag)
(HMap :mandatory ~@items)]))))
(println (macroexpand '(Variant [:foo {:bar Str}])))
View reports3.clj
(defn download-report [{:keys [client date] :as state}]
;; snip
(assoc state :file downloaded-file))
(defn upload-to-s3 [{:keys [file] :as state}]
;; snip
(assoc state :bucket bucket :key key))
(defrecord Transition [op next-state])
@cgrand
cgrand / transmogrify.clj
Last active Aug 29, 2015
transmogrify->> rewrites last-threaded forms to use transducers.
View transmogrify.clj
(defmulti transmogrify
"Rewrites the last form of a thread-last to use transducer (if possible)."
(fn [f xform src & args] f))
(defmacro transmogrify->>
"Like ->> but uses transducers"
([x] x)
([src & xs]
(let [end (last xs)
xforms (butlast xs)
@clojj
clojj / plugin.groovy
Last active Aug 29, 2015
Runs in LivePlugin for IntelliJ
View plugin.groovy
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.editor.markup.EffectType
import com.intellij.openapi.editor.markup.HighlighterTargetArea
import com.intellij.openapi.editor.markup.TextAttributes
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.LangDataKeys
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.PsiRecursiveElementWalkingVisitor
@clojj
clojj / kahn.clj
Last active Aug 29, 2015 — forked from alandipert/kahn.clj
Kahn's topological sort in Clojure
View kahn.clj
;; Copyright (c) Alan Dipert. All rights reserved.
;; The use and distribution terms for this software are covered by the
;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
;; By using this software in any fashion, you are agreeing to be bound by
;; the terms of this license.
;; You must not remove this notice, or any other, from this software.
(ns alandipert.kahn
(:require [clojure.set :refer [difference union intersection]]))
@clojj
clojj / plugin.groovy
Last active Aug 29, 2015
highlight Cursive code
View plugin.groovy
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.LangDataKeys
import com.intellij.openapi.editor.Document
import com.intellij.openapi.editor.markup.EffectType
import com.intellij.openapi.editor.markup.HighlighterTargetArea
import com.intellij.openapi.editor.markup.TextAttributes
import com.intellij.openapi.util.Condition
import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
@ck
ck / levenshtein.clj
Created May 7, 2011 — forked from vishnuvyas/levenshtein.clj
A purely functional implementation of levenshtein distance in clojure
View levenshtein.clj
(ns levenshtein
^{:doc "A purely functional implementation of the levenshtien distance in clojure"})
(defn- compute-next-row
"computes the next row using the prev-row current-element and the other seq"
[prev-row current-element other-seq pred]
(reduce
(fn [row [diagonal above other-element]]
(let [update-val
(if (pred other-element current-element)