Skip to content

Instantly share code, notes, and snippets.

@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(
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 / 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"];
@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 / 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
(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]]
(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]))
This is what people get when they mail you “offensive” stuff.
They layman wouldn’t know what’s going on and most glaringly there’s no “TEK Systems” or “Allegis” anything in here.
Just in case you hadn’t seen this before.
BTW the expression I used that got me filtered is increasingly common:
http://goo.gl/lcOHvG
http://goo.gl/Hm9T6k
; Quick miniKanren-like code
;
; written at the meeting of a Functional Programming Group
; (Toukyou/Shibuya, Apr 29, 2006), as a quick illustration of logic
; programming. The code is really quite trivial and unsophisticated:
; it was written without any preparation whatsoever. The present file
; adds comments and makes minor adjustments.
;
; $Id: sokuza-kanren.scm,v 1.1 2006/05/10 23:12:41 oleg Exp oleg $
#lang racket
;#lang web-server/insta
;(get-uri (calc g-i (car rings) cogs) (calc g-i (car (cdr rings)) cogs))
(define rings (list 38 50))
(define cogs (list 23 21 19 17 16 15 14 13 12 11))
(define max-x (/ 55 11.0))
(define axis (list 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0))
(define nums->csv