This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require | |
'[marsrover.grid :as grid] | |
'[marsrover.robot :as robot] | |
'[marsrover.core :refer :all]) | |
;; 10x10 grid with obstacle at 1,1. Robot moves beside it. | |
(let [grid (grid/make-grid [10 10] [[1 1]]) | |
robot (robot/make-robot [0 0] \n grid)] | |
(tell-robot robot "fffrf")) | |
;;{:robot {:pos [1 3], :dir \e, :grid {:dim [10 10], :obstacles {[1 1] true}}}, :status :ok} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=OpenVPN | |
After=docker.service | |
Requires=docker.service | |
[Service] | |
TimeoutStartSec=0 | |
Environment="OVPN_DATA=ovpn-data" | |
Environment="OVPN_IMAGE=kylemanna/openvpn" | |
Environment="OVPN_CONTAINER=openvpn_server" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Based on | |
;; http://bjeanes.com/2012/09/call-clojure-function-on-a-timer | |
;; Example: | |
;; (def flag (atom true)) | |
;; (tick-while flag 1000 (fn [s] (println (str s ":" (System/currentTimeMillis)))) "Time") | |
;; wait for some time and | |
;; (swap! flag (fn [_] false)) | |
(defn tick-while | |
"Executes the function f (side-effects) with args every t ms until p-ref de-references to false." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; From the REPL | |
(require '[clojure.math.numeric.tower :as math]) | |
(defn histo | |
[v & {:keys [size] :or {size 40}}] | |
(letfn [(digits-for-num [x] | |
(inc | |
(int (math/floor (/ (Math/log x) (Math/log 10))))))] | |
(let [mm (apply max v) | |
digits-x (digits-for-num (count v)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns minisink.Sink | |
(:import | |
minisink.Sink | |
(org.apache.flume Context Sink$Status)) | |
(:gen-class | |
:extends org.apache.flume.sink.AbstractSink | |
:implements [org.apache.flume.conf.Configurable] | |
;; state an object will have. Use atoms, refs or agents | |
;; to introduce mutability. It will be exposed as a method. | |
:state state |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; from the REPL | |
(import java.awt.GraphicsEnvironment) | |
(doseq [fnt (.. (GraphicsEnvironment/getLocalGraphicsEnvironment) getAvailableFontFamilyNames)] | |
(println fnt)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; From the REPL | |
(import '(java.awt GraphicsEnvironment Font) java.io.File) | |
(.. (GraphicsEnvironment/getLocalGraphicsEnvironment) | |
(registerFont (Font/createFont Font/TRUETYPE_FONT | |
(File. "font.ttf")))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro validate-args | |
[exp msg] | |
`(when-not ~exp | |
(throw (IllegalArgumentException. ~msg)))) | |
(defmacro chan-pipe | |
;; first and last body functions will be prepended an argument (the out and in channel) | |
;; internal body functions will be prepended two arguments in and out channels | |
[bindings & body] | |
(validate-args (vector? bindings) "bindings should be a vector") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def partition(seq, num): | |
"Partititons a seq en disjoint seqs of up to num elems" | |
return [seq[start:start+count] \ | |
for (start, count) in \ | |
[(num * x,y) for (x,y) in \ | |
zip(range(len(seq)/num), [num]*(num*(len(seq)/num)))] + | |
[(num * (len(seq)/num), len(seq) % num)] | |
if count >0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/expect | |
# Example script for rsync-ing a path when | |
# it is not possible to use ssh keys. | |
# This is not good practice. Adding a password | |
# to a file never is. Even less when it is used | |
# to bypass some security mechanisms implemented by | |
# ssh. | |
# It should be used only in very specific situations. | |
# It is left here for reference. |
OlderNewer