Skip to content

Instantly share code, notes, and snippets.

View scott-w's full-sized avatar

Scott Walton scott-w

  • Hotjar
  • Newcastle upon Tyne
View GitHub Profile
@scott-w
scott-w / python3.py
Created March 18, 2017 13:01
Backport Python 3 features to Python 2
from __future__ import absolute_import, print_function, unicode_literals
from __future__ import absolute_import, print_function, unicode_literals
from six import string_types, text_type, binary_type
## Python 2 only
some_value = 20
value_as_string = unicode(some_value)
value_as_bytes = str(some_value)
@scott-w
scott-w / six_classes.py
Created March 18, 2017 13:18
Classes in Six
from __future__ import absolute_import, print_function, unicode_literals
from six import python_2_unicode_compatible
from django.db import models
@python_2_unicode_compatible
class MyModelClass(models.Model):
"""Python 2 and 3 compatible model.
@scott-w
scott-w / exceptions.py
Created March 18, 2017 13:27
Catching Exceptions
from __future__ import absolute_import, print_function, unicode_literals
from .modules import my_function, handle_exception
## Python 2 only
try:
my_function()
except AttributeError, exc:
handle_exception()
@scott-w
scott-w / find_exceptions.sh
Last active March 18, 2017 13:34
Find Exceptions
grep "except\s\+\w\+,\s*\w\+:$"
@scott-w
scott-w / index.html
Created March 25, 2017 18:22
Your Index Page
<!DOCTYPE html>
<html>
<head>
<!-- ... -->
</head>
<body>
<!-- Where our application will render everything to -->
<div id="root"></div>
<!-- Link to your compiled application -->
@scott-w
scott-w / driver.js
Last active April 1, 2017 07:20
Application Root
import {Application, View} from 'backbone.marionette';
import _ from 'underscore';
// If you use a navbar or panel
import {NavView} from './views/nav';
// Your home page
import {IndexView} from './views/index';
const RootView = View.extend({
@scott-w
scott-w / driver.js
Last active April 1, 2017 07:19
A skeleton for setting up an application with a router.
import Bb from 'backbone';
import {Application, View} from 'backbone.marionette';
import _ from 'underscore';
// The Router class defined above
import {Router} from './router'
// If you use a navbar or panel
import {NavView} from './views/nav';
// Your home page
import {Model} from 'backbone';
export const NoteModel = Model.extend({
urlRoot: '/notes/',
defaults: {
header: '',
body: ''
}
});
@scott-w
scott-w / root.js
Last active April 26, 2017 17:54
Root View for a simple note-taking app
import {View} from 'backbone.marionette';
import {template} from 'underscore';
import {NoteCollection} from './notes';
import {NoteModel} from './note';
import {NoteListView} from './list';
import {NoteView} from './detail';