Skip to content

Instantly share code, notes, and snippets.

View j4mie's full-sized avatar

Jamie Matthews j4mie

View GitHub Profile
@j4mie
j4mie / workinghours.sh
Last active August 5, 2021 13:35
Plugin for xbarapp.com to display total time spent using your computer today
#!/usr/bin/env bash
# This query adds up the lengths of all the /app/usage events in ZOBJECT.
# This gives an approximation of how long the machine has been used for today, assuming
# the display goes to sleep fairly quickly when the machine is not used (eg 1 minute).
# You'll need to give xbar "Full Disk Access"
# (System Preferences -> Security and Privacy -> Privacy) for this to work.
DBPATH=~/Library/Application\ Support/Knowledge/knowledgeC.db
@j4mie
j4mie / disable_queries.py
Created July 19, 2018 12:13
Context manager / decorator for stopping the Django ORM from making queries in a given block of code
from contextlib import contextmanager
from django.db import connections
class QueriesDisabledError(Exception):
pass
def fake(*args, **kwargs):
raise QueriesDisabledError()
@j4mie
j4mie / keybase.md
Created February 15, 2017 13:49
keybase.md

Keybase proof

I hereby claim:

  • I am j4mie on github.
  • I am recurse (https://keybase.io/recurse) on keybase.
  • I have a public key whose fingerprint is D8BA 7050 B327 D160 4C39 58D5 9CD6 DBBD F454 4518

To claim this, I am signing this object:

@j4mie
j4mie / gist:9055969
Last active October 23, 2020 13:40
Django CSRF error

Since Django 1.5.5, CSRF tokens are rotated on login. That makes it trivial to trigger a CSRF error in the following way:

  1. Open your app's login page in two different browser tabs.
  2. Log in using tab 1
  3. Log in using tab 2

The CSRF token sent along with the second login attempt (in a cookie) won't match the token that was embedded in the form, and so a CSRF error will be displayed.

It could be argued that the above is an odd/contrived thing to do, and so displaying a CSRF error here isn't too bad. Fine. But there's another, more subtle, way to trigger the same thing:

@j4mie
j4mie / ardiuno-makefile.md
Created October 17, 2012 21:17
arduino-makefile-osx

Ardiuno-Makefile instructions for OS X

Examples for Arduino Nano V3.0.

First, install the Arduino software from arduino.cc as usual, as well as the FTDI driver (if needed for your board). https://github.com/mjoldfield/Arduino-Makefile

You'll need a couple of Perl modules:

@j4mie
j4mie / gist:1778918
Created February 9, 2012 09:46
# How to run Sentry in a subdirectory (http://your.server.com/sentry/) with nginx

How to run Sentry in a subdirectory with nginx

Scenario: you already have an app running at http://your.server.com/ and you want to run Sentry at http://your.server.com/sentry/

I spend a few hours banging my head against this, and finally got it to work. There may be a better way, but I couldn't find it.

Warning: hacky.

nginx.conf (in server stanza)

@j4mie
j4mie / 400or403.md
Created November 20, 2011 20:02
400 or 403?

400 or 403 for invalid form submission?

Conclusion: use 400

The Spec ( http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html )

10.4.1 400 Bad Request

The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.

@j4mie
j4mie / README.md
Created October 31, 2011 17:59
blocks

isometric drawing experiment with three.js

click the shape to enable/disable animation

source code here

@j4mie
j4mie / codebase.py
Created October 17, 2011 16:03
None-working Codebase API code
import requests
key = 'xxxx' # API key copied from https://dabapps.codebasehq.com/settings/profile
auth = ('dabapps/j4mie', key)
headers = {
'Accept': 'application/xml',
'Content-type': 'application/xml',
}
@j4mie
j4mie / backend.py
Created August 12, 2011 08:37
Proof-of-concept JSON-based Django cache backend for offline operation of django_compressor
import os
from django.core.cache.backends.base import BaseCache
from django.utils import simplejson as json
from django.conf import settings as django_settings
from compressor.conf import settings
class CompressorManifestCache(BaseCache):
"""Proof of concept, do not use"""