Skip to content

Instantly share code, notes, and snippets.

View ninapavlich's full-sized avatar

Nina Pavlich ninapavlich

View GitHub Profile
@ninapavlich
ninapavlich / md5_file_field.py
Last active April 4, 2018 05:36
Image and File fields that assist in storing MD5 info on another related field
import hashlib
from django.db import models
from django.db.models.fields.files import FileDescriptor, FieldFile, ImageFieldFile, ImageFileDescriptor
"""
USAGE:
file = MD5FileField(md5_field='md5')
md5 = models.CharField(max_length=255) #NOTE - this field must come AFTER file field to be processed correctly.
"""
@ninapavlich
ninapavlich / check_repo_status.sls
Created March 15, 2018 01:54
Manually check if repo has been updated
#!/bin/sh
GIT_DIR="/srv/project-name/src/"
RESTART_SCRIPT="sh /etc/project-name/deploy.sh"
SLACK_WEBHOOK="https://hooks.slack.com/services/XXXXXX/XXXXXX/XXXXXXXXXXXX"
SLACK_CHANNEL="#development"
echo "Fetching..."
git --git-dir=$GIT_DIR.git --work-tree=$GIT_DIR fetch
@ninapavlich
ninapavlich / deploy.sh
Created March 15, 2018 01:53
Manually deploy python project
#!/bin/sh
GIT_DIR="/srv/project-name/src/"
#First update the repo
git --git-dir=$GIT_DIR.git --work-tree=$GIT_DIR fetch
git --git-dir=$GIT_DIR.git --work-tree=$GIT_DIR reset --hard origin/master
echo "Pulled latest code from origin/master"
#Manage virtual environment
@ninapavlich
ninapavlich / lights.ino
Created March 5, 2018 01:11
Softly twinkling lights for Teensy 2.0++
int ledPin1 = 27;
int ledPin2 = 0;
int ledPin3 = 1;
int ledPin4 = 14;
int ledPin5 = 15;
int ledPin6 = 16;
int ledPin7 = 24;
int ledPin8 = 25;
@ninapavlich
ninapavlich / django_ace_grappelli.css
Created February 22, 2018 21:32
CSS Shim for Django Ace fullscreen mode when used with Grappelli
/*
USAGE:
Fullscreen mode for Django Ace doesn't work correctly because the CSS isn't quite compatible with Django Grappelli's.
To work around it, place this file in a static directory and include in admin like so:
@admin.register(MyModel)
class MyModelAdmin(admin.ModelAdmin):
class Media:
css = {
'all': ('admin/django_ace_grappelli.css',)
#Formats time differences in Python
def timesince(self, start=None, end=None, timesuffix='ago', instant_label='Just now'):
if not end:
end = timezone.now()
if not start:
start = self.start_time
dt = end - start
@ninapavlich
ninapavlich / melody.ino
Last active April 28, 2018 22:51
First few bars of Frolic (Curb Your Enthusiasm theme) for Arudino
/*
First few bars of Frolic from Curb Your Enthusiasm
Requires pitches.h
nina@ninalp.com
*/
#include "pitches.h"
const int speakerPinMelody = 9;
const int speakerPinTweeter = 10; /* not really necessary; just for comedic effect */
@ninapavlich
ninapavlich / retrieve-files.py
Last active January 29, 2018 19:58
Retrieve list of files in a given folder with Google Drive API (v3) + Requests + ServiceAccountCredentials
import os
import json
import urllib
import requests
from oauth2client.service_account import ServiceAccountCredentials
from django.core.management.base import BaseCommand, CommandError
@ninapavlich
ninapavlich / test.sh
Last active January 24, 2018 20:23
Bash script for sending a test result record to a password-protected elasticsearch endpoint
#!/bin/sh
# Example Usage:
# test.sh 'cluster-id' 'node-id' 'my-fancy-app' 'tag-a,tag-b' 'cluster-id-node-id-my-fancy-app-unit-test-a' 'false' 'Unit Test A is failing because of X'
# test.sh 'cluster-id' 'node-id' 'my-fancy-app' 'tag-a,tag-b' 'cluster-id-node-id-my-fancy-app-unit-test-a' 'true' 'Unit Test A is passing'
# Example Usage - same service but different UUID tests:
# test.sh 'cluster-id' 'node-id' 'nginx' 'tag-a,tag-b' 'cluster-id-node-id-nginx-https-test' 'false' 'HTTPS not working on NGINX'
# test.sh 'cluster-id' 'node-id' 'nginx' 'tag-a,tag-b' 'cluster-id-node-id-nginx-port-test' 'false' 'NGINX is not running on port 80'
# test.sh 'cluster-id' 'node-id' 'nginx' 'tag-a,tag-b' 'cluster-id-node-id-nginx-memory' 'false' 'NGINX is using too much memory'
@ninapavlich
ninapavlich / heartbeat.sh
Last active January 24, 2018 20:16
Bash script for sending a heartbeat record to a password-protected elasticsearch endpoint
#!/bin/sh
# Inputs:
# $1 = cluster
# $2 = node
# $3 = service
# $4 = tags
# $5 = uuid
# $6 = heartbeat_frequency_seconds