Skip to content

Instantly share code, notes, and snippets.

View dcoles's full-sized avatar

David Coles dcoles

View GitHub Profile
@dcoles
dcoles / producer_consumer.py
Created September 15, 2018 19:24
Coroutines in Python
"""Producer/Consumer coroutines."""
import asyncio
q = asyncio.Queue(7)
def reader(iterable):
"""Producer."""
it = iter(iterable)
while True:
@dcoles
dcoles / lua_coroutines.py
Last active September 16, 2018 00:59
Lua-style coroutines
"""
Lua-style coroutines.
Examples taken from https://www.lua.org/pil/9.html.
"""
import types
class Coroutine:
@dcoles
dcoles / coroutine_pipeline.py
Created September 16, 2018 01:02
Coroutine pipeline
"""
Coroutine pipeline.
Based off https://www.lua.org/pil/9.2.html.
"""
import types
if __name__ == '__main__':
@dcoles
dcoles / greeter_server_fork_exec.py
Last active November 4, 2018 01:02
gRPC server fork (causes "Failed accept4: Invalid argument" on Python 3.6)
# Copyright 2015 gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
/*
Based on demo_userns.c by Michael Kerrisk
Copyright 2013, Michael Kerrisk
Licensed under GNU General Public License v2 or later
*/
#define _GNU_SOURCE
#include <sys/wait.h>
#include <sys/sysmacros.h>
#include <sys/mount.h>
@dcoles
dcoles / minijail-9-makefile.patch
Last active June 18, 2019 23:13
minijail ebuild
diff --git a/Makefile b/Makefile
index 54ee978..a50ee9a 100644
--- a/Makefile
+++ b/Makefile
@@ -46,8 +46,8 @@ ifeq ($(USE_SYSTEM_GTEST),no)
GTEST_CXXFLAGS := -std=gnu++14
GTEST_LIBS := gtest.a
else
-GTEST_CXXFLAGS := $(shell gtest-config --cxxflags)
-GTEST_LIBS := $(shell gtest-config --libs)
@dcoles
dcoles / list.libsonnet
Created June 17, 2019 07:19
List implementation in Jsonnet
{
head(list)::
if list == [] then
error 'Can not take head of empty list'
else
list[0],
tail(list)::
if list == [] then
error 'Can not take tail of empty list'
@dcoles
dcoles / nginx-build.sh
Created July 16, 2019 01:24
Nginx out-of-tree build
#!/bin/bash
# Helper script for development build of Nginx
set -e
NGINX_SRC=/home/dcoles/src/nginx
BASEDIR="$(dirname "$(realpath "$0")")"
cd "${BASEDIR}"
mkdir -p build
@dcoles
dcoles / halloween.py
Created July 17, 2019 00:44
Halloween for Phillips Hue
# Copyright 2013-2018 Sony Interactive Entertainment LLC
import asyncio
import random
from phue import Bridge
b = Bridge('10.128.12.96')
BEDSIDE = b.lights[0]
@dcoles
dcoles / windows-nfc.py
Created September 7, 2019 06:06
Example of NFC using Windows Proximity class
"""
Example of NFC using Windows Proximity class.
Tested using Sony RC-S380 (make sure you enable NFP in the driver).
Requires Windows 10 and Python 3.7+ (for WinRT/Python).
"""
import sys
import time