Skip to content

Instantly share code, notes, and snippets.

Avatar

Christo Crampton toast38coza

View GitHub Profile
@toast38coza
toast38coza / imagekit-upload.py
Created Nov 22, 2021
Manually upload a file to imagekit using python requests
View imagekit-upload.py
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 Jun 30, 2021
Generate an encrypted pdf with WeasyPrint and PyPDF2
View generate-encrypted-pdf.py
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')
View detect-dark-mode
window.matchMedia('(prefers-color-scheme: dark)').matches
@toast38coza
toast38coza / pagination.py
Created Nov 5, 2020
Faceted pagination for Django Rest Framework
View pagination.py
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 Aug 31, 2020
Download a pdf of a webpage using puppeteer
View download-pdf.js
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 Aug 5, 2020
A simple way to do a debounce with Vue (not dependencies required)
View debounce.vue
<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 Apr 17, 2019
Extending the v-autocomplete to support typeahead
View VTypeAhead.vue
<template>
<v-autocomplete
v-model='item'
@update:searchInput='valueTyped'
:items='computedItems'
v-bind='extraProps' >
</v-autocomplete>
</template>
<script>
@toast38coza
toast38coza / .bumpversion.cfg
Created Feb 1, 2019
Fun times with Sentry (and Django)
View .bumpversion.cfg
[bumpversion]
current_version = 1.0.0
commit = False
tag = False
[bumpversion:file:api/custom_settings.py]
@toast38coza
toast38coza / zoom_send_sms.py
Last active Nov 16, 2017
Zoom Connect send SMS
View zoom_send_sms.py
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 Aug 31, 2017
Konga Dashboard for Kong API Gateway
View docker-compose.yml
version: "3"
services:
konga:
image: pantsel/konga:latest
env_file: 'kong.env'
ports:
- '8999:1337'
mongo:
image: mongo
volumes: