Skip to content

Instantly share code, notes, and snippets.

View flyte's full-sized avatar
🎯
Focusing

Ellis Percival flyte

🎯
Focusing
  • London
View GitHub Profile
@thismatters
thismatters / 0001_migrate_to_encrypted.py
Last active March 5, 2024 00:07
Migrating existing columns to use django-cryptography
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
from django_cryptography.fields import encrypt
app_with_model = 'account'
model_with_column = 'User'
column_to_encrypt = 'email_address'
column_field_class = models.CharField
@ekiara
ekiara / django-getting-a-model-from-a-string.md
Last active April 11, 2022 11:59
django-getting-a-model-from-a-string
@nvgoldin
nvgoldin / asyncio_shutdown_loop.py
Created July 27, 2016 13:34
Python 3.5 asyncio - shutdown all tasks safely using signal handler
import signal
import functools
async def looping_task(loop, task_num):
try:
while True:
print('{0}:in looping_task'.format(task_num))
await asyncio.sleep(5.0, loop=loop)
except asyncio.CancelledError:
return "{0}: I was cancelled!".format(task_num)
@alexanderwallin
alexanderwallin / unpack_stems.sh
Created June 27, 2016 18:38
Unpacks stems into folders with cover art and separate tracks using ffmpeg
#!/bin/bash
#
# Extracts tracks from stems files and puts them in folders
# named after the stem filenames.
#
for stem in *.mp4
do
name=${stem%\.*}
@liluxdev
liluxdev / gist:363aa9b0191a5c63dc6b
Created November 17, 2014 11:57
ADFS IdP Example SAML metadata
<EntityDescriptor ID="_46a4ff39-ad96-499d-91d9-040588865218" entityID="http://adfs.server.url/adfs/services/trust" xmlns="urn:oasis:names:tc:SAML:2.0:metadata"><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/><ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/><ds:Reference URI="#_46a4ff39-ad96-499d-91d9-040588865218"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/><ds:DigestValue>tjL/uSGbAj7aGTU/RrT2ukV7FXOnF/nmKhRD3WtN/Lo=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>X+XDwL8chvi4SzQnrQTlyovg8wgBM1Z0ac1tozXY78E9jRkCI8Ce6fuACSK4i1Ak51NeCXev2v7c/yzFnbTaC7Y3eGYcEt2e75BUbXmEJFMiHy0MSBEKMot06LFe5zLy9NPCbc9aOVwKZT6Le8dLndG6WTHgExYdf/ujaqLFHukQ4kC5EfU+hI2SLocJGFr
"UserData": {
"Fn::Base64": { "Fn::Join":["", [
"#!/bin/bash -ex\n",
"apt-get update\n",
"apt-get -y install python-setuptools\n",
"mkdir aws-cfn-bootstrap-latest\n",
"curl https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz | tar xz -C aws-cfn-bootstrap-latest --strip-components 1\n",
"easy_install aws-cfn-bootstrap-latest\n",
"/usr/local/bin/cfn-init --stack ", { "Ref":"AWS::StackName" }, " --resource WebServer", " --region ", { "Ref": "AWS::Region" }, "\n",
"\n",
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active May 3, 2024 16:53
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@abrookins
abrookins / gist:3440646
Created August 23, 2012 19:32
Set the path of an ImageField in Django
from django.db import models
# Assuming this model.
class Example(models.Model):
image = models.ImageField(upload_to="somewhere/special")
# You want to set this field to point to an existing image (in a script, or a view, etc.).
example = Example.objects.get(id=1)