Skip to content

Instantly share code, notes, and snippets.

View krsmedlund's full-sized avatar

Kristoffer Smedlund krsmedlund

View GitHub Profile
@krsmedlund
krsmedlund / scoped_method_rate_throttle.py
Last active March 22, 2022 17:26
ScopedRateThrottle per HTTP method.
class ScopedMethodRateThrottle(ScopedRateThrottle):
"""
If you need to set different throttles per different http method on the same view.
# Usage
## views.py
class MyView(SomeAPIView):
throttle_classes = [ScopedMethodRateThrottle,]
@krsmedlund
krsmedlund / _output
Last active December 31, 2019 12:23
Quick and dirty django async background tasks to run after request is done.
$ uvicorn test.asgi:application
INFO Started server process
INFO Uvicorn running
INFO Application startup complete.
INFO 127.0.0.1:54844 - "GET / HTTP/1.1" 200
Request done at 2019-12-11 19:13:01.500296
Sleepy woke at 2019-12-11 19:13:06.506096
@krsmedlund
krsmedlund / vimrc
Last active December 21, 2015 22:29
set nocompatible
set t_Co=256
set lazyredraw
set wildmode=list:longest
set nobackup
set nowritebackup
set noswapfile
set background=dark
set showcmd
GLint nUniforms, nAttributes;
GLchar* label = new GLchar[128];
GLenum type;
GLsizei length(0);
GLint size(0);
glGetProgramiv(m_programId, GL_ACTIVE_UNIFORMS, &nUniforms);
std::cout << "\tActive uniforms ("<< yellow << nUniforms << "): ";
Application
id: "testApp"
Area
id: "appArea"
class: "row"
state: "page1"
states:
page1: State
from compressor.filters import CompilerFilter
class CoffeeCompilerFinder(staticfiles.finders.AppDirectoriesFinder):
"""
A quick hacked up staticfiles-finder that will automatically recompile .coffee files to .js and serve the .js file
It will respond to a request for /foo/bar/baz.js and if the coffee-file with the same name in that same dir is newer then
then js-file requested then the js-file will be recompiled.
I did this to not have to manually recompile my scripts or use the watcher and still be compatible with require.js
without have to change the code once i deploy with compiled js-files. it depends on django-compressor at the moment
but if you dont use that its just a small class to lift out from it.
def update_stuff(request, pk):
instance = get_object_or_404(PCB, pk=pk)
if request.method in ('POST', 'PUT'):
form = FormClass(data=request.POST, files=reuqest.FILES, instance=instance)
if form.is_valid():
form.save()
...
else:
form = FormClass(instance=instance)
render_to_response({'form':form}, ...)