Skip to content

Instantly share code, notes, and snippets.

View attentive's full-sized avatar

Tom attentive

View GitHub Profile
@attentive
attentive / leaflet-helloworld.cljs
Last active August 29, 2015 14:00
LeafletJS Hello World in Om and ClojureScript
(ns leaflet-helloworld
(:require [om.core :as om :include-macros true]
[om.dom :as dom :include-macros true]))
(defn map-view [_ owner]
(reify
om/IRender
(render [_]
(dom/div #js {:id "the-map"} nil))
om/IDidMount
@attentive
attentive / conduit.clj
Last active August 29, 2015 14:03
Shows one way to create a "dynamic deftemplate" for Enlive
(ns gist.conduit
(:use [net.cgrand enlive-html tagsoup]))
; The implementations of conduit and defconduit are modified versions of
; the macros template and deftemplate from the guts of Enlive.
; They're named 'conduit' because the selectors and transformations serve as a
; channel between the scaffold of HTML and some data provided as an argument.
; Tagsoup is used to parse a list of HTML nodes from a specified input file at runtime.
@attentive
attentive / main.js
Created June 7, 2011 15:13
Prettified Mapnificent
window.Mapnificent = (function (window, document, $, undefined) {
var getOSMMapType = function () {
return new google.maps.ImageMapType({
getTileUrl: function (coord, zoom) {
return "http://tile.openstreetmap.org/" + zoom + "/" + coord.x + "/" + coord.y + ".png"
},
tileSize: new google.maps.Size(256, 256),
isPng: true,
maxZoom: 18,
name: "OSM"
(ns vchain.graph
(:require [om.core :as om :include-macros true]
[cljs.core.async :as async :refer [put! chan mult]]
[clojure.string :as string :refer [join]]
[sablono.core :as html :refer-macros [html]]
[strokes :refer [d3]]
vchain.links
vchain.routes
vchain.slug
vchain.wrap))
@attentive
attentive / add-watch.cljc
Created May 5, 2017 04:09
Using Clojure add-watch to track the previous state of an atom
(def current (atom 1))
(def previous (atom nil))
(add-watch current :dontcare
(fn [_ _ old-state _]
(reset! previous old-state)))
(repeatedly 10 #(do (swap! current * 2)
(println "Current:" @current "Previous:" @previous)))
@attentive
attentive / leaflet.cljs
Last active September 16, 2017 09:25
Adapting React components in Rum
(ns project.leaflet
(:require-macros [project.macros :as m])
(:require [rum.core :as rum]
cljsjs.react-leaflet)) ;; js/ReactLeaflet
(m/adapt-react leaflet-map js/ReactLeaflet.Map)
(m/adapt-react tile-layer js/ReactLeaflet.TileLayer)
(m/adapt-react marker js/ReactLeaflet.Marker)
(m/adapt-react popup js/ReactLeaflet.Popup)
@attentive
attentive / postgis.clj
Created October 29, 2012 10:25
PostGIS and Korma
(ns postgis
(:require [clj-json.core :as json])
(:use korma.core korma.db korma.sql.engine))
(defn intersects [first-geom second-geom]
"An extended Korma predicate that uses the PostGIS function ST_Intersects."
(sql-func "ST_Intersects" first-geom second-geom))
(defn from-wkt [wkt]
"Create a PostGIS geometry with geographic SRID from WKT using ST_GeomFromText."
(ns fizzbuzz
(:require [clojure.core.match :refer [match]]))
(defn interpret [x y i]
(match [x y i]
[true true _] "FizzBuzz"
[true false _] "Fizz"
[false true _] "Buzz"
:else i))
@attentive
attentive / pg2mvt.sh
Created November 26, 2018 03:11
Connect to PostGIS and export vector tiles
# This rigmarole should connect successfully first
ogrinfo PG:"dbname='databasename' host='addr' port='5432' user='x' password='y'" layername
# Requires GDAL 2.3 or higher (current stable Ubuntu packages for Bionic are only 2.2.x)
ogr2ogr -f MVT out.mbtiles PG:"dbname='databasename' host='addr' port='5432' user='x' password='y'" layername
@attentive
attentive / core.cljs
Last active February 12, 2019 04:53
How to integrate react-native-splash-screen with ClojureScript
(ns rnss.core
(:require [oops.core :refer [oget ocall]]
[reagent.core :as r]
["react-native" :as RN]
["react-native-splash-screen" :as RNSS]))
;; The code below depends on the existence of a separate splash screen
;; layout in your app, as per the react-native-splash-screen doco.
;; This sample shows only how to reference the splash screen library and