Skip to content

Instantly share code, notes, and snippets.

View terjesb's full-sized avatar

Terje Sten Bjerkseth terjesb

  • Outnordic
  • Norway
View GitHub Profile
@terjesb
terjesb / accounts.clj
Last active August 29, 2015 14:17 — forked from pelle/accounts.clj
(use '[datomic.api :only [q db] :as d])
(def uri "datomic:mem://accounts")
;; create database
(d/create-database uri)
;; connect to database
(def conn (d/connect uri))
(def conn (start-datomic! (str "datomic:mem://" (java.util.UUID/randomUUID)) (schema)))
(def data
[{:db/id (d/tempid :com.mdrogalis/people)
:user/name "Mike"}
{:db/id (d/tempid :com.mdrogalis/people)
:user/name "Dorrene"}
{:db/id (d/tempid :com.mdrogalis/people)
:user/name "Benti"}
{:db/id (d/tempid :com.mdrogalis/people)
@terjesb
terjesb / gist:8494273
Created January 18, 2014 18:28 — forked from bpsm/gist:613279
(ns bpsmannschott
(:import java.io.File)
(:import java.io.FileNotFoundException))
(defn as-file [s]
"Return whatever we have as a java.io.File object"
(cond (instance? File s) s ; already a file, return unchanged
(string? s) (File. s) ; return java.io.File for path s
:else (throw (FileNotFoundException. (str s)))))
(defn optify
"Helper that examines paths with the supplied prefix and either subs
in their cache-busting URLs or returns them unchanged."
[req prefix]
(fn [^String src]
(or (and (.startsWith src prefix)
(not-empty (link/file-path req src)))
src)))
# Installing graphite dependencies
apt-get install -y python2.6 python-pip python-cairo python-django python-django-tagging
apt-get install -y libapache2-mod-wsgi python-twisted python-memcache python-pysqlite2 python-simplejson
pip install whisper
pip install carbon
pip install graphite-web
# Setup a vhost by grabbing the example the graphite team released on their repo.
# In this file, you'll provide the url used to access to your Graphite dashboard
wget https://raw.github.com/tmm1/graphite/master/examples/example-graphite-vhost.conf -O /etc/apache2/sites-available/graphite

Overview

We run multiple server processes in two data centers. Each process listens on two ports, one for HTTP and one for HTTPS. HTTPS is terminated by Apache prior to reaching node.js. HTTP goes directly from the client to node.js (through a master load balancer). We do not use clusters. We slice our physical servers into thin virtual machines running SmartOS, each with about 3GB of memory designed for a single node.js process.

Our node.js servers are hapi.js servers using the composer functionality and plugins architecture. We have three sets of plugins loaded: mobile web front end experience (single page app), legacy API reverse proxy, and monitoring.

We also serve original node.js services off another server zone which runs closed source plugins using hapi.

Analytics

@terjesb
terjesb / dopar.clj
Created November 28, 2013 18:45 — forked from candera/dopar.clj
(defn dopar
"Given a (potentially infinite) sequence `coll`, uses core.async to
run `f` for side effects against each value in the collection.
Performs at most `concur` operations in parallel, and never enqueues
more than `lead` items ahead of the ones being consumed. If any call
to `f` throws an exception, it will be rethrown from this function.
Otherwise, returns nil. Optional timeout value is number of
milliseconds to wait for all operations to complete."
([coll f concur lead] (dopar coll f concur lead nil))
([coll f concur lead timeout-ms]
@terjesb
terjesb / fanout.clj
Created November 28, 2013 18:45 — forked from candera/fanout.clj
(require '[clojure.core.async :as async])
(let [l (Object.)]
(defn log
[fmt & args]
(locking l
(apply printf fmt args)
(flush))))
(let [req (async/chan 10)
@terjesb
terjesb / gist:7628803
Created November 24, 2013 16:11 — forked from bobby/gist:5911181
(ns user
(:require [clojure.java.io :as io]
[datomic.api :as d]))
(defn order-schema []
(read-string (slurp (io/resource "schema.edn"))))
(defn start-datomic! [uri schema]
(d/create-database uri)
(let [conn (d/connect uri)]
object DatomicPricing {
object Schema extends VersionedSchemaComponent("0.0.1") {
object ns {
val pricing = new Namespace("Pricing")
}
val isIndexed = true
val isComponent = true
val quoteId = Attribute(ns.pricing / "QuoteId", SchemaType.string, Cardinality.one).withUnique(Unique.identity)