Skip to content

Instantly share code, notes, and snippets.

View mattlong's full-sized avatar
🌊

Matt Long mattlong

🌊
  • Medplum
  • San Francisco, CA
View GitHub Profile
from django import forms
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as ContribUserAdmin
from django.contrib.auth.forms import ReadOnlyPasswordHashField
from .models import User
class UserCreationForm(forms.ModelForm):
password1 = forms.CharField(label='Password', widget=forms.PasswordInput)
description "django-celery daemon"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
chdir /path/to/my/django-project
exec /usr/bin/python manage.py celery worker --loglevel=info > /var/log/celery.log 2>&1
set daemon 60 #check interval in seconds
check process ssh with pidfile "/var/run/sshd.pid"
start program "/sbin/start ssh"
stop program "/sbin/stop ssh"
if failed port 22 protocol ssh then restart
[program:celery]
directory = /path/to/my/django-project
command = /usr/bin/python manage.py celery worker --loglevel=info
stdout_logfile = /var/log/celery.log
redirect_stderr = true
stopasgroup = true
@mattlong
mattlong / fields.py
Created January 6, 2014 21:32
WebsafeCharField for Django REST Framework
class WebsafeCharField(serializers.CharField):
"""
Like a regular CharField but does not allow certain characters.
cannot contain / or \ or non-printable ASCII (0-31, 127)
cannot contain non-characters from Unicode Plane 1 (U+FFFE and U+FFFF)
cannot contain characters from Unicode Planes 2-16 (U+10000 through U+10FFFF)
"""
default_error_messages = {
'contains_unallowed_chars': _(r'Cannot contain non-printable ASCII, /, \, U+FFFE, U+FFFF, or U+10000 through U+10FFFF.'),
}
#!/bin/sh
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# Usage:
# Remove the .sh file extension when you put the script in your hooks folder!
#
@mattlong
mattlong / admin.py
Created September 17, 2014 18:26
Add a custom admin page for a model and link to it from the detail page
from functools import update_wrapper
from django.contrib import admin
from django.contrib.admin import ModelAdmin
from django.contrib.admin.templatetags.admin_urls import add_preserved_filters
from django.core.exceptions import PermissionDenied
from django.shortcuts import render
from myapp.models import Widget
from myapp.forms import ManageWidgetForm
@mattlong
mattlong / gist:9416571ace0db598577b
Last active August 29, 2015 14:07
foldLeft in terms of foldRight expansion
def foldRight[A,B](l: List[A], z: B)(f: (A, B) => B): B =
l match {
case Nil => z
case Cons(a, as) => f(a, foldRight(as, z)(f))
}
def foldLeft[A,B](l: List[A], z: B)(f: (B, A) => B): B =
foldRight(l, (b:B) => b)((a,g) => b => g(f(b,a)))(z)

Keybase proof

I hereby claim:

  • I am mattlong on github.
  • I am mateolargo (https://keybase.io/mateolargo) on keybase.
  • I have a public key whose fingerprint is 2630 B827 4976 C128 FD90 8C08 0E97 4319 70DF A0F3

To claim this, I am signing this object:

@mattlong
mattlong / wrapper
Last active August 29, 2015 14:13
Production MySQL client wrapper
#!/bin/bash
cat << End-of-message
..........,...,.......,. .......,....,....................
..MMMMMM..MM....M..,MNMMMM...MM...MM.......MM..MMMMMMMM...
..MM......MM....M..MM....MI..MM..MM. ......MM.....MM..,..
..MMMMZ...MM....M..MM.. ...MMMMM.........MM.....MN...
..MM......MM. ..M..MM.. .....MM..MM........MM.....MN...
..MM:.....OM....Z..MM....MI..MM...MM.......MM.....MN...
..MM... ..,MM8......MMMMM...MM....MM......MM.....MN.