Skip to content

Instantly share code, notes, and snippets.

View clojens's full-sized avatar

Rob Jentzema clojens

View GitHub Profile
(require 'iimage)
(autoload 'iimage-mode "iimage" "Support Inline image minor mode." t)
(autoload 'turn-on-iimage-mode "iimage" "Turn on Inline image minor mode." t)
(add-to-list 'iimage-mode-image-regex-alist '("@startuml\s+\\(.+\\)" . 1))
;; Rendering plantuml
(defun plantuml-render-buffer ()
(interactive)
(message "PLANTUML Start rendering")
(shell-command (concat "java -jar ~/Downloads/plantuml.jar "
@clojens
clojens / inspect.clj
Created March 30, 2013 00:14
Most useful Clojure one-liners for reference, sanity and general information need of beginning developers.
;; Note: for the best result/experience you should download LightTable at www.lighttable.com
;; Open the program, press [^-Space] (Control-Space) and type "Insta" then click/press [Return] to open one and paste this in
;; Macro to define/create namespace and bind neatly only the required functions (explicit use of :refer key)
(ns clj-no.de
^{:doc "Namespace and directives for easy inspection of symbols, hash-maps, namespaces and so on."
:author "Rob Jentzema"
:version "0.01"}
;; These provide us with easy access to some very useful functions
;;
;; NS CHEATSHEET
;;
;; * :require makes functions available with a namespace prefix.
;;
;; * :use makes functions available without a namespace prefix
;; (i.e., refers functions to the current namespace).
;;
;; * :import refers Java classes to the current namespace.
;;
;variants of the code from point #2 of:
; http://www.tbray.org/ongoing/When/200x/2009/12/01/Clojure-Theses
;original
(apply merge-with +
(pmap count-lines
(partition-all *batch-size*
(line-seq (reader filename)))))
@clojens
clojens / 1.md
Last active December 17, 2015 22:19
Python/Sublime regexp

Seperate paragraphs using Python/Sublime2 regular expressions:

\s*?\n\s*?\n\s*?

Fetch all predicate symbol names in second group

(\(defn )(\w.*\?)
@clojens
clojens / project.clj
Last active September 15, 2020 11:56
Semantic grid in Clojure Garden DSL for CSS generation.
(defproject gridsystem "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.5.1"]
[compojure "1.1.5"]
[garden "1.0.0-SNAPSHOT"]
[ring/ring-jetty-adapter "0.2.5"]
[hiccup "1.0.4"]]
:plugins [[lein-ring "0.8.5"]]
:ring {:handler semantic-gs.handler/app}
:profiles
{:dev {:dependencies [[ring-mock "0.1.5"]]}})
@clojens
clojens / read.md
Last active December 20, 2015 02:38
Evil Clojure

read

Namespace clojure.core
Description

Reads the next object from stream, which must be an instance of java.io.PushbackReader or some derivee. Stream defaults to the current value of *in*.

Usage
@clojens
clojens / class.txt
Last active December 20, 2015 15:09
@startuml
class Car
Driver - Car : drives >
Car *- Wheel : have 4 >
Car -- Person : < owns
@enduml
@clojens
clojens / polling.clj
Created August 19, 2013 11:24
Long polling example in Clojure
(ns long-polling
(:require [clojure.data.json :as json]))
(def timeout 100) ; sec
;[clojure.contrib.http.agent :as h]
;(use 'clojure.contrib.http.agent)
; fetch, this will wait if no messages are active
;(string (http-agent "http://127.0.0.1/activity?id=1"))
(ns pigeonhole-sort)
(defn int-sort [s]
(let [listmap (reduce #(update-in
(update-in %1 [%2] (fnil inc 0))
[:max] max %2) {:max 0} s)]
(mapcat #(repeat (get listmap % 0) %)
(range (inc (:max listmap))))))