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
@mattlong
mattlong / db.py
Created February 27, 2016 03:27 — forked from carljm/db.py
SQLAlchemy and Postgres autocommit
"""
SQLAlchemy, PostgreSQL (psycopg2), and autocommit
See blog post: http://oddbird.net/2014/06/14/sqlalchemy-postgres-autocommit/
"""
from contextlib import contextmanager
from sqlalchemy import create_engine, event
from sqlalchemy.orm import sessionmaker, Session as BaseSession
Remove osxfuse if installed via homebrew:
> brew uninstall osxfuse
Install osxfuse binary and choose to install the MacFUSE compatibility layer:
http://sourceforge.net/projects/osxfuse/files/latest/download?source=files
Reboot (optional but recommended by osxfuse)
Install ntfs-3g via homebrew:
> brew update && brew install ntfs-3g
@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.

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 / 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)
@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
#!/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 / 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.'),
}
[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
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