Skip to content

Instantly share code, notes, and snippets.

View joshuachinemezu's full-sized avatar

Joshua Chinemezu joshuachinemezu

View GitHub Profile
@darklow
darklow / celery_tasks_error_handling.py
Last active December 20, 2024 02:44
Celery tasks error handling example
from celery import Task
from celery.task import task
from my_app.models import FailedTask
from django.db import models
@task(base=LogErrorsTask)
def some task():
return result
class LogErrorsTask(Task):
@jacoor
jacoor / AdditionalDataListApiView.py
Created March 5, 2014 15:37
additional data for listApiView for django.rest.framework
class TransactionsList(ListAPIView):
"""
List all transactions for currently logged in user, paginated by 25
page -- page number
ordering -- yoddle_amount, created, yoddle_description, reverse order ie. -yoddle_amount
"""
model = Transaction
@ziadoz
ziadoz / index.php
Last active June 2, 2023 23:08
Simple PHP / jQuery CSRF Protection
<?php
// See: http://blog.ircmaxell.com/2013/02/preventing-csrf-attacks.html
// Start a session (which should use cookies over HTTP only).
session_start();
// Create a new CSRF token.
if (! isset($_SESSION['csrf_token'])) {
$_SESSION['csrf_token'] = base64_encode(openssl_random_pseudo_bytes(32));
}
@Integralist
Integralist / remote-git.md
Created February 21, 2012 09:51
Basic set-up of remote git repository on a standard server

Set-up remote git repository on a standard server

The first thing to do is to install Git on the remote server.

Once you do that the rest of the process is split into three sections:

  1. Server set-up
  2. Local set-up (push commits)
  3. Server (pull commits)
@pydanny
pydanny / api.group_permissions.py
Created December 31, 2011 20:30
django-rest-framework permissions by groups
""" User Django Rest Framework to check to see if an authenticated user
is in a particular group
Usage::
from api.group_permissions import GroupAPIGETPermission
class SearchProductView(View):
permissions = (IsAuthenticated, GroupAPIGETPermission,)
@pmclanahan
pmclanahan / middleware.py
Created November 22, 2010 19:25
Django 1.2+ middleware that allows you to set cookies from a request object.
from types import MethodType
from django.http import CompatCookie, HttpRequest
def _set_cookie(self, key, value='', max_age=None, expires=None, path='/',
domain=None, secure=False):
self._resp_cookies[key] = value
self.COOKIES[key] = value
if max_age is not None: