Skip to content

Instantly share code, notes, and snippets.

(ns guestbook.routes.home
(:use compojure.core)
(:use hiccup.core)
(require [me.raynes.conch :as conch]
[amazonica.aws.s3 :as s3]
[clojure.data.json :as json]
[noir.io :as io]
[clojurewerkz.cassaforte.query :as cql-query]
[clojurewerkz.cassaforte.client :as cql-client]))
(defn move-to-s3 [k f]
(s3/put-object :bucket-name s3-bucket
:key k
:file f)
(io/delete-file f))
(defn upload [userid file]
(let [img-uuid (uuid)
exts [".orig.jpg" ".0.jpg" ".1.jpg"]
dims [[nil nil] [595 296] [180 120]]
@irneh
irneh / icons.sh
Last active August 29, 2015 14:05
file=$(basename "$1")
ext="${file##*.}"
file="${file%.*}"
declare -a vars=(120x120 114x114 80x80 72x72 58x58 57x57 50x50 29x29)
for v in ${vars[@]}; do
convert -resize $v $1 $file-$v.$ext
done
@irneh
irneh / gist:75daee0dffa9185e9637
Last active August 29, 2015 14:09
Delete S3 files that aren't in your Postgres database anymore
psql -t -c "select key from media order by 1;" hikerpix > db.asc
s3cmd ls s3://{{your-bucket-path}} | sort > s3.asc
join -v 2 db.asc <(cut -c 55-74 s3.asc | sort -u) > orphans.asc
awk '{print $4}' s3.asc | grep -f orphans.asc > urls.asc
xargs -P 4 s3cmd del $1 < urls.asc
@irneh
irneh / mongo.gv
Last active August 29, 2015 14:14
digraph G {
fontname = helvetica;
fontsize = 10;
node [fontname = helvetica; fontsize = 10; style = filled; fillcolor = grey];
edge [fontname = helvetica; fontsize = 10];
subgraph cluster0 {
label = "document";
c0 [label = "children\n(inbound)"; fillcolor = green];
h0 [label = "hierarchy"];
n0 [label = "name"];
digraph g {
fontname = helvetica; fontsize = 10;
node [shape = record; fontname = helvetica; fontsize = 10];
edge [fontname = helvetica; fontsize = 10];
/* Documents */
doc0 [label = "<f0> parent_id|<f1> children|<f2> hierarchy|<f3> name|<f4> region"];
doc1 [label = "<f0> parent_id|<f1> children|<f2> hierarchy|<f3> name|<f4> region"];
@irneh
irneh / app.py
Last active August 29, 2015 14:25
Routing, database connection pooling, HTTP responses, sessions
import flask
import os
import psycopg2
import psycopg2.pool
app = flask.Flask(__name__)
app.secret_key = '@1*V*vpVqqfyhCZ)s/`5>B^V]mJ85]We'
app.debug = True
pool = psycopg2.pool.SimpleConnectionPool(
expires = datetime.utcnow() + timedelta(days=(25 * 365))
expires = expires.strftime("%a, %d %b %Y %H:%M:%S GMT")
file.seek(0)
k.set_contents_from_string(file.read(), headers={
'Content-Type': 'image/jpeg',
'Cache-Control': 'public',
'Expires': expires,
})
#!/usr/bin/perl -wT
# Upgrade a PostgreSQL cluster to a newer major version.
#
# (C) 2005-2009 Martin Pitt <mpitt@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
ooh la la