Skip to content

Instantly share code, notes, and snippets.

View nvie's full-sized avatar
🍀
Simplifying things

Vincent Driessen nvie

🍀
Simplifying things
View GitHub Profile
@nvie
nvie / gzip_middleware.py
Created May 22, 2012 15:11
A WSGI middleware wrapper to add gzip to your WSGI app
from gzip import GzipFile
from wsgiref.headers import Headers
import re
import cStringIO as StringIO
# Precompile the regex to check for gzip headers
re_accepts_gzip = re.compile(r'\bgzip\b')
# Precompile the regex to split a comma delimitered string of Vary headers
@nvie
nvie / new_workers.py
Created August 30, 2012 21:22
Initial experiment with a possible new worker structure for RQ
from gevent import monkey
monkey.patch_all()
import gevent.pool
import os
import random
import time
import datetime
from multiprocessing import Semaphore, Array
import { Suspense, useEffect, useState } from "react";
import type { ReactElement } from "react";
type Props = {
fallback: ReactElement;
children: () => ReactElement;
};
/**
* Almost like a normal <Suspense> component, except that for server-side
import { Decoder, object, string } from 'decoders';
type Example = {
eg: string;
};
const exampleDecoder: Decoder<Example> = object({
eg: string
});
export type Range = [number, number]
type Position = {
offset: number
line: number
column: number
}
export type Location = {
start: Position
@nvie
nvie / codegen.fish
Created September 13, 2019 07:52
Fish completion for codegen
# Put the following in your ~/.config/fish/completions directory
complete --command codegen --no-files --arguments "(codegen -l)"
@nvie
nvie / .bashrc
Created December 17, 2009 09:15 — forked from henrik/.bashrc
# http://henrik.nyh.se/2008/12/git-dirty-prompt
# http://www.simplisticcomplexity.com/2008/03/13/show-your-git-branch-name-in-your-prompt/
# username@Machine ~/dev/dir[master]$ # clean working directory
# username@Machine ~/dev/dir[master*]$ # dirty working directory
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
@nvie
nvie / problem.py
Last active May 15, 2018 06:41
I'm stuck with this problem for a long time now and could really use the help of a gevent expert. Anybody? Please? Please read the comment on top of the file for a description. This is a minimal example that showcases my problem.
"""
Theres a gevent pool of 4 greenlets. Jobs are spawned continuously, blocking
until a free greenlet is available (default gevent.pool behaviour). Say,
a unit of work takes rougly a second. Then, at any moment, there are likely
4 jobs mid-execution.
The Goal
--------
I want to catch both SIGINT/KeyboardInterrupt _and_ SIGTERM in
the main loop, and in a nondestructive way. By nondestructive, I mean (1)
@nvie
nvie / worker_poll.py
Last active April 27, 2018 12:53
Which API is the nicest for the new RQ with concurrency?
# Alt 1: very explicit, but requires knowledge on what type of workers exist
from rq.workers.gevent import GeventWorker
w = GeventWorker(4)
# Alt 2: A bit like an "Abstract Factory", no need for knowing the implementing
# class names, backward compatible, and kind='forking' by default
from rq import Worker
w = Worker(4, kind='gevent')
# Alt 3: I don't think (2) works without really nasty tricks. This one is as
[submodule "vim/bundle/vim-characterize"]
path = vim/pack/nvie/start/vim-characterize
url = https://github.com/tpope/vim-characterize.git