Skip to content

Instantly share code, notes, and snippets.

View georgedorn's full-sized avatar
💭
mostly moved to gitlab

Sam Thompson georgedorn

💭
mostly moved to gitlab
View GitHub Profile
import json
from collections import OrderedDict
from tastypie.serializers import Serializer
from tastypie import fields
from tastypie.resources import Resource
from django.core.serializers.json import DjangoJSONEncoder
class OrderedSerializer(Serializer):
def to_json(self, data, options=None):
options = options or {}
index 146ac15..647a826 100644
--- a/tests/core/tests/resources.py
+++ b/tests/core/tests/resources.py
@@ -1404,6 +1404,24 @@ class ModelResourceTestCase(TestCase):
self.assertTrue("resource_uri" in data)
self.assertTrue("title" in data)
self.assertTrue("is_active" in data)
+
+ def test_post_list_duplicate(self):
+ self.assertEqual(Note.objects.count(), 6)
@georgedorn
georgedorn / snatchdj.js
Created September 25, 2011 05:09
Fast grab of DJ slot on Turntable.fm
var is_dj = false;
var timeout_handler = 0;
function get_slot(){
if(is_dj){
if (timeout_handler){
clearInterval(timeout_handler);
}
return;
}
@georgedorn
georgedorn / gist:1240964
Created September 25, 2011 18:59
UpdateView that handles "create" as well
from myapp.models import MyModel, RelatedModel
from django.views.generic import UpdateView
class ModelCreateUpdateView(UpdateView):
model = MyModel
def get_object(self, *args, **kwargs):
related_id = self.kwargs.get('related_id')
related_model = RelatedModel.objects.get(pk=related_id)
@georgedorn
georgedorn / autodj.bookmarklet.js
Created September 26, 2011 23:22 — forked from mattsgarrison/autodj.bookmarklet.js
Turntable.fm DJ Script
javascript:(function(g,d,f){if(f)d.info("Session found:",f);else return d.warn("No session found!");var h={check:10,wait:500},b=g.autodj={api:g[f],available:function(a){return b.api.taken_dj_map[a]<0},spot:function(){return b.api.become_dj.data("spot")},become:function(a){b.api.callback("become_dj",a)},waiter:function(a){return function(){return b.available(a)?(b.become(a),a):(-1)}},seated:function(a){return b.api.djs[a]&&b.api.djs[a][0]===b.api.myuserid},wait:function(a,c){var e=c!==void 0,
a=a||h.check,c=c||b.spot();b.seated(c)?d.warn("Spot",c,"taken!"):(e&&d.error("Spot",c,"missed. Restarting..."),d.info("Polling @",a,"ms"),b.check(a,b.waiter(c)))},check:function(a,c){setTimeout(function(){var e=c.call(b);e>0?(d.warn("Spot",e,"open..."),setTimeout(function(){b.wait(a,e)},h.wait)):b.check(a,c)},a)}}})(window,console,function(g,d,f,h,b,a,c,e,i,j,k){try{return g(d)[f](h)[b][a][c][e]()[i](j)[k]}catch(l){return null}}(jQuery,".invite_dj","data","events","click",0,"handler","toString","match",
/\{\s*(.+)\./,1));
@georgedorn
georgedorn / stat_analysis.py
Created November 28, 2012 22:37
Analysis of Random vs Point-Buy for Rolemaster Playtest
"""
Rolls up a huge number of rolemaster characters,
calculates the equivalent values using point-buy,
aggregates the results.
"""
number_of_rolls_per_stat = 3
minimum_stat_roll = 11
number_of_characters = 100000 #pretty consistant at this number, use more if you feel like it
@georgedorn
georgedorn / get_event_types.py
Last active October 19, 2016 18:00
Parses a python codebase to find all event_types along with event_name subtypes where appropriate.
import json
import random
import re
import sys
from pprint import pprint
from subprocess import check_output
from collections import defaultdict
@georgedorn
georgedorn / opencv_OSX.sh
Created October 31, 2016 14:56 — forked from chintak/opencv_OSX.sh
OpenCV with a Virtualenv
# Installing OpenCV python libs on mac to work with virtualenv
# OpenCV 2.4.3
# Python 2.7.3 installed with brew
# assuming you have virtualenv, pip, and python installed via brew
# assuming $WORKON_HOME is set to something like ~/.virtualenvs
# using homebrew - make sure we're current
brew update
@georgedorn
georgedorn / therm.py
Created August 23, 2017 01:49 — forked from ghostbitmeta/therm.py
Python script to control Honeywell Thermostat's through My Total Connect
#!/usr/bin/python
# By Brad Goodman
# http://www.bradgoodman.com/
# brad@bradgoodman.com
####################### Fill in settings below #######################
USERNAME="your@emailaddress.com"
PASSWORD="your_total_comfort_password"
@georgedorn
georgedorn / run_with_proton.sh
Created May 10, 2021 04:44
Running an executable within the proton environment for a steam game on linux
# app id can be found in the URL to the game's store page
cd ~/.steam/steam/steamapps/compatdata/32370 # this is for Star Wars: Knights of the Old Republic; change 32370 to the app id of target game
# This is for Proton 6.3; update as needed, especially if using something like Glorious Eggroll.
STEAM_COMPAT_DATA_PATH=`pwd` WINEPREFIX=`pwd`/pfx "~/.steam/root/steamapps/common/Proton 6.3/proton" run /path/to/executable.exe