Skip to content

Instantly share code, notes, and snippets.

View ninapavlich's full-sized avatar

Nina Pavlich ninapavlich

View GitHub Profile
@ninapavlich
ninapavlich / edit.js
Last active September 17, 2019 16:16
Edit Parenting Item
javascript: (async function() {
var bookmarkletVersion = "1.0.0";
var apiRoot = "https://parenting.nytimes.com/api/v1";
var cmsRoot = "https://nyt-parentingcms-prd.appspot.com";
console.log("Running Parenting Edit Bookmarlet v" + bookmarkletVersion);
/*
Generic function for requesting URLs
*/
@ninapavlich
ninapavlich / test_logging.py
Last active May 29, 2019 23:52
Example Django command for testing different logging levels
import logging
from django.core.management.base import BaseCommand, CommandError
logger = logging.getLogger('django')
class Command(BaseCommand):
def handle(self, *args, **options):
@ninapavlich
ninapavlich / troubleshoot.sh
Last active February 4, 2019 20:13
Troubleshoot Python/NGINX Deployment
# 1. Check Services
# - NGINX
sudo nginx -t
sudo service nginx status
sudo service uwsgi status
# 2. Logs for Errors
tail /var/log/nginx/access.fifo
tail /var/log/nginx/error.fifo
@ninapavlich
ninapavlich / settings.py
Created December 20, 2018 23:32
Django Slack Error Logger using File Uploads
# My favorite logging settings
# -----------------------------------------------------------------------------
# LOGGING
# -----------------------------------------------------------------------------
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'propagate': 1,
'filters': {
@ninapavlich
ninapavlich / nginx.conf
Created July 2, 2018 20:34
Serve media from multiple directories
server {
....
location ~ /media/([a-zA-Z0-9\-_\/\.]+)$ {
root /var/www/mysite/;
try_files /media/$1 /uploads/$1 =404;
}
@ninapavlich
ninapavlich / admin.py
Last active July 26, 2022 04:17
Custom configuration for django-autocomplete-light plugin
from django import forms
from django.contrib import admin
from dal import autocomplete, forward
class AdminAutocompleteFormMixin(forms.ModelForm):
class Media:
js = ('admin/autocomplete/forward.js',
'admin/autocomplete/select_admin_autocomplete.js')
@ninapavlich
ninapavlich / super_file_models.py
Last active October 31, 2023 20:12
Custom Django File field that provides meta data (md5, mime type, content type, size) to sibling fields, creates thumbnails in sibling fields, can add watermarks to thumbnails, and can enforce size and various validations.
import hashlib
import io
import logging
import mimetypes
import os
import re
import tempfile
from xml.dom import minidom
from PIL import Image
@ninapavlich
ninapavlich / alarm_player.ino
Created May 1, 2018 04:23
Customization of Adafruit's music player for an alarm
// Specifically for use with the Adafruit Feather, the pins are pre-set here!
// include SPI, MP3 and SD libraries
#include <SPI.h>
#include <SD.h>
#include <Adafruit_VS1053.h>
// These are the pins used
#define VS1053_RESET -1 // VS1053 reset pin (not used!)
@ninapavlich
ninapavlich / alarm.ino
Created May 1, 2018 01:32
First few bars of Gymnopedia No 1 - very very roughly
/*
First few bars of Gymnopedia No 1 - very very roughly
Requires pitches.h
[email protected]
*/
#include "pitches.h"
const int speakerPinMelody = 3;
@ninapavlich
ninapavlich / woeisme.ino
Created April 28, 2018 22:56
First few bars of Woe Is Me (World's Smallest Violin) from Spongebob Square Pants
/*
First few bars of Woe Is Me (World's Smallest Violin) from Spongebob Square Pants
Requires pitches.h
[email protected]
*/
#include "pitches.h"
const int speakerPinMelody = 26;