Skip to content

Instantly share code, notes, and snippets.

View toast38coza's full-sized avatar

Christo Crampton toast38coza

View GitHub Profile
FROM python:3.4
ENV PYTHONUNBUFFERED 1
RUN mkdir -p /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/
@toast38coza
toast38coza / call_soap_with_requests.py
Created October 22, 2014 11:17
Call a SOAP Service with plain old requests
import requests
url="http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL"
#headers = {'content-type': 'application/soap+xml'}
headers = {'content-type': 'text/xml'}
body = """<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns0="http://ws.cdyne.com/WeatherWS/" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<ns1:Body><ns0:GetWeatherInformation/></ns1:Body>
</SOAP-ENV:Envelope>"""
@toast38coza
toast38coza / github_repo.py
Created February 9, 2016 18:05
An Ansible module for managing github repos
#!/usr/bin/python
DOCUMENTATION = '''
---
module: github_repo
short_description: Manage your repos on Github
'''
EXAMPLES = '''
- name: Create a github Repo
@toast38coza
toast38coza / commands
Last active March 3, 2022 11:30
Simple systemd unit for running a django app
# start / stop / restart / status
systemctl start test
systemctl stop test
systemctl restart test
systemctl status test
# logs use journalctl:
# tail the logs for unit `django`
journalctl -f -u django
@toast38coza
toast38coza / exclamation.py
Created May 18, 2011 10:25
Jiminy cricket! A fun exclamation filter for django
from django import template
from django.conf import settings
from random import choice
register = template.Library()
#usage: {{explamation}}! A fun exclamation filter for django
@register.filter(name="exclamation")
def exclamation(punctuation):
@toast38coza
toast38coza / call_weather_service.py
Created August 29, 2014 08:25
Calling a SOAP WebService with Python Suds
from suds.client import Client
url="http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL"
client = Client(url)
print client ## shows the details of this service
result = client.service.GetWeatherInformation()
print result ## see: restult.txt below
@toast38coza
toast38coza / imagekit-upload.py
Created November 22, 2021 19:19
Manually upload a file to imagekit using python requests
imagekit_private_key = '..'
base = 'https://api.imagekit.io/v1'
# files = {"file": result.content} # example from a url
files = {"file": open('/some/file.png', 'rb')} # from a local file
data = {
"fileName": "my-file.png",
"tags": "foo,bar,baz",
"folder": "/remote/file/path/"
}
@toast38coza
toast38coza / generate-encrypted-pdf.py
Last active June 30, 2021 22:13
Generate an encrypted pdf with WeasyPrint and PyPDF2
import PyPDF2
import io
from weasyprint import HTML
password = 'foo'
url = "https://google.com"
pdf = HTML(url).write_pdf()
in_file = io.BytesIO(pdf)
out_file = open('google.pdf', 'wb')
@toast38coza
toast38coza / vuex_persist.js
Created January 18, 2017 13:20
Dump the entire vuex store to localStorage and retrieve it again.
// key to use for get/set state:
export const LOCALSTORAGE_KEY = '..'
// as an action:
export const PERSIST_ACTION = ({ rootState }) => {
let stateAsString = JSON.stringify(rootState)
window.localStorage.setItem(LOCALSTORAGE_KEY, stateAsString)
}
// restore a cached vuex store:
window.matchMedia('(prefers-color-scheme: dark)').matches