Instantly share code, notes, and snippets.

$ chef-client --once --local-mode --config /\
Users/cnk/Code/sandbox/customizing_chef/part3_examples/solo.rb --override-runlist testcookbook::default
Starting Chef Client, version 12.3.0
[2015-07-09T17:08:42-07:00] WARN: Run List override has been provided.
[2015-07-09T17:08:42-07:00] WARN: Original Run List: []
[2015-07-09T17:08:42-07:00] WARN: Overridden Run List: [recipe[testcookbook::default]]
resolving cookbooks for run list: ["testcookbook::default"]
Synchronizing Cookbooks:
- testcookbook
Compiling Cookbooks...
def site_authors(request):
return Author.objects.filter(
class Authorships(Orderable, models.Model):
author = models.ForeignKey('Author', related_name='author_paper_relationship', on_delete=models.CASCADE)
paper = ParentalKey('Page', related_name='paper_author_relationship', on_delete=models.CASCADE)
panels = [
SnippetChooserPanel('author', qs_restriction=site_authors, editable=False)
class Author(models.Model):
first_name = models.CharField(max_length=128)
last_name = models.CharField(max_length=128)
site = models.ForeignKey('wagtailcore.Site', on_delete=models.CASCADE)
panels = [
FieldPanel('first_name', classname='col6 first-name'),
FieldPanel('last_name', classname='col6 last-name'),
from import BaseCommand
from import CampusAnnouncementImporter
class Command(BaseCommand):
help = "Imports Campus Announcements."
def handle(self, **options):
importer = CampusAnnouncementImporter()
View application_controller.rb
def permission_denied
@page_args[:title] = "Permission Denied"
@body = "You are not allowed to view the page you have requested. If you believe you should have been able to view that page, please use the contact information in the footer to report this problem."
render 'system/errors', status: 403
from django.conf import settings
class DefaultDatabaseRouter(object):
def db_for_read(self, model, **hints):
This is the fall through. If the table isn't found in mk_web_core, it must be here.
if model._meta.app_label in ['accounts', 'materials',]:
return 'mk_web_core'
View app-controllers-application_controller.rb
class ApplicationController < ActionController::Base
# omitted stuff
# Used to correct content type for files uploaded with bulkupload or from PicMonkey
def correct_content_type_for_octet_stream(filedata)
return nil if filedata.blank?
# see what the unix file command thinks this is
if filedata.content_type == 'application/octet-stream'
filedata.content_type = type_from_file_command(filedata.path)
class FooSerializer(rest_serializers.ModelSerializer):
class Meta:
model = MultipleChoiceQuestion
fields = ('id', 'model_name', 'title', 'student_answer_url', 'block_state', 'ready_preview', )
def validate(self, data):
'''Mostly this just shovels data from the request into validated_data. '''
errors = {}
print('in validate initial data is: ', type(self.initial_data))
last_answer = StudentNumericAnswer.objects.filter(numeric_question=question_id,'updated_at').last()
if request.method == 'GET':
if not last_answer:
return Response(status=status.HTTP_404_NOT_FOUND)
data = StudentNumericAnswerSerializer(last_answer, context={'request': request}).data
# CNK cheat and add the correct answer data here for now
if last_answer.is_answer_correct or last_answer.gave_up:
data['correct_answer'] = {'correct_answer': question.correct_answer,
Starting development server at
Quit the server with CONTROL-C.
in update view
serializer not valid
{'title': ['This field may not be blank.']}