Skip to content

Instantly share code, notes, and snippets.

@jordwalke
jordwalke / myComponent.ml
Last active December 13, 2021 17:32
React OCaml API
open ReactDOM
module MyComponent = struct
(* Component Properties *)
type props = {count: int}
(* Hey, state can be any type! *)
type state = string
(* Initializer *)
@pleasetrythisathome
pleasetrythisathome / nashorn.clj
Last active August 29, 2015 14:10
nashorn cljs rendering
(ns starlab.services.nashorn
(:require [clojure.tools.logging :as log]
[clojure.java.io :as io])
(:import [javax.script
Invocable
ScriptEngineManager])
(:use [plumbing.core :exclude [update]]))
(defn nashorn-env []
(doto (.getEngineByName (ScriptEngineManager.) "nashorn")
FROM debian:wheezy
ENV DEBIAN_FRONTEND noninteractive
# Oracle Java 8
RUN apt-get update \
&& apt-get install -y wget openssl ca-certificates \
&& cd /tmp \
&& wget -qO jdk8.tar.gz \
@narma
narma / datascript_utils.cljs
Last active January 27, 2016 13:13
Convert json dump or just regular data to seq for `d/transact!`
(ns datascript-utils
(:require [datascript :as d]))
(defn data->datoms [prefix json]
(let [make-prefix
(fn [p]
(let [[full short]
(re-matches #"(.+?)s?$" p)]
short))]
@leblowl
leblowl / idb.cljs
Created February 13, 2015 02:00
simple clojurescript interface to IndexedDB for github.com/leblowl/lokate
(def db (atom nil))
(defn error [e]
(.error js/console "An IndexedDB error has occured!" e))
(defn new [cb]
(let [version 1
request (.open js/indexedDB "lokate" version)]
(set! (.-onupgradeneeded request) (fn [e]
(reset! db (.. e -target -result))
@fritzy
fritzy / 1_triggers.sql
Last active August 2, 2025 18:25
Get table change notifications from Postgres as JSON
CREATE OR REPLACE FUNCTION table_update_notify() RETURNS trigger AS $$
DECLARE
id bigint;
BEGIN
IF TG_OP = 'INSERT' OR TG_OP = 'UPDATE' THEN
id = NEW.id;
ELSE
id = OLD.id;
END IF;
PERFORM pg_notify('table_update', json_build_object('table', TG_TABLE_NAME, 'id', id, 'type', TG_OP)::text);
@robert-stuttaford
robert-stuttaford / config.edn
Last active May 1, 2017 07:07
Using Onyx with Trapperkeeper
{:environment :production
:global {:logging-config "./logback.xml"}
:onyx {:job-scheduler :onyx.job-scheduler/balanced
:task-scheduler :onyx.task-scheduler/balanced
:peer-config {:onyx.messaging/impl :netty
:onyx.messaging/peer-port-range [40200 40220]
:onyx.messaging/peer-ports [40199]
:onyx.messaging/bind-addr "localhost"
:onyx.messaging/backpressure-strategy :high-restart-latency}
:peer-count 20
(ns your.macros-for-cljs.ns
(:require [sablono.compiler :as sablono-c]))
;; Make sablono also walk into other forms:
;; if, for, let, do: Already exist
(.addMethod @(var sablono-c/compile-form) "when"
(fn
[[_ bindings & body]]
`(when ~bindings ~@(for [x body] (sablono-c/compile-html x)))))
@joshisa
joshisa / URL Parsing
Created February 3, 2017 02:27
Parsing of URLs using bash sh scripting
#!/bin/bash
# Referenced and tweaked from http://stackoverflow.com/questions/6174220/parse-url-in-shell-script#6174447
proto="$(echo $1 | grep :// | sed -e's,^\(.*://\).*,\1,g')"
# remove the protocol
url="$(echo ${1/$proto/})"
# extract the user (if any)
userpass="$(echo $url | grep @ | cut -d@ -f1)"
pass="$(echo $userpass | grep : | cut -d: -f2)"
if [ -n "$pass" ]; then
(defmulti control (fn [action] action))
(defmethod control :init [_ [init-state] _]
init-state)
(defonce reconciler
(scrum/reconciler {:state (atom {}) ;; <= client-side state
:controllers {:user control}})) ;; <= action handlers