Skip to content

Instantly share code, notes, and snippets.

@micha
micha / gist:997056
Created May 28, 2011 17:34
Euler project problem #1
#! /usr/bin/env racket
; Euler problem #1. Sum of integers between 1 and N which are
; divisible by i, j, k, ..., or l.
;
; The sum 1+2+3+...+n = (n^2 + n)/2, call this sum-range(n).
;
; Then the sum of i+2i+3i+...+qi = i * sum-range(floor(n/i)), where
; qi is the greatest multiple of i such that i <= n.
;
@micha
micha / rpc.clj
Created March 17, 2014 15:45
Datomic transactor function that works like Clojure's `swap!` function.
{:db/id #db/id[:db.part/db]
:db/doc "Works like clojure.core/swap!, basically."
:db/ident :swap!
:db/fn #db/fn {:lang "clojure"
:params [db id k expr args]
:code "(let [f (if-not (string? expr)
(resolve expr)
(eval (read-string expr)))
e (datomic.api/entity db id)
v (apply f (concat [(get e k 0)] args))]
@micha
micha / build.clj
Created April 25, 2014 16:38
Boot tasks: run tasks in the background, etc.
(def bgs
"List of tasks running in other threads that will need to be cleaned up before
boot can exit."
(atom ()))
;; cleanup background tasks on shutdown
(-> (Runtime/getRuntime)
(.addShutdownHook (Thread. #(doseq [job @bgs] (future-cancel job)))))
(deftask once
@micha
micha / index.cljs.clj
Last active September 6, 2023 04:41
Hoplon example: simple survey using Twitter Bootstrap
(page "index.html"
(:refer-hoplon :exclude [form])
(:require
[clojure.string :as string]
[tailrecursion.hoplon.reload :refer [reload-all]]))
;; auto-reload the page when you modify this file
(reload-all)
;; UTILITY FUNCTIONS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@micha
micha / gist:37b02eb356094f8611f9
Created July 12, 2014 19:29
Hoplon discourse site code markdown
I've been using the triple-backquote method and it works pretty well. For example:
```
(map inc [1 2 3])
```
Check out [the source for this post](https://gist.github.com/micha/37b02eb356094f8611f9) on GitHub.
@micha
micha / text-macro.clj
Created August 22, 2014 14:50
text= macro
(defmacro text= [form]
`(tailrecursion.javelin/cell= ~(interpol8 form)))
@micha
micha / cli_util.clj
Last active August 29, 2015 14:06
Clojure macro defines a macro which evaluates expressions with some bindings.
(defmacro defbound [sym bindings]
`(defmacro ~sym [& body#]
`(let ~'~bindings ~@body#)))
(comment
user=> (defbound with-xy [x 100 y 200])
#'user/with-xy
user=> (with-xy (+ x y))
300
)
@micha
micha / .vimrc
Created November 15, 2014 18:06
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
@micha
micha / .vimrc
Created November 15, 2014 21:17
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
;; -*- mode: clojure; -*-
(set-env!
:src-paths #{"src/clj" "src/cljs"}
:rsc-paths #{"resources"}
:update :always
:dependencies '[[org.clojure/clojure "1.7.0-alpha4"]
[org.clojure/core.async "0.1.346.0-17112a-alpha"]
[com.taoensso/timbre "3.3.1-1cd4b70"]
[http-kit "2.1.19"]