Skip to content

Instantly share code, notes, and snippets.

View adamserafini's full-sized avatar
🦩
Flamingo!

Adam Serafini adamserafini

🦩
Flamingo!
View GitHub Profile
@valsteen
valsteen / queue_processing.py
Last active November 27, 2022 10:41
Self-feeding task queue using python's asyncio
"""
This demonstrates a task scheduling loop where tasks can send back other tasks to the queue.
Program input: a nested list of items that can either be integers, whose processing is simulated by waiting
a proportional amount of time, or another list, in which case after waiting a time proportional to its length,
sub-items are rescheduled for processing.
Solution is inspired by goroutines, channels and waitgroups.
Asyncio's Queue can serve both as channel and waitgroup, thanks to Queue.join() that blocks until the queue is empty.
@valsteen
valsteen / concurrency_limit.py
Last active July 25, 2022 09:48
How to limit concurrency with Python asyncio?
import asyncio
from typing import Awaitable, Callable, Coroutine, Iterator
from asyncio_pool import AioPool
import pytest as pytest
from more_itertools import peekable
"""
Different approaches to "How to limit concurrency with Python asyncio?"
https://stackoverflow.com/questions/48483348/how-to-limit-concurrency-with-python-asyncio/48484593#48484593
@snehesht
snehesht / Concurrent HTTP Requests with Python3 and asyncio
Last active October 20, 2020 19:00
Concurrent HTTP Requests with Python3 and asyncio
#http://geekgirl.io/concurrent-http-requests-with-python3-and-asyncio/
Concurrent HTTP Requests with Python3 and asyncio
My friend who is a data scientist had wipped up a script that made lots (over 27K) of queries to the Google Places API. The problem was that it was synchronous and thus took over 2.5hours to complete.
Given that I'm currently attending Hacker School and get to spend all day working on any coding problems that interests me, I decided to go about trying to optimise it.
I'm new to Python so had to do a bit of groundwork first to determine which course of action was best.
@tclancy
tclancy / expire_all_sessions.py
Last active May 9, 2022 12:07 — forked from playpauseandstop/gist:1818351
Django management command to expire all sessions
import datetime
from django.conf import settings
from django.contrib.auth import logout
from django.contrib.auth.models import User
from django.contrib.sessions.models import Session
from django.core.management.base import NoArgsCommand
from django.http import HttpRequest
from django.utils.importlib import import_module
@pkulchenko
pkulchenko / js.lua
Created March 12, 2014 23:49
Simple JavaScript spec file for ZeroBrane Studio (put it in spec/folder)
-- author: Paul Kulchenko
---------------------------------------------------------
local funccall = "([A-Za-z_][A-Za-z0-9_]*)%s*"
return {
exts = {"js", "json"},
lexer = wxstc.wxSTC_LEX_ESCRIPT,
apitype = "js",
linecomment = "//",
@guyrt
guyrt / gist:5074374
Created March 3, 2013 03:34
Get all named url patterns in django
from django.core import urlresolvers
resolver = urlresolvers.get_resolver(None)
url_re_list = ['^/' + url[1] for url in resolver.reverse_dict.itervalues()]
@clintel
clintel / gist:1155906
Created August 19, 2011 02:40
Fenced code in bullet lists with GitHub-flavoured MarkDown??

Fenced code blocks inside ordered and unordered lists

  1. This is a numbered list.

  2. I'm going to include a fenced code block as part of this bullet:

    Code
    More Code