Skip to content

Instantly share code, notes, and snippets.

View mikeengland's full-sized avatar

Mike England mikeengland

  • London, United Kingdom
View GitHub Profile
@petermoresi
petermoresi / rule_parser.js
Last active January 3, 2017 09:14
Parser for simple business rules language
/* parser generated by jison 0.4.13 */
/*
Returns a Parser object of the following structure:
Parser: {
yy: {}
}
Parser.prototype: {
yy: {},
@vladiibine
vladiibine / swap_django_auth_user.md
Last active March 9, 2020 20:59
Swap django auth.User with custom model after having applied the 0001_initial migration

Swapping the django user model during the lifecycle of a project (django 1.8 guide)

I've come to a point where I had to swap django's user model with a custom one, at a point when I already had users, and already had apps depending on the model. Therefore this guide is trying to provide the support that is not found in the django docs.

Django warns that this should only be done basically at the start of a project, so that the initial migration of an app includes the creation of the custom user model. It took a while to do, and I ran into problems created by the already existing relations between other models and auth.User.

There were good and not so good things regarding my project state, that influenced the difficulty of the job.

Things that made the swap simpler
  1. My custom user also had an id field, that's just a usual default django id
var Col = require('react-bootstrap/lib/Col')
var PageHeader = require('react-bootstrap/lib/PageHeader')
var React = require('react')
var Row = require('react-bootstrap/lib/Row')
var {connect} = require('react-redux')
var {reduxForm} = require('redux-form')
var DateInput = require('./DateInput')
var FormField = require('./FormField')
var LoadingButton = require('./LoadingButton')
@paltman
paltman / axis-headers.js
Created July 3, 2015 14:11
override axios default csrf header and cookie name to match what Django expects
var axios = require("axios");
var axiosDefaults = require("axios/lib/defaults");
axiosDefaults.xsrfCookieName = "csrftoken"
axiosDefaults.xsrfHeaderName = "X-CSRFToken"
@sebmarkbage
sebmarkbage / Enhance.js
Last active January 31, 2024 18:33
Higher-order Components
import { Component } from "React";
export var Enhance = ComposedComponent => class extends Component {
constructor() {
this.state = { data: null };
}
componentDidMount() {
this.setState({ data: 'Hello' });
}
render() {
@hitsujixgit
hitsujixgit / forms.py
Created October 2, 2014 13:45
Add class attributes to option tags of select menu on Django projects.
# -*- coding: utf-8 -*-
from django import forms
from myapp.models import DataGroup # Overwrite this to your model
from django.utils.encoding import force_text
from django.utils.safestring import mark_safe
from django.utils.html import format_html
class DataGroupSelect(forms.widgets.Select):
def render_option(self, selected_choices, option_value, option_label):
@darklow
darklow / celery_tasks_error_handling.py
Last active May 29, 2024 04:39
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):
@amatellanes
amatellanes / celery.sh
Last active July 18, 2024 07:23
Celery handy commands
/* Useful celery config.
app = Celery('tasks',
broker='redis://localhost:6379',
backend='redis://localhost:6379')
app.conf.update(
CELERY_TASK_RESULT_EXPIRES=3600,
CELERY_QUEUES=(
Queue('default', routing_key='tasks.#'),
@learncodeacademy
learncodeacademy / gist:5f84705f2229f14d758d
Last active July 16, 2024 04:56
Getting Started with Vagrant, SSH & Linux Server Administration