Skip to content

Instantly share code, notes, and snippets.

@Deraen
Deraen / .vimrc
Last active March 15, 2017 06:32
Vimrc clojure parts
" Parts of my .vimrc which might be relevant to Clojure users.
" Src: https://raw.githubusercontent.com/Deraen/dotfiles/master/.vimrc
" NeoBundle is a Vim package manager
" Check https://github.com/Shougo/neobundle.vim for installation
" Autocomplete - https://github.com/Valloric/YouCompleteMe
NeoBundle 'Shougo/vimproc', {'build': {'unix': 'make'}}
NeoBundle 'Valloric/YouCompleteMe'
" Clojure syntax highlight
@Deraen
Deraen / recap.clj
Last active November 11, 2015 15:04
Futurice training, 5.6.2014
(ns working-with-data
(:require [working-with-data.data :refer [participants]]))
;; Futu training, 5.6.2014
;; RECAP
(def a {:name "Juho"})
;; assoc - return a new map
(assoc a :age 24)
@Deraen
Deraen / daemon.clj
Last active August 29, 2015 14:02
Clojure daemon (jsvc, centos initscript) NOTE: Not very complete initscript
(ns foobar.daemon
(:require [foobar.main :as main])
(:import [org.apache.commons.daemon Daemon DaemonContext])
(:gen-class
:implements [org.apache.commons.daemon.Daemon]))
(def state (atom nil))
;; Daemon implementation
(defn -init [this ^DaemonContext context])
@Deraen
Deraen / working-with-data.clj
Created August 20, 2014 10:49
Clojure bootcamp, 20.8.2014, muistiinpanot / hands-on
(ns working-with-data
(:require [metosin.dataset.pizzas :refer [pizzas]]))
(conj pizzas {:name "Speciale"})
; v1
(filter (fn [pizza]
(if (< (get pizza :price) 8)
true))
pizzas)
(defn mrg [[x & xrest :as X] [y & yrest :as Y] R]
(if (and X Y)
(if (<= x y)
(recur xrest Y (conj R x))
(recur X yrest (conj R y)))
(concat R X Y)))
(defn mrgsrt [X]
(if (> (count X) 1)
(let [[left right] (split-at (/ (count X) 2) X)]
(defn outrun-2 [pyramid]
(->> pyramid
(reduce
(fn [previous line]
(mapv (fn [this i]
(let [left (get previous (dec i) 0)
right (get previous i 0)]
(+ this (max left right))))
line
(range))))
(ns reaktor-outrun.core
(:require [nio.core :as nio]
[clojure.java.io :as io]
[hiphip.int :as hh])
(:gen-class :main true))
(set! *warn-on-reflection* true)
(set! *unchecked-math* true)
;; http://reaktor.fi/blog/fast-track-osa-kolme-koodaa-out-run-lempikielellasi/
@Deraen
Deraen / components.clj
Last active December 15, 2019 08:03
Compojure-api with Component
(ns foobar.components
(:require [com.stuartsierra.component :as component]
[compojure.api.sweet :refer :all]))
(defmethod compojure.api.meta/restructure-param :components
[_ components acc]
(update-in acc [:letks] into [components `(::components ~'+compojure-api-request+)]))
(defn wrap-components [handler components]
(fn [req]
@Deraen
Deraen / viikko43.hs
Last active August 29, 2015 14:08
Some Haskell excercises
#!/usr/bin/env runhaskell
import System.IO
import Control.Monad
import qualified Data.Text as T
splitLines :: String -> [String]
splitLines s = map T.unpack $ T.splitOn (T.pack ",") $ T.pack s
readNumbers :: [String] -> [Int]
readNumbers = map (\x -> read x :: Int)
(defn debounce
"Creates a channel which will change put a new value to the output channel
after timeout has passed. Each value change resets the timeout. If value
changes more frequently only the latest value is put out.
When input channel closes, the output channel is closed."
[in ms]
(let [out (chan)]
(go-loop [last-val nil]
(let [val (if (nil? last-val) (<! in) last-val)