Skip to content

Instantly share code, notes, and snippets.

<small><b>by</b> {[{post.author}]}</small>
<a ng-show="globals.is_authenticated" class="btn" ng-click="open('create')"> Create</a>
<a ng-hide="globals.is_authenticated" class="btn" href="/api-auth/login/"> Create</a>
from rest_framework import permissions
class IsOwnerOrReadOnly(permissions.BasePermission):
"""
Custom permission to only allow owners of an object to edit it.
"""
def has_object_permission(self, request, view, obj):
# Read permissions are allowed to any request
if request.method in permissions.SAFE_METHODS:
from rest_framework import serializers
from posts.models import Post
class PostSerializer(serializers.HyperlinkedModelSerializer):
author = serializers.Field(source='author.username')
api_url = serializers.SerializerMethodField('get_api_url')
class Meta:
model = Post
from django.contrib.sessions.backends.base import SessionBase, CreateError
from django.conf import settings
from django.utils.encoding import force_unicode
import redis
class SessionStore(SessionBase):
""" Redis store for sessions"""
def __init__(self, session_key=None):
self.redis = redis.Redis(

Build your own private, encrypted, open-source Dropbox-esque sync folder

Prerequisites:

  • One or more clients running a UNIX-like OS. Examples are given for Ubuntu 12.04 LTS, although all software components are available for other platforms as well (e.g. OS X). YMMV
  • A cheap Ubuntu 12.04 VPS with storage. I recommend Backupsy, they offer 250GB storage for $5/month. Ask Google for coupon codes.

Software components used:

  • Unison for file synchronization
  • EncFS for folder encryption
<div class="row">
<div class="span9 main">
<div class="row">
<div class="span9">
<h3>{[{ post.title }]}</h3>
<p>
{[{ post.description }]}
</p>
</div>
</div>
<br>
<div class="row">
<div class="span9 main">
<div class="row">
<div class="span9">
<a class="btn" ng-click="open('create')"> Create</a>
<div modal="postModalCreate" close="close('create')" options="opts">
<a ng-click="close('create')" class="close" data-dismiss="modal">×</a>
Blog.filter('truncate', function () {
return function (text, length, end) {
if (isNaN(length))
length = 10;
if (end === undefined)
end = "...";
if (text.length <= length || text.length - end.length <= length) {
return text;
Blog.controller('PostController', function ($scope, $routeParams, $location, PostService, GlobalService, post) {
$scope.post = post;
$scope.globals = GlobalService;
var failureCb = function (status) {
console.log(status);
}
//options for modals
$scope.opts = {
backdropFade: true,
dialogFade: true