Skip to content

Instantly share code, notes, and snippets.

@bentappin
bentappin / serpy_thumbnail_field.py
Created August 8, 2019 19:09
SerpyThumbnailImageField
import serpy
from drf_haystack.serializers import HaystackSerializer
from sorl.thumbnail import get_thumbnail
class SerpyThumbnailImageField(serpy.StrField):
"""
A Serpy Field class returning hyperlinked scaled and cached images.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Ansi 0 Color</key>
<dict>
<key>Alpha Component</key>
<real>1</real>
<key>Blue Component</key>
<real>0.19370138645172119</real>
@bentappin
bentappin / Climbing.md
Last active September 22, 2016 14:08
@bentappin
bentappin / postgresql_date_function_index_howto.md
Last active September 18, 2015 10:36 — forked from cobusc/postgresql_date_function_index_howto.md
Short explanation of the issues faced when trying to create a PostgreSQL index using the date() function and how to resolve it.

Given a table...

CREATE TABLE foo (
  id SERIAL PRIMARY KEY,
  created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
  ...
);
@bentappin
bentappin / 0_LICENSE
Last active August 29, 2015 14:21
A reusable confirm field update pattern for Django
Copied from https://github.com/code-kitchen/django-utensils/ and licensed under the MIT license.
#!/bin/sh
# Just copy and paste the lines below (all at once, it won't work line by line!)
# MAKE SURE YOU ARE HAPPY WITH WHAT IT DOES FIRST! THERE IS NO WARRANTY!
function abort {
echo "$1"
exit 1
}
set -e
@bentappin
bentappin / is_rsa.pub
Created September 29, 2014 13:56
SSH key ben@kirsche
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC06J4JLI+WCSu49Ht8Oj62nEKWI0d+rx/mqDmsASIi8DgNsXnVYz8+jU8Oiq80InPpMBziciRIJ10fjLCLjG4QXCuPzT3SenYD2XQ7owseeybjAvTd6rEVOu+iTRefTdhZwaiedp8/hrsJbK9oykTdFjAF2nCh1EKw78qo9UlLmzRVmc4cnlLk8K+BMMWBUPthV6h6yl/iNN9buiGr3IUtKo6cWAoLVup1+E/4eh5MBVPSF+2Gv/R6sa8ffAKLZizS/W2Jdbd8nhw9x9P/h9E/FNCdzwC00Qdf/M6a+56SePeiKRMaJ/AluFeqQg5HMIKEVIGz21ySaPkatafnkZxy0xUcW85OUk0DjK/+omTOENDI5xjwotMx95rr6dXkaxAH9fhsJr1oToM2jM1BysoSwKFp7KZkd/WsuGSMK/a4+ag++YIa+E5gGS8VG4a0Wb5V1qk+hEpkl852Lx0fkWqnBmCOxrtUlZEUuCJKRFG2kHnDlpkYqKQmdYJmSopXae+u2+Xz3QiBuHT9kbFPccUwmfgCyLJMZ/2/YMJeUy05PfEEUEeSf3W6ESclbbCMeKWHKJwEgP68W/AmEI6imisvbNN6IbG6XQPXIEG1segkZMg/fZXI+AR9zKU5wM8Dk1YrRAU8BUWMAvCNJWL8EBK3WtIWxExlSWySzND5PaIQnQ== ben@kirsche
@bentappin
bentappin / distance.sql
Last active August 29, 2015 14:02
SQL: Sort by distance from a point
# Adapted from: http://dillieodigital.wordpress.com/2011/06/16/sorting-latitudelongitude-positions-by-distance-in-sql/
SELECT
*, 6378 * 2 * ASIN(
SQRT(
POWER(
SIN((51.5081 - latitude) * pi() / 180 / 2),
2
) + COS(51.5081 * pi() / 180) * COS(latitude * pi() / 180) * POWER(
SIN((0.1281 - longitude) * pi() / 180 / 2),
2
@bentappin
bentappin / Gruvbox Dark.tmTheme
Last active August 29, 2015 14:01
Gruvbox Dark.tmTheme
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!-- Generated by: TmTheme-Editor -->
<!-- ============================================ -->
<!-- app: http://tmtheme-editor.herokuapp.com -->
<!-- code: https://github.com/aziz/tmTheme-Editor -->
<plist version="1.0">
<dict>
<key>gutterSettings</key>
<dict>