Skip to content

Instantly share code, notes, and snippets.

View jcdyer's full-sized avatar

Cliff Dyer jcdyer

View GitHub Profile
class PathMap(object):
sep = u'.'
def __init__(self):
self._store = {}
def __setitem__(self, key, value):
segments = key.rstrip(self.sep).split(self.sep)
next_ = self._store
diff --git a/lms/djangoapps/course_api/serializers.py b/lms/djangoapps/course_api/serializers.py
index 6f30d7e..4ab8d45 100644
--- a/lms/djangoapps/course_api/serializers.py
+++ b/lms/djangoapps/course_api/serializers.py
@@ -18,12 +18,12 @@ class CourseSerializer(serializers.Serializer): # pylint: disable=abstract-meth
Serializer for Course objects
"""
- id = serializers.CharField(read_only=True) # pylint: disable=invalid-name
+ course_id = serializers.CharField(source='id', read_only=True) # pylint: disable=invalid-name
class UniversalSet(set):
def __init__(self):
super(UniversalSet, self).__init__([])
def __and__(self, other):
if not isinstance(other, set):
other = set(other)
return other
def __rand__(self, other):
@jcdyer
jcdyer / typed.py
Last active November 13, 2015 15:47
from collections import namedtuple, OrderedDict
import functools
import pytest
def typednamedtuple(name, fields):
factory = namedtuple(name, fields.keys())
@functools.wraps(factory)
def wrapper(*args, **kwargs):
for spec, arg in zip(fields.iteritems(), args):
[alias]
gl1 = log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all
gl2 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all
glog = !"git gl2"
>>> def f():
... return {1, 2, 3}
...
>>> dis.dis(f)
2 0 LOAD_CONST 1 (1)
3 LOAD_CONST 2 (2)
6 LOAD_CONST 3 (3)
9 BUILD_SET 3
12 RETURN_VALUE
>>> def g():
@jcdyer
jcdyer / Usage.txt
Last active October 1, 2015 17:58
This script will generate an OAuth bearer token for use in curl or python scripts that use requests.
COMMAND LINE:
$ export OAUTH_CLIENT_ID=ffffbbbb777733330000
$ oauthtoken.py staff edx
3bae7d8cf43a69e34a35188636c3553e8b52a89c
$ token=`oauthtoken.py staff edx`
$ curl -H "Authorization: Bearer $token" http://localhost:8000/api/user/v1/accounts/staff
{"username":"staff",...}
PYTHON
@jcdyer
jcdyer / proper.json
Created May 17, 2013 19:24
The template that should be created by a pyplate with nested joins.
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "demonstration of an error with nested joins.",
"Resources": {
"Value": {
"Fn::Join": [
"",
[
"site_url: ",
{
@jcdyer
jcdyer / template.json
Created May 17, 2013 19:22
The JSON template created by a pyplate with nested joins.
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "demonstration of an error with nested joins.",
"Resources": {
"Value": {
"Fn::Join": [
"",
[
"site_url: ",
[
@jcdyer
jcdyer / template.py
Created May 17, 2013 19:21
An example of a pyplate that creates an invalid template when nesting joins.
description = 'demonstration of an error with nested joins.'
cft = CloudFormationTemplate(description)
site_url = join('.', ref('AWS::StackName'), 'mmstacks.net'),
cft.resources.update({'Value': join('', 'site_url: ', site_url)})