Skip to content

Instantly share code, notes, and snippets.

View danielneal's full-sized avatar

Daniel Neal danielneal

View GitHub Profile
@danielneal
danielneal / gist:5f140fc0899e7551c54a
Last active August 29, 2015 14:01
Hoplon - How to handle collections of cells?
(page "index.html")
;; ---------------
;; View cell
;;
;; A view cell is a type of formula cell that only uses lookup operations.
;; This allows it to stay updatable (unlike other formula cells)
;; It is defined by calling `view-cell` with the root and a path.
;; The path is a vector of keys or indexes, as used in assoc-in, or update-in
;;
(ns hoplon.dimple.chart
(:require-macros [tailrecursion.javelin :refer [cell=]])
(:require [cljsjs.dimple]))
(def chart-types
{:line js/dimple.plot.line
:area js/dimple.plot.area
:bubble js/dimple.plot.bubble
:bar js/dimple.plot.bar})
@danielneal
danielneal / composite-keys-in-yesql
Created July 2, 2015 17:46
Querying postgres using composite keys with YeSQL / Clojure
;; currently anonymous record types are not supported by postgres/jdbc
;; however, it is possible to create a custom type and query using that
CREATE TYPE some_composite_key AS (first_id UUID,second_id TEXT);
;; implement jdbc/ISQLValue
(defrecord SomeCompositeKey [first_id second_id]
jdbc/ISQLValue
(sql-value [_]
(doto (PGobject.)
@danielneal
danielneal / clojure-sql-demo.clj
Last active April 14, 2016 12:37
Clojure-SQL relational algebra / query composition
(ns clojure-sql-demo
(:require [clojure-sql.core :as sql]) ;;[clojure-sql "0.2.0-SNAPSHOT"]
(def user-emails
(-> (sql/table :user_email_history)
(sql/project {:email :user_email_history.email
:user_id :user_email_history.user_id
:email_request_id :user_email_history.email_request_id})))
(def users
;; [ WITH [ RECURSIVE ] with_query [, ...] ]
;; SELECT [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ]
;; * | expression [ [ AS ] output_name ] [, ...]
;; [ FROM from_item [, ...] ]
;; [ WHERE condition ]
;; [ GROUP BY expression [, ...] ]
;; [ HAVING condition [, ...] ]
;; [ WINDOW window_name AS ( window_definition ) [, ...] ]
;; [ { UNION | INTERSECT | EXCEPT } [ ALL ] select ]
;; [ ORDER BY expression [ ASC | DESC | USING operator ] [ NULLS { FIRST | LAST } ] [, ...] ]
@danielneal
danielneal / eqt.sh
Created March 10, 2017 16:26
Command line tool for pretty-printing transit
#!/usr/local/bin/planck
(ns eqt.core
(:require [cljs.pprint :refer [pprint]]
[cljs.reader :as edn]
[planck.core :as planck]
[clojure.string :as string]
[cognitect.transit :as transit]))
(->> (repeatedly planck/read-line)
#!/usr/local/bin/planck
(ns eq.core
(:require [cljs.pprint :refer [pprint]]
[cljs.reader :as edn]
[planck.core :as planck]
[clojure.string :as string]))
(->> (repeatedly planck/read-line)
(take-while identity)
+-----------------------+--------------------------------+-----------------------+---------------------------------+-------------------------+
| \ To | Reagent Component | Reagent Hiccup Vector | React Component | React Element |
| From \ | | | | |
|-----------------------+--------------------------------+-----------------------+---------------------------------+-------------------------|
| Reagent Component | identity | | reagent.core/reactify-component | |
|-----------------------+--------------------------------+-----------------------+---------------------------------+-------------------------|
| Reagent Hiccup Vector | | identity | | reagent.core/as-element |
|----------------------
+-----------------------+--------------------------------+-----------------------+---------------------------------+-------------------------+
| \ To | Reagent Component | Reagent Hiccup Vector | React Component | React Element |
| From \ | | | | |
|-----------------------+--------------------------------+-----------------------+---------------------------------+-------------------------|
| Reagent Component | identity | | reagent.core/reactify-component | |
|-----------------------+--------------------------------+-----------------------+---------------------------------+-------------------------|
| Reagent Hiccup Vector | | identity | | reagent.core/as-element |
|----------------------
(ns app.graphql
(:require [om.next :as om]
[clojure.string :as str]
[clojure.set :as set]))
(defn graphql-type [v]
(cond
(string? v) "String"
(int? v) "Int"
(float? v) "Float"