This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use the Drafts Credential function to store the API key | |
var credential = Credential.create("Mem.ai", "The mem.ai web API. Generate your key in the Flows section of the mem app."); | |
credential.addTextField("apikey", "API Key"); | |
credential.authorize(); | |
// Retrieve the credential and add to the request headers | |
var headers = { | |
"Content-Type": "application/json", | |
"Authorization": "ApiAccessToken " + credential.getValue("apikey") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib import auth | |
from django.contrib.auth import get_user_model | |
from django.core.management.base import BaseCommand | |
class Command(BaseCommand): | |
help = 'Get a list of all permissions available in the system.' | |
def handle(self, *args, **options): | |
permissions = set() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# get rid of docker containers that exited with status 1 | |
docker rm (docker ps -a -q --filter 'exited=1') | |
# connect to a running container, run bash cos probably no fish :-( | |
docker container exec -it <container name or id> bash | |
# or, to just run a command | |
docker exec -i <container name or id> sh -c "command arg args" | |
# Connect to an image, and have a poke around... | |
docker run --rm -it --entrypoint=/bin/bash <image name> | |
# Install compose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import migrations | |
def combine_names(apps, schema_editor): | |
# We can't import the Person model directly as it may be a newer | |
# version than this migration expects. We use the historical version. | |
Person = apps.get_model('yourappname', 'Person') | |
for person in Person.objects.all(): | |
person.name = '%s %s' % (person.first_name, person.last_name) | |
person.save() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
content_type = ContentType.objects.get(app_label='', model='') | |
#get all permssions for this model | |
perms = Permission.objects.filter(content_type=content_type) | |
group = Group.objects.get(name='') | |
for p in perms: | |
group.permissions.add(perms) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import subprocess | |
def asrun(ascript): | |
"Run the given AppleScript and return the standard output and error." | |
osa = subprocess.Popen(['osascript', '-'], | |
stdin=subprocess.PIPE, | |
stdout=subprocess.PIPE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This file contains the WSGI configuration required to serve up your | |
# web application at http://simplicat.pythonanywhere.com/ | |
# It works by setting the variable 'application' to a WSGI handler of some | |
# description. | |
# | |
# +++++++++++ GENERAL DEBUGGING TIPS +++++++++++ | |
# getting imports and sys.path right can be fiddly! | |
# We've tried to collect some general tips here: | |
# https://www.pythonanywhere.com/wiki/DebuggingImportError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.mail import send_mail | |
from django.template.loader import render_to_string | |
def send_rendered_email(recipients=[]): | |
# send an email to a list of recipients - NB it's a list! | |
ctx = {'var': 'val'} # context dict | |
text_body = render_to_string('path/to/template.txt', ctx) | |
html_body = render_to_string('path/to/template.html', ctx) | |
if send_mail("My subject", text_body, from_email, recipients, html_message=html_body): | |
return "Mail sent" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This script uses Github's API V3 with Basic Authentication to export issues from | |
a repository. The script saves a json file with all of the information from the | |
API for issues, comments, and events (on the issues), downloads all of the | |
images attached to issues, and generates a markdown file that can be rendered | |
into a basic HTML page crudely mimicking Github's issue page. If the gfm module | |
is available, the script will go ahead and render it itself. | |
In the end, you'll be left with a folder containing a raw .json file (which you | |
can use to extract information for your needs, or to import it somewhere else), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# | |
# Very simple Python script to dump all emails in an IMAP folder to files. | |
# This code is released into the public domain. | |
# | |
# RKI Nov 2013 | |
# | |
import sys | |
import imaplib | |
import getpass |
NewerOlder