Skip to content

Instantly share code, notes, and snippets.

View tochimclaren's full-sized avatar
🏠
Working from home

tochimclaren tochimclaren

🏠
Working from home
View GitHub Profile
@tochimclaren
tochimclaren / !README-javascript-audio.md
Created September 20, 2024 23:13 — forked from tatsuyasusukida/!README-javascript-audio.md
🎵 How to record audio using the Web Audio API in JavaScript

🎵 How to record audio using the Web Audio API in JavaScript

Demo video: How to record audio using the Web Audio API in JavaScript

About this article

This article describes how to record audio using the Web Audio API in JavaScript. The related resources are shown below.

@tochimclaren
tochimclaren / ftp_download.py
Created November 27, 2023 03:41 — forked from jcollado/ftp_download.py
ftp upload and download scripts [python, ftplib]
#!/usr/bin/env python
"""Download a file from ftp server."""
import argparse
import logging
import os
from ftplib import FTP_TLS
@tochimclaren
tochimclaren / admin_list_editable_autosubmit.js
Created January 1, 2021 09:15 — forked from magopian/admin_list_editable_autosubmit.js
Small js script that automatically submits the changelist form on field changes. This is convenient when used with https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_editable, and avoids having to remember to submit the form when done (the form on the changelist page doesn't look like a form after all, …
/*
* Only useful in changelist pages when the ModelAdmin displayed has
* "list_editable" (https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_editable)
* configured.
*
* When one of the input/select/textarea value is changed, automatically submit
* the form using ajax.
*
* Only form fields relevant to the "list_editable" will trigger a form submit.
*
@tochimclaren
tochimclaren / celery.sh
Created December 30, 2020 00:12 — forked from amatellanes/celery.sh
Celery handy commands
/* Useful celery config.
app = Celery('tasks',
broker='redis://localhost:6379',
backend='redis://localhost:6379')
app.conf.update(
CELERY_TASK_RESULT_EXPIRES=3600,
CELERY_QUEUES=(
Queue('default', routing_key='tasks.#'),
@tochimclaren
tochimclaren / celery.py
Created December 24, 2020 21:39 — forked from pgrangeiro/celery.py
Django Celery Beat Example
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
from django.conf import settings
from robot.config import ROBOT_CELERY_BEAT_SCHEDULE
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'test.settings')
@tochimclaren
tochimclaren / admin.py
Created September 13, 2020 15:22 — forked from sanbartels/admin.py
Limit number of Django model instances
from django.contrib import admin
from example.models import Example
class ExampleAdmin(admin.ModelAdmin):
"""
Don't allow addition of more than one model instance in Django admin
See: http://stackoverflow.com/a/12469482
"""
def has_add_permission(self, request):
@tochimclaren
tochimclaren / DJANGO_get_next_or_prev
Created April 26, 2020 04:53 — forked from kvnn/DJANGO_get_next_or_prev
Django: Get next or previous item of a Queryset
''' Useage ''''
# Declare our item
store = Store.objects.get(pk=pk)
# Define our models
stores = Store.objects.all()
# Ask for the next item
new_store = get_next_or_prev(stores, store, 'next')
# If there is a next item
if new_store:
# Replace our item with the next one
@tochimclaren
tochimclaren / slugify.py
Created August 31, 2019 18:26
Django Unique Slug Generator
import random
import string
from django.utils.text import slugify
def random_string_generator(size=10, chars=string.ascii_lowercase + string.digits):
return ''.join(random.choice(chars) for _ in range(size))
def unique_slug_generator(instance, new_slug=None):
if new_slug is not None:
slug = new_slug
@tochimclaren
tochimclaren / validators.py
Created August 6, 2019 14:46 — forked from emilio-rst/validators.py
Django validate image dimensions
# coding: utf-8
from django.core.exceptions import ValidationError
from django.core.files.images import get_image_dimensions
from django.utils.translation import ugettext_lazy as _
from django.utils.deconstruct import deconstructible
@deconstructible
class ImageDimensionsValidator: