Skip to content

Instantly share code, notes, and snippets.

View toast38coza's full-sized avatar

Christo Crampton toast38coza

View GitHub Profile
@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 / README.md
Last active November 4, 2019 08:26
Take a large file and cache it in memcached

Installation

pip install -r requirements.txt

Run

python chunker.py
@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 / docker.yml
Created February 25, 2016 08:10
Ansible playbook to install docker toolbox on Ubuntu 14.04
---
- hosts: localhost
tasks:
- name: Update apt
apt:
update_cache: yes
become: yes
become_user: root
become_method: sudo
@toast38coza
toast38coza / http_status.py
Last active April 2, 2018 11:13
HTTP status codes as a dict. Source: https://httpstatuses.com/
STATUS_CODES = {
100: "100 Continue",
101: "101 Switching Protocols",
102: "102 Processing",
200: "200 OK",
201: "201 Created",
202: "202 Accepted",
203: "203 Non-authoritative Information",
204: "204 No Content",
@toast38coza
toast38coza / docker-compose-postgres.yml
Last active January 6, 2018 21:44
Docker-compose files for Kong
version: "2"
services:
postgres:
image: postgres:9.4
container_name: kong-database
ports:
- "5432:5432"
environment:
- POSTGRES_USER=kong
@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
}