Skip to content

Instantly share code, notes, and snippets.

View bhoung's full-sized avatar

Brendan Houng bhoung

View GitHub Profile
@rduplain
rduplain / app.py
Created January 19, 2012 17:28
Plot a PNG using matplotlib in a web request, using Flask.
"Plot a PNG using matplotlib in a web request, using Flask."
# Install dependencies, preferably in a virtualenv:
#
# pip install flask matplotlib
#
# Run the development server:
#
# python app.py
#
@quiver
quiver / README.md
Last active April 3, 2024 15:47
Who says PostgreSQL can't Pub/Sub like Redis?

Pub/Sub pattern with PostgreSQL's LISTEN/NOTIFY command

This is a simple chat-like program using pub-sub pattern, backed by PostgreSQL's LISTEN/NOTIFY command.

Publish

publish message to foo channel from user nickname.

$ python pub.py foo nickname
PUBLISH to channel #foo
@chanks
chanks / gist:7585810
Last active February 29, 2024 03:50
Turning PostgreSQL into a queue serving 10,000 jobs per second

Turning PostgreSQL into a queue serving 10,000 jobs per second

RDBMS-based job queues have been criticized recently for being unable to handle heavy loads. And they deserve it, to some extent, because the queries used to safely lock a job have been pretty hairy. SELECT FOR UPDATE followed by an UPDATE works fine at first, but then you add more workers, and each is trying to SELECT FOR UPDATE the same row (and maybe throwing NOWAIT in there, then catching the errors and retrying), and things slow down.

On top of that, they have to actually update the row to mark it as locked, so the rest of your workers are sitting there waiting while one of them propagates its lock to disk (and the disks of however many servers you're replicating to). QueueClassic got some mileage out of the novel idea of randomly picking a row near the front of the queue to lock, but I can't still seem to get more than an an extra few hundred jobs per second out of it under heavy load.

So, many developers have started going straight t

@dtheodor
dtheodor / listen_pg.py
Created December 18, 2014 21:30
Listen for pg_notify with Psycopg2
import select
import datetime
import psycopg2
import psycopg2.extensions
conn = psycopg2.connect(database="postgres", user="vagrant")
#conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
curs = conn.cursor()
@jexp
jexp / fetch_tree.adoc
Created June 19, 2015 22:09
Fetch a Tree with Neo4j

Fetch a Tree with Neo4j

Today I came across a really interesting StackOverflow question:

Given a forest of trees in a Neo4j REST server, I`m trying to return a single tree given the root vertex. Being each tree quite large, I need a de-duplicated list of all vertices and edges in order to be able to reconstruct the full tree on the client side.

@seanhess
seanhess / Test.hs
Created July 8, 2015 18:27
Haskell Servant ReaderT ExceptT newtype monad transformer stack
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Serials.Route.Test where
import Control.Monad.Trans (lift)
import Control.Monad.Trans.Either
Example: https://denpa.moe/~syrup/himawari8.png
@stefanbuck
stefanbuck / upload-github-release-asset.sh
Last active November 26, 2023 12:40
Script to upload a release asset using the GitHub API v3.
#!/usr/bin/env bash
#
# Author: Stefan Buck
# License: MIT
# https://gist.github.com/stefanbuck/ce788fee19ab6eb0b4447a85fc99f447
#
#
# This script accepts the following parameters:
#
# * owner
@michaelwebb76
michaelwebb76 / Technical Test Instructions.md
Last active February 23, 2023 23:23
Technical Test Instructions

WELCOME

We're stoked you've chosen to join us. If you're successful, you'll be joining a team that is focused on technical excellence and continuous improvement. We take great care to produce well-structured, well-tested, maintainable code. To be successful, you'll need to demonstrate that you do as well.

Our expectations are that this exercise should take you no longer than 4 hours to complete (and hopefully much less). If it takes you much longer than that to get to a working solution, you might not be the right candidate for this role.

INSTRUCTIONS

  1. Complete the short version of the Big 5 test and save your results as text.
  2. Create a new git repository for your code.
  3. Write a utility that parses the textual results of your test into the following format. Note that you'll need to include your email, which doesn't appear in the output of your Big 5 test. Feel free to use intermediary data structures and useful libraries.
@antirez
antirez / lmdb.tcl
Created April 28, 2017 15:40
LMDB -- First version of Redis written in Tcl
# LVDB - LLOOGG Memory DB
# Copyriht (C) 2009 Salvatore Sanfilippo <antirez@gmail.com>
# All Rights Reserved
# TODO
# - cron with cleanup of timedout clients, automatic dump
# - the dump should use array startsearch to write it line by line
# and may just use gets to read element by element and load the whole state.
# - 'help','stopserver','saveandstopserver','save','load','reset','keys' commands.
# - ttl with milliseconds resolution 'ttl a 1000'. Check ttl in dump!