Skip to content

Instantly share code, notes, and snippets.

View sweldon's full-sized avatar

Steve Weldon sweldon

  • Boston, MA
View GitHub Profile
@sweldon
sweldon / 000-default.conf
Last active December 6, 2022 16:46
Django Apache2 WSGI Config Example
WSGIPythonPath /home/ubuntu/your-repo/venv/lib/python3.6/site-packages
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
@sweldon
sweldon / wsgi.py
Last active March 13, 2020 20:38
Django WSGI Example
"""
WSGI config for a django project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/
"""
import os
@sweldon
sweldon / flower.conf
Created March 13, 2020 20:44
Supervisor Config Example
[supervisord]
environment=SOME_ENV_VAR="blah",ANOTHER_ENV_VAR="blah"
[program:flower]
command=/home/ubuntu/venv/bin/flower -A projName --port=5555
directory=/home/ubuntu/projName
autostart=true
autorestart=true
stderr_logfile=/var/log/flower-supervisor.err.log
stdout_logfile=/var/log/flower-supervisor.out.log
@sweldon
sweldon / tasks.py
Created March 13, 2020 20:58
Celery Periodic Task in Django Example
from celery.decorators import periodic_task
from datetime import timedelta
@periodic_task(run_every=(timedelta(seconds=10)), name="my_task", ignore_result=True)
def my_task():
return "success"
@sweldon
sweldon / handle_sms.py
Last active March 13, 2020 21:03
Handle SMS from Gmail
import imaplib
mail = imaplib.IMAP4_SSL('imap.gmail.com')
mail.login(os.environ["EMAIL_USER"], os.environ["EMAIL_PASS"])
def handle_text():
mail.list()
# List of "folders" aka labels in gmail.
mail.select("inbox")
result, data = mail.search(None, "ALL")
@sweldon
sweldon / example_test_ios_push.apns
Last active April 23, 2020 18:46
Example APNS for Testing IOS Push
{
"aps": {
"alert": {
"title": "Comment mention",
"body": "Comment mention body",
},
"badge": 1
},
"Simulator Target Bundle": "bundle_id.com",
"push_type": "comment",
@sweldon
sweldon / gist:fd67026c8e10c5efc73a0f1ce7b1e073
Created December 6, 2022 21:56
Amazon Linux Color Prompt
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
@sweldon
sweldon / filter_dicts.py
Last active October 25, 2023 19:17
Filter list of dictionaries
# Filter a list of dicts by a dynamic number of conditions (which is a dict of key/vals)
# If you pass a list as a filter value, it will be treated as an OR condition
list_of_dicts = [{"name": "Steve", "age": 29}, {"name": "John", "age": 99}]
filter_conditions = {"name": "Steve", "age": [18, 29]} # Would return 1 result
filtered_records = list(filter(
lambda record: all((
# If the value is a list, filter for any values in that list (i.e. OR condition)
record[filter_key] in filter_value