Skip to content

Instantly share code, notes, and snippets.

begin;
create table user_ratings (
id serial primary key,
user_id integer not null,
rating integer not null check (rating >= 0 and rating <= 5),
ratable_id integer not null
);
create function random_int(max integer) returns integer as $$
;;
;; NS CHEATSHEET
;;
;; * :require makes functions available with a namespace prefix.
;;
;; * :use makes functions available without a namespace prefix
;; (i.e., refers functions to the current namespace).
;;
;; * :import refers Java classes to the current namespace.
;;
(In views/layouts/application.haml)
%html
= yield :application_with_nested_layout
= yield
hItuE25058127
6uGdS64633551
iZ8Yg129410073
mn9Ni177063744
tvUy62899300
LlcJs181693848
rRNp274174151
UsiSz5027013
DH4Yd88472413
eEIN376415610
hItuE25058127
6uGdS64633551
iZ8Yg129410073
mn9Ni177063744
tvUy62899300
LlcJs181693848
rRNp274174151
UsiSz5027013
DH4Yd88472413
eEIN376415610
@danneu
danneu / ruby_ri20min.rb
Last active December 17, 2015 18:09 — forked from anonymous/ruby ri20min
class Greeter
def initialize(*names)
names << "World" if names.empty?
@names = names
end
def say_hi
@names.each do |name|
puts "Hello #{name}!"
end
(ns redis-memo
(:require redis)
(:import (java.net URLEncoder)))
;; --------------------------------------------------------------------------------
;; Default connection params
;; --------------------------------------------------------------------------------
(def memo-server {:host "localhost" :port 6379 :db 14})
;; Datomic example code
;; make in memory database
(use '[datomic.api :only (q db) :as d])
(def uri "datomic:mem://matches")
(d/create-database uri)
(def conn (d/connect uri))
;; add the match attribute
(d/transact
@danneu
danneu / gist:6504543
Created September 10, 2013 03:13 — forked from vaughnd/gist:3705861
(use '[datomic.api :only (q db) :as d])
(def uri "datomic:mem://user-groups3")
(d/create-database uri)
(def conn (d/connect uri))
(d/transact
conn
[{:db.install/_attribute :db.part/db
:db/id #db/id[:db.part/db]
:db/ident :user/name
@danneu
danneu / gist:6532819
Created September 12, 2013 03:41 — 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)]