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
@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):
@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, {
.custom-form, form {
max-width: 800px;
margin: 0 auto;
}
#sub-container {
padding-top: 3rem !important;
}
#left-sidebar {
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",
# Training config
runtime:
cuda: true
logging:
# Logging to Weights and Bias dashboard
wandb:
project_name: null
# Saving checkpoint to S3
checkpoint:
save_name: null
runtime:
type: dict
schema:
cuda:
type: boolean
required: true
nullable: false
logging:
type: dict
"""
Synthesizes speech from the input string of text.
from reader.services.translate.polly import text_to_speech_mp3
reading = Reading.objects.last()
with open('./test.mp3', 'wb') as f:
text_to_speech_mp3(reading, f)
"""
from io import BytesIO
import boto3
@MattSegal
MattSegal / example.js
Last active September 15, 2020 23:20
import React, { useState } from 'react'
import Header from './components/Header.js'
import Game from './components/Game.js'
import LeaderBoard from './components/LeaderBoard.js'
import Spinner from './components/Spinner.js'
// Don't hardcode strings, use constants
const DEFAULT_NAME = 'jeff'
export default function App(){
import React, { useState } from 'react'
import Header from './components/Header.js'
import Game from './components/Game.js'
import LeaderBoard from './components/LeaderBoard.js'
import Spinner from './components/Spinner.js'
// Don't hardcode strings, use constants
const DEFAULT_NAME = 'jeff'
export default function App(){
user root;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
}
http {
##