Skip to content

Instantly share code, notes, and snippets.

View ccfontes's full-sized avatar
🎯
Focusing

Carlos Fontes ccfontes

🎯
Focusing
View GitHub Profile
(defproject myapp "0.1.0-PROOF-OF-CONCEPT"
:description ""
:dependencies [[org.clojure/clojure "1.4.0"]
[postgresql/postgresql "9.1-901.jdbc4"]
[noir "1.3.0-beta10"]
[crudite "0.1.1"]
[org.clojure/java.jdbc "0.2.3"]
[cljs-uuid "0.0.3"]
[clj-time "0.4.4"]
[noir-cljs "0.3.0"]
SELECT c.column_name, c.is_nullable, c.character_maximum_length, c.numeric_precision, c.numeric_scale, c.udt_name, tc.constraint_type
FROM ((information_schema.columns as c
INNER
JOIN information_schema.constraint_column_usage as ccu
ON c.column_name = ccu.column_name)
INNER
JOIN information_schema.table_constraints as tc
ON tc.constraint_name = ccu.constraint_name)
WHERE table_name = 'users';
column_name | is_nullable | character_maximum_length | numeric_precision | numeric_scale | udt_name | unique
---------------------+-------------+--------------------------+-------------------+---------------+-----------+--------
distance | YES | | 32 | 0 | int4 |
setting_preset_uuid | YES | | | | uuid |
blocks | YES | | | | _uuid |
longitude_home | YES | | 9 | 6 | numeric |
latitude_home | YES | | 9 | 6 | numeric |
available_invites | YES | | 16 | 0 | int2 |
longitude_meeting | YES | | 9 | 6 | numeri
(defn foo
(let [eggs #(str %)]
([x y] (println (eggs x) y))
([x] (println (eggs x)))))
(defn insert
"Insert user registration invitation."
[to_email]
(let [invite-id (make-random)]
(db/insert :invites
{:id invite-id
:to_email to_email
:created_at (to-sql-date (now))
:users_id (app.session/get :id)})
(.toString invite-id)))
@ccfontes
ccfontes / custom_tags_bt_example
Last active August 29, 2015 14:02
Definition and usage example of custom tags for Twitter Bootstrap
(ns custom-tags-bt-example
(:require [hiccup.core :refer [deftag]]))
(defn accordion-panel-tag [{:keys [title collapse class] :as attrs} body]
(let [collapse-id (str (string/replace title #"\s+" "-") (rand-int 999999999))]
[:div (merge {:class (str "panel panel-default " class)}
(dissoc attrs :title :collapse :class))
[:div {:class "panel-heading"}
[:h4 {:class "panel-title"}
[:a {:data-toggle "collapse"
@ccfontes
ccfontes / is-cljs-modified.hy
Created August 23, 2014 01:14
Verifies if the Clojurescript sources were modified since last build.
#!/usr/bin/env hy
; Author: <Carlos C. Fontes> ccfontes@gmail.com
(defn cljs-modified?
"""Verifies if the Clojurescript sources were modified since last build."""
[]
(let [ls-by-time-modified (partial ls "-t")]
(-> (glob "src-cljs/app/*.cljs")
(ls-by-time-modified "resources/public/js/main.js")
.split
@ccfontes
ccfontes / readme-append
Created August 23, 2014 01:38
Formats lein-notes and then appends them to README.md
#!/usr/bin/env hy
; Author: <Carlos C. Fontes> ccfontes@gmail.com
(import [sh [cat lein echo tee rm]])
(import [script.hy-lib.hyclops.hyclops [comp]]) ; you must provide this your own
(setv irrelevant-note-patterns
["/.repl/" "/out/" "/README.md" "/target/" "/script/hy_lib/"])
(defn irrelevant-note?
@ccfontes
ccfontes / cljs
Created August 23, 2014 01:55
Runs 'lein cljsbuild auto' (non blocking) when there are changes in the cljs files. Accepts other commands as arguments to execute after the daemon is launched. Example: 'script/with/cljs lein run' (script has problems with messages printing to several terminals)
#!/usr/bin/env hy
; Author: <Carlos C. Fontes> ccfontes@gmail.com
(import [sh [touch ls lein sleep]]
[glob [glob]]
sys
[subprocess [call Popen PIPE STDOUT]]
[thread [start_new_thread]])
(defn with-print-call [exe]
@ccfontes
ccfontes / change-datomic-schema-fulltex-idx.clj
Last active January 16, 2024 12:06
Change datomic schema by adding a fulltext index to :url/path attribute
; 1. rename attribute: :url/path → :legacy/url-path-v1
(do (require '[datomic.api :as datomic] '[kanasubs.db :as db])
(datomic/transact @db/connection
[{:db/id :url/path, :db/ident :legacy/url-path-v1}]))
; 2. repurpose :url/path
(do (in-ns 'kanasubs.db)
(transact @connection
[{:db/id #db/id[:db.part/db]
:db/ident :url/path