Skip to content

Instantly share code, notes, and snippets.

View clintonb's full-sized avatar

Clinton Blackburn clintonb

View GitHub Profile
image: docker:latest
services:
- docker:dind
variables:
CONTAINER_TEST_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
CONTAINER_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest
before_script:
@clintonb
clintonb / oauth_test.py
Last active November 8, 2017 16:05
Test JWTs with the edX Discovery Service
"""
This script tests the retrieval of a JWT access token and submission of the token to the Discovery Service. If all goes
well, you should see a print out of the token and data from the Discovery API's courses endpoint.
NOTE: You will need to install the edx-rest-api-client package at https://pypi.python.org/pypi/edx-rest-api-client.
"""
from edx_rest_api_client.client import EdxRestApiClient
# TODO Set these values to the URLs of your own services
ACCESS_TOKEN_URL = 'https://courses.example.com/oauth2/access_token'
@clintonb
clintonb / queryset_decorator_example.py
Last active October 6, 2017 16:03
Example of counting number of invocations for a Django QuerySet method
def counter(fn):
"""
Adds a call counter to the given function.
Source: http://code.activestate.com/recipes/577534-counting-decorator/
"""
def _counted(*largs, **kargs):
_counted.invocations += 1
fn(*largs, **kargs)
_counted.invocations = 0
@clintonb
clintonb / history_cleanup.py
Created September 19, 2017 14:17
Delete ecommerce history data
import datetime
import pytz
from oscar.core.loading import get_model
from ecommerce.courses.models import Course
from ecommerce.invoice.models import Invoice
Order = get_model('order', 'Order')
OrderLine = get_model('order', 'Line')
@clintonb
clintonb / update_loadtest_branches.sh
Created August 14, 2017 21:19
Updated loadtest branches
#!/usr/bin/env bash
git checkout master
git pull
services=(credentials discovery ecommerce)
for service in "${services[@]}"
do
# Is the openedx directory useful, or causing pain? The `skip_unless_lms` test decorator seems like an anti-pattern. If an
# app is specific to one project, its code should probably live in that project. This script is meant to help determine how
# many, and which, apps should be moved out of openedx.
import pprint
import os
DJANGO_APP_DIRS = (
'cms/djangoapps',
@clintonb
clintonb / create_profiles.py
Created May 13, 2016 13:22
Create profiles for edx-platform service users
""" Create profiles for service users. """
from django.contrib.auth import get_user_model
from student.models import UserProfile
User = get_user_model()
usernames = ('affiliate_window', 'course_discovery_worker', 'programs_worker', 'sailthru',)
for username in usernames:
@clintonb
clintonb / delete_baskets.py
Created March 1, 2016 20:39
Delete Otto baskets
from edx_rest_api_client.client import EdxRestApiClient
ACCESS_TOKEN = ''
basket_ids = []
api_client = EdxRestApiClient('https://ecommerce.stage.edx.org/api/v2/', oauth_access_token=ACCESS_TOKEN)
for basket_id in basket_ids:
if not api_client.baskets(basket_id).delete():
print('Failed to delete basket [{}].'.format(basket_id))
@clintonb
clintonb / credit-queries.sql
Created October 15, 2015 22:01
Queries for answering credit-related questions
-- Number of students who have submitted credit requests,
-- grouped by course and status.
SELECT
co.course_key
, cr.status
, COUNT(1) AS 'count'
FROM
credit_creditrequest cr
JOIN credit_creditcourse co ON cr.course_id = co.id
GROUP BY
@clintonb
clintonb / setup
Last active November 28, 2016 15:51
Create a new edx-platform superuser
sudo -u www-data /edx/bin/python.edxapp /edx/app/edxapp/edx-platform/manage.py lms --settings aws create_user -s -p edx -e edxapp@example.com
sudo -u www-data /edx/bin/python.edxapp /edx/app/edxapp/edx-platform/manage.py lms --settings aws shell
from django.contrib.auth.models import User
me = User.objects.get(username="edxapp")
me.is_superuser = True
me.is_staff = True
me.save()