Skip to content

Instantly share code, notes, and snippets.

View danielbraun's full-sized avatar

Daniel Braun danielbraun

  • Tel-Aviv, Israel
View GitHub Profile
@danielbraun
danielbraun / gist:27e43b914c6a2e081792
Created November 24, 2014 12:11
Vim syntax coloring for Cocoapods' Podfile.
// Append this to your .vimrc
au BufNewFile,BufRead Podfile set filetype=ruby
@danielbraun
danielbraun / gist:07604e7bd6f1650aa2e7
Last active August 29, 2015 14:10
django-storages + Amazon S3

For those of you trying to integrate django-storages with Amazon S3, don't select Frankfurt as the bucket region. Use the default region (US standard or something). You'll get into weird HTTP 400 errors otherwise.

Also, make sure that DEFAULT_FILE_STORAGE is 'storages.backends.s3boto.S3BotoStorage' The other engine mentioned, 'storages.backends.s3.S3Storage', is broken.

In addition, add AWS_QUERYSTRING_AUTH = False to your settings. Otherwise, django-storages breaks browser caching by default. SO Answer: http://stackoverflow.com/questions/15668443/django-storage-with-s3-boto-break-browser-cache/15710661#15710661

@danielbraun
danielbraun / gist:87384ea330053b3ffa83
Created November 27, 2014 14:03
Django Rest Framework + ImageField URL
When serializing models using DRF, the related ImageFields return the file system path instead of an absolute URL.
To solve it, define an instance variable on your model serializer:
class PersonSerializer(serializers.ModelSerializer):
image = serializers.Field('image.url')
diff --git a/autoload/fireplace/nrepl.vim b/autoload/fireplace/nrepl.vim
index 5d081e7..15367e0 100644
--- a/autoload/fireplace/nrepl.vim
+++ b/autoload/fireplace/nrepl.vim
@@ -183,8 +183,10 @@ endfunction
function! s:extract_last_stacktrace(nrepl, session) abort
if a:nrepl.has_op('stacktrace')
let stacktrace = filter(a:nrepl.message({'op': 'stacktrace', 'session': a:session}), 'has_key(v:val, "file")')
- if !empty(stacktrace)
- return map(stacktrace, 'v:val.class.".".v:val.method."(".v:val.file.":".v:val.line.")"')
@danielbraun
danielbraun / enlive.clj
Last active May 13, 2016 17:18
two-column-table->map
(defn- two-column-table->map [table-dom]
(->> (enlive/select table-dom [:td])
(map (comp string/trim enlive/text))
(apply hash-map)
(map #(update % 0 string/replace ":" ""))
(into {})))
(defn paginate
([coll] (paginate 1 coll))
([n coll] (paginate 25 n coll))
([per-page n coll]
(let [partitioned (vec (partition-all per-page coll))
page (or n 1)]
(some-> (get partitioned (dec page))
(let [per-page 25
page 2
page-count (sql/call :ceiling (sql/call :/ :%count.* per-page))
]
(-> {:select [[:%count.* :total_count]
[page-count :page-count]
[(sql/call :< page page-count) :has-next?]
[(sql/call :> page 1) :has-previous?]
[page :current_page]
]
openapi: 3.0.0
info:
title: Tasksheriff
version: 1.0.0
servers:
- url: 'https://api.tasksheriff.com'
components:
securitySchemes:
oAuth2:
type: oauth2
(ns ring-server-pg
(:require [ring.adapter.jetty :as jetty]
[clojure.java [jdbc :as jdbc]]
[clj-postgresql.core]
[ring.middleware.defaults :as defaults]))
(def db (System/getenv "DB_URL"))
(def last-request (atom nil))
/*global L, document*/
document.querySelectorAll("[data-leaflet]").forEach(function(el) {
var data = JSON.parse(el.dataset.leaflet),
map = L.map(el, data);
data.tileLayers.forEach(function(layer) {
L.tileLayer(layer.urlTemplate, layer).addTo(map);
});
if (data.locate) {
map.locate(data.locate);
}