Skip to content

Instantly share code, notes, and snippets.

View tatut's full-sized avatar

Tatu Tarvainen tatut

View GitHub Profile
(ns webjure.wiki
(:refer-clojure)
(:use webjure)
(:use webjure.html))
(def *pages* (ref {}))
(defn update-page [page-name title body]
(dosync
(alter *pages*
(ns bug
(:require [reagent.core :refer [atom] :as reagent]))
;; This version does not work: changed values of all-selections or
;; selected atoms are not reflected in the markup.
;; The open swap! works as expected.
(defn pulldown [selected format-fn select-fn selections]
(let [open (atom false)]
(fn []
[:div.pulldown-menu
@tatut
tatut / weather.10m.sh
Created January 5, 2016 15:08
Bitbar plugin to fetch weather (air and road temps) from Finnish Transport Agency weather camera
#!/bin/sh
# To change the station, go to http://liikennetilanne.liikennevirasto.fi/
# and open the network inspector when clicking a weather camera.
# Copy the URL below.
curl -s "https://services1.arcgis.com/rhs5fjYxdOG1Et61/ArcGIS/rest/services/RWS_station/FeatureServer/0/query?f=json&where=NUMERO%3D13008&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=windSpeed%2CwindDirection%2CTSA_NIMI%2CmeasurementTime%2CairTemperature%2CroadTemperature%2CroadSurfaceCondition" | /usr/local/bin/jq -r "\"Ilma: \\(.features[0].attributes.airTemperature), Tie: \\(.features[0].attributes.roadTemperature)\""
@tatut
tatut / args.clj
Created March 6, 2016 10:54
Uncle Bob's arg parsing in Clojure
(ns args)
(defn- parse-schema
"Parse comma separated schema. Returns map of character to type keyword."
[schema-spec]
(into {}
(map (fn [flag]
(let [chr (.charAt flag 0)
spec (subs flag 1)]
[chr (case spec
[{"url":"https://api.github.com/repos/finnishtransportagency/harja/pulls/99","id":80041335,"html_url":"https://github.com/finnishtransportagency/harja/pull/99","diff_url":"https://github.com/finnishtransportagency/harja/pull/99.diff","patch_url":"https://github.com/finnishtransportagency/harja/pull/99.patch","issue_url":"https://api.github.com/repos/finnishtransportagency/harja/issues/99","number":99,"state":"open","locked":false,"title":"Tee materiaalin käytöstä uniikki","user":{"login":"tatut","id":83725,"avatar_url":"https://avatars.githubusercontent.com/u/83725?v=3","gravatar_id":"","url":"https://api.github.com/users/tatut","html_url":"https://github.com/tatut","followers_url":"https://api.github.com/users/tatut/followers","following_url":"https://api.github.com/users/tatut/following{/other_user}","gists_url":"https://api.github.com/users/tatut/gists{/gist_id}","starred_url":"https://api.github.com/users/tatut/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tatut/subscriptions",
@tatut
tatut / github.5m.cljs
Created August 19, 2016 06:34
Bitbar plugin to fetch Harja project's open PR:s
#!/usr/local/bin/planck
(ns github.core
(:require [planck.http :as http]
[planck.core :refer [spit slurp]]
[planck.shell :as sh]))
(def gh-url "https://api.github.com/")
(defn load-gh-uri [uri]
(sh/sh "curl" "-o" "/tmp/harja-pulls.json" (str gh-url uri))
(ns m
(:require [clojure.java.io :as io]
[clojure.pprint :refer [*print-suppress-namespaces* pprint]]
[clojure.repl :refer [doc source]]))
;; Utility ennen/jälkeen tulosteille
(defmacro m [form]
(binding [*print-suppress-namespaces* true]
(println "\n----ENNEN:" )
(pprint form)
@tatut
tatut / pivotal.cljs
Created November 8, 2017 06:41
Script for Bitbar (getbitbar.com) to your current work items
#!/usr/local/bin/planck
(ns pivotal.core
(:require [planck.http :as http]
[planck.core :refer [spit slurp]]
[planck.shell :as sh]
[clojure.walk :as walk]
[clojure.string :as str]))
;; Config section
(def pivotal-token "your token here")
@tatut
tatut / string_wrap.clj
Created April 10, 2018 18:14
String wrap (by splitting to words)
;; keeps original new-lines, so that there may be shorter lines
;; caveat: if a single word is longer than the split length, it will overflow
(defn split-line [n line]
(reduce
(fn [lines word]
(if (or (empty? lines)
(>= (+ (count (last lines)) (count word)) n))
(conj lines word)
(update lines (dec (count lines)) str " " word)))
@tatut
tatut / ec2.clj
Created April 20, 2018 18:32
Automatically generated clojure.spec definitions from AWS CloudFormation JSON spec
(ns aws.ec2
"AUTOGENERATED clojure.spec definitions"
(:require [clojure.spec.alpha]))
(clojure.spec.alpha/def
:aws.ec2/launch-template
(clojure.spec.alpha/keys
:req
[]
:opt