Skip to content

Instantly share code, notes, and snippets.

;; This is a stand alone version of https://github.com/petterik/om/commit/c99f1b892f0a143fba6ce57c3ffefc7ce1e2b9a0
;; Changed so that in path-meta, we're parsing the joins from a query one time for each data collection
;; instead of parsing joins for each item in the collection.
;; This gist contains implementation and a test.
;; It's runnable with planck by either downloading the gist as gist.cljs and passing it to planck
;; with the om source code:
;; planck -c "<path-to-om-project>/src/main" gist.cljs
(ns petterik.path-meta-perf
@petterik
petterik / macro-fail.clj
Created March 24, 2016 13:39
Calling a declared macro results in "wrong number of args (-1)"
(declare fail)
(defn fail* [m]
(if (map? m)
(fail 1)
m))
(defmacro fail [m]
(if (map? m)
(fail* m)
(ns navigation.example
(:require-macros [natal-shell.components :refer [navigator]]
[navigation.macros :refer [with-om-vars]])
(:require [om.next :as om]))
;;; Helpers for getting a deep ref
(defn react-ref
"Wrapper around react-ref to always turn keywords into strings."
[component ref]
@petterik
petterik / gist:50779d8cf15d6b6443e4
Created February 22, 2016 14:47
Trying optimistic updates with om.next, datascript and datomic [Questions]
I'm trying to implement optimistic updates using om.next, datascript and datomic. Mutations should be visible instantly in the UI (the optimistic part) and synced with datomic once the mutation has been successfully transacted. Mutations should also be retryable.
I might be going about this all wrong, but here's the way I'm going about it:
Client:
0. Call om/transact with a mutation `[(my/mutation { ... }) :read/this...]
1. Transact update to datascript and save the optimistic transaction's tx number.
2. Pass the optimistic tx number in the remote's ast's :params (more on this later).
Server:
3. Transact update to datomic returning entities created in datomic and the optimistic tx number from :params, to client.
Client:
@petterik
petterik / react-kebab-case-css.cljs
Last active October 19, 2015 08:30
Wasn't impressed with react's camel case css...
;; Garden style css (just uses css properties as keywords as you'd expect):
[:style (css {:border-width "1px"})]
;; React cljs (camel cased css property names):
[:div {:style #js {:borderWidth "1px"}}]
;; Why camel case? "[...] This is consistent with the DOM style JavaScript property", see: https://facebook.github.io/react/docs/dom-differences.html
;; Problem: Cannot share code between inline css and react.
;; Context: I'm using datascript and representing a Component as an entity.
;; Discovered a few problems when trying to nest components.
;; Problem 1:
;; When this EntityComponent is updated, it tries to read :db/id :person/name
;; and :person/likes.
;; Without context (like entity id in this case) those attributes may match many entries.
;;
;; Question:
;; Would it make sense to (assoc env :ident (ident c (props c))) in om/default-ui->props so
@petterik
petterik / shuttlCopyBucket.sh
Created December 4, 2013 19:23
Script to copy buckets using Shuttl and without the move needed in the warmToColdScript.sh
set -e
set -u
cd $SPLUNK_HOME/etc/apps/shuttl/bin
bucket="$1"
source java_executable.env
$JAVA -cp ./*:../lib/* com.splunk.shuttl.archiver.copy.ColdCopyEntryPoint "$bucket" &
(defn run-db-tests [db]
(fact "should get password that gets stored"
(.put-password db "email" "password")
(.get-password db "email") => "password"))
(fact "all db tests should be true"
(every? true? (map run-db-tests [(memory/get-instance)])) => true)
@petterik
petterik / lägenhetsprylar.txt
Created August 22, 2012 11:14
Petters: "Allt ska bort!"
Allt ska bort!
Skänkes mot hämtning:
Köksartiklar
- Bestick
- Tallrikar
- Stekpannor
- etc.
Hylla, vit: http://www.ikea.com/se/sv/catalog/products/50102157/#/00134052
Taklampa
@petterik
petterik / Time.java
Created February 19, 2012 08:15
Current time with Time.java
public class Time {
public static void main(String[] args) {
System.out.println(System.currentTimeMillis());
}
}