Skip to content

Instantly share code, notes, and snippets.

View spookylukey's full-sized avatar

Luke Plant spookylukey

View GitHub Profile
from django import forms
from django.utils.safestring import mark_safe
from django.utils.encoding import force_unicode
class BootstrapRadioFieldRenderer(forms.RadioSelect.renderer):
def render(self):
"""Outputs a <ul> for this set of radio fields."""
return mark_safe('<span id="id_%s"></span>'
'<ul class="inputs-list">\n%s\n</ul>'
@spookylukey
spookylukey / gist:4024116
Created November 6, 2012 11:19
Automatically use mysqld-ram server if available.
import sys
if sys.argv[1] == "test":
import psutil
def mysqld_ram_running():
return any('mysqld-ram.sh' in ' '.join(p.cmdline) for p in psutil.get_process_list())
if mysqld_ram_running():
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'djangotests',
with open('step3.txt') as f:
for l in f:
json_dict = json.loads(l)
Hints:
= Step 2 =
1) The first line of the table is different from the others
2) It should be
Request:
-----
DELETE /v0/subscription HTTP/1.1
Host: api.sign-up.to
Content-Length: 16
accept-encoding: gzip, deflate
content-type: application/json
accept: application/json
authorization: SuTToken blahblahblah
user-agent: Python-httplib2/0.8 (gzip)
# Using my client
from signupto import Client, TokenAuthorization
client = Client(auth=TokenAuthorization(username='my_api_user@example.com',
password='my_strong_password'))
// Example using official client (condensed)
require_once('apiclient/pmapirequest.class.inc');
require_once('apiclient/pmapiauthnone.class.inc');
require_once('apiclient/pmapiauthtoken.class.inc');
$request = new PMAPIRequest(new PMAPIAuthNone());
$response = $request->token->post(array('username' => 'my_api_user@example.com',
'password' => 'my_strong_password'));
@spookylukey
spookylukey / stackoverflow_docs_no_thanks.rst
Last active January 31, 2017 12:31
Stackoverflow docs no thanks (at least for Django)

I'm talking about this: http://stackoverflow.com/documentation/django

Compared to well written documentation, this kind of documentation is pretty bad. Yes, many projects have terrible documentation, and for them it might be an improvement, but for many that have good docs, this is a major step backwards.

Good documentation requires serious effort and organisation. It can't be achieved by throwing together lots of examples.

@spookylukey
spookylukey / convert_leading_spaces_to_en
Created June 22, 2017 07:05
Make source code readable on forums that have poor support
#!/usr/bin/env python3
import sys
def fix_line(l):
if not l:
return l
if l[0] == " ":
# Non breaking: "\u00a0" - but munged by some browsers
# EM space: "\u2003" - not munged by browsers
@spookylukey
spookylukey / Confirm.js
Created September 19, 2018 10:16
Elm 0.18 confirm Task
// Native/Confirm.js
var _user$project$Native_Confirm = function () {
var scheduler = _elm_lang$core$Native_Scheduler;
function confirmTask(prompt, successValue, failValue) {
return scheduler.nativeBinding(function (callback) {
if (window.confirm(prompt)) {
callback(scheduler.succeed(successValue));
} else {