Skip to content

Instantly share code, notes, and snippets.

View spookylukey's full-sized avatar

Luke Plant spookylukey

View GitHub Profile
// See http://www.reddit.com/r/programming/comments/as759/hey_reddit_out_of_these_4_programmers_who_would/
using System;
class MainClass {
static int Main(string[] argv) {
foreach (string s in new string[] {"hello", "λ", Char.ConvertFromUtf32(0x1D161)}) {
Console.WriteLine(s);
Console.WriteLine(Reverse(s));
}
# 100% code coverage, with an obvious type level bug that is not caught - Bar
# does not define method2 and do_it will fail for some values.
class Foo(object):
def method1(self, arg):
return arg + 1
def method2(self, arg):
return arg + 2
#!/usr/bin/env python
# Quick and dirty script to convert ktimetracker.ics files
# into TimeCult files.
import os.path
import sys
import time
import uuid
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>'
# list_detail.object_list replacement with all the things I need
def object_list(request, queryset, extra_context=None,
template_name='', paginate_by=None):
class ObjectList(ListView):
def post(self, request, *args, **kwargs):
return self.get(request, *args, **kwargs)
def get_context_data(self, **kwargs):
c = super(ObjectList, self).get_context_data(**kwargs)
@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='[email protected]',
password='my_strong_password'))