Skip to content

Instantly share code, notes, and snippets.

View rcanepa's full-sized avatar

Renzo Canepa rcanepa

  • Santiago, Chile
View GitHub Profile
@rcanepa
rcanepa / gist:535163dc249539912c25
Last active May 2, 2024 07:08
Activate pg_stat_statements on PostgreSQL
1) Edit file postgresql.conf and add the next 3 lines (any where):
shared_preload_libraries = 'pg_stat_statements'
pg_stat_statements.max = 10000
pg_stat_statements.track = all
2) Restart PostgreSQL
3) Execute the next command on psql, pgAdmin or similar:
@rcanepa
rcanepa / pre_post_cond_example.clj
Created December 15, 2015 14:57
Improve feedback from Clojure function pre/post conditions.
(defn string-to-string [s1]
{:pre [(or (string? s1)
(throw (Exception. (format "Pre-condition failed; %s is not a string." s1))))]
:post [(or (string? %)
(throw (Exception. (format "Post-condition failed; %s is not a string." %))))]}
s1)
@rcanepa
rcanepa / CREATE_DATABASE.sql
Created December 16, 2015 15:11
Basic setup for a dev and test database on PostgreSQL
CREATE DATABASE auth;
CREATE DATABASE auth_test;
\c auth;
CREATE EXTENSION citext;
\c auth_test;
CREATE EXTENSION citext;
CREATE ROLE auth_user LOGIN;
ALTER ROLE auth_user WITH PASSWORD 'password1';
GRANT ALL PRIVILEGES ON DATABASE auth to auth_user;
GRANT ALL PRIVILEGES ON DATABASE auth_test to auth_user;
@rcanepa
rcanepa / mit_scheme_on_osx.md
Last active December 19, 2015 15:51
Installing MIT Scheme on OSX

#Instructions to install MIT Scheme on OSX

  1. Download either the 32-bit or 64-bit dmg file for Scheme from http://ftp.gnu.org/gnu/mit-scheme/stable.pkg/.

  2. Double click the .dmg file, and you'll get this window, in which you should drag the "MIT/GNU Scheme" file into the Applications folder.

  3. Execute the following commands depending on the package version and OSX version:

##OSX pre El Capitan##

####For the 32-bit version####

#!/bin/bash
usage()
{
cat << EOF
usage: $0 options
This script set ownership for all table, sequence and views for a given database
Credit: Based on http://stackoverflow.com/a/2686185/305019 by Alex Soto
(require '[schema.core :as s])
(require '[schema.coerce :as coerce])
(require '[schema.utils :as utils])
(defn filter-schema-keys
[m schema-keys extra-keys-walker]
(reduce-kv (fn [m k v]
(if (or (contains? schema-keys k)
(and extra-keys-walker
(not (utils/error? (extra-keys-walker k)))))
@rcanepa
rcanepa / gist:830e3844c08e143a2ecc
Last active February 20, 2016 21:52 — forked from qtrfeast/gist:e5d1acbb007f47655508
Great little snippet for using Postgres enum types inside clojure.java.jdbc
(defn str->pg-enum
"Convert a string value into an enum-compatible object."
[enum-type s]
(doto (org.postgresql.util.PGobject.)
(.setType enum-type)
(.setValue s)))
(def str->status
"Convert a string status into a something_status enum object"
(partial string->pg-enum "something_status"))
@rcanepa
rcanepa / exclude.sql
Created March 4, 2016 21:17 — forked from fphilipe/exclude.sql
PostgreSQL EXCLUDE constraint
CREATE EXTENSION btree_gist;
CREATE TABLE room_reservations (
room_id integer,
reserved_at timestamptz,
reserved_until timestamptz,
canceled boolean DEFAULT false,
EXCLUDE USING gist (
room_id WITH =, tstzrange(reserved_at, reserved_until) WITH &&
) WHERE (not canceled)
@rcanepa
rcanepa / gist:374e9aba820117bce29b510b271ca76d
Created April 8, 2016 20:43
Add prefix to multiple files at once
# Add office- prefix to all files on a directory
ls | xargs -I {} mv {} office-{}
# Add office- prefix to all .js files on a directory
ls | grep .js | xargs -I {} mv {} office-{}
More information:
http://stackoverflow.com/questions/6329505/how-to-rename-all-file-in-a-folder-with-a-prefix-in-a-single-unix-command
@rcanepa
rcanepa / gist:7bc723500587e22759d38d6747d1cce6
Last active April 18, 2016 19:35
PostgreSQL OVERLAPS examples
Starting data: 2 reserves on two different meeting rooms.
M1: Meeting Room 1
M2: Meeting Room 2
M1 M2
07
08
09 x
10 x x