Skip to content

Instantly share code, notes, and snippets.

View toast38coza's full-sized avatar

Christo Crampton toast38coza

View GitHub Profile
@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')
window.matchMedia('(prefers-color-scheme: dark)').matches
@toast38coza
toast38coza / pagination.py
Created November 5, 2020 20:46
Faceted pagination for Django Rest Framework
class FacetedPagination(pagination.PageNumberPagination):
"""
If requested, will include facet information in the response
Example response
```
{
"links": {
"next": ..,
"previous": ..,
@toast38coza
toast38coza / download-pdf.js
Last active August 31, 2020 00:41
Download a pdf of a webpage using puppeteer
const puppeteer = require('puppeteer');
const fs = require('fs');
const URL = https://apexcharts.com/" // set this to the url you want to generate a pdf of
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(URL, {waitUntil: 'networkidle2'});
await page.pdf({path: 'download.pdf', format: 'A4'});
await browser.close();
@toast38coza
toast38coza / debounce.vue
Created August 5, 2020 00:34
A simple way to do a debounce with Vue (not dependencies required)
<template>
<input type=text v-model='value' @kepup='debounceExpensiveMethod' />
</template>
<script>
export default {
name: 'SomeComponent',
data () {
return {
timeout: null
}
@toast38coza
toast38coza / VTypeAhead.vue
Last active April 17, 2019 20:53
Extending the v-autocomplete to support typeahead
<template>
<v-autocomplete
v-model='item'
@update:searchInput='valueTyped'
:items='computedItems'
v-bind='extraProps' >
</v-autocomplete>
</template>
<script>
@toast38coza
toast38coza / .bumpversion.cfg
Created February 1, 2019 16:38
Fun times with Sentry (and Django)
[bumpversion]
current_version = 1.0.0
commit = False
tag = False
[bumpversion:file:api/custom_settings.py]
@toast38coza
toast38coza / zoom_send_sms.py
Last active November 16, 2017 14:36
Zoom Connect send SMS
import requests
def send_sms(to, content):
token = '..'
email = '..'
headers = {'Content-type': 'application/json', 'Accept': 'application/json'}
params = {
token: token,
email: email
}
@toast38coza
toast38coza / docker-compose.yml
Created August 31, 2017 09:29
Konga Dashboard for Kong API Gateway
version: "3"
services:
konga:
image: pantsel/konga:latest
env_file: 'kong.env'
ports:
- '8999:1337'
mongo:
image: mongo
volumes: