Skip to content

Instantly share code, notes, and snippets.

View MattSegal's full-sized avatar
💭
Recovering engineering student

Matt Segal MattSegal

💭
Recovering engineering student
View GitHub Profile
runtime:
type: dict
schema:
cuda:
type: boolean
required: true
nullable: false
logging:
type: dict
# Training config
runtime:
cuda: true
logging:
# Logging to Weights and Bias dashboard
wandb:
project_name: null
# Saving checkpoint to S3
checkpoint:
save_name: null
from cerberus import Validator
ENV_CHOICES = ("aws", "desktop", "laptop")
CONFIG_SCHEMA = {
"runtime": {
"type": "dict",
"schema": {"cuda": {"type": "boolean", "required": True, "nullable": False},},
},
"logging": {
"type": "dict",
.custom-form, form {
max-width: 800px;
margin: 0 auto;
}
#sub-container {
padding-top: 3rem !important;
}
#left-sidebar {
@MattSegal
MattSegal / http.js
Created November 27, 2018 02:08
HTTP API Boilerplate for ES5 JavaScript + Django
import Cookies from 'universal-cookie'
// Get Django cross site request forgery cookie for API requests.
const getCSRF = () => new Cookies().get('csrftoken')
// HTTP helper functions.
const http = {
// POST a JSON to URL (create new resource)
post: (url, data) =>
fetch(url, {
@MattSegal
MattSegal / models.py
Created August 8, 2018 22:55
Wagtail body image lookup
from bs4 import BeautifulSoup
from wagtail.core.fields import RichTextField
from wagtail.core.models import Page
class BlogPost(Page):
body = RichTextField()
images = models.ManyToManyField('wagtailimages.Image')
def save(self, *args, **kwargs):
class ArticlePage(Page):
pass
class SectionPage(Page):
# ...
def route(self, request, path_components):
"""
Perform ORM optimisations on ArticlePage to speed up article load times
"""
try:
@MattSegal
MattSegal / super_and_subscript.py
Created June 19, 2018 03:29
Draftail Super and Subscript
# models.py
from wagtail.core.fields import RichTextField
from wagtail.core.models import Page
class MyModel(Page):
# ...
body = RichTextField(features=[
# ...
'subscript',
'superscript',
@MattSegal
MattSegal / text-block.js
Created May 11, 2018 00:48
Draftail atomic block state change
import { Component } from 'react';
const { AtomicBlockUtils, EditorState, SelectionState, Modifier } = window.DraftJS
// The source gathers data for new entities that are being added in the Draftail editor
// It is invoked only when an new embed is inserted by the user
export class TextSource extends Component {
componentDidMount() {
const { editorState, entityType, onComplete } = this.props;
@MattSegal
MattSegal / salt.py
Last active October 10, 2017 00:13
import hashlib
user_password = 'hunter12'
database_password = '6618f892842dcbc32f7968cc8f73b5b0065ec04e'
salt = '#&@#DH@HDHUUS'
user_password_hashed = hashlib.sha1(user_password + salt).hexdigest()
print(user_password_hashed == user_password_hashed)