Skip to content

Instantly share code, notes, and snippets.

Avatar

David Coles dcoles

View GitHub Profile
@dcoles
dcoles / lua_coroutines.py
Last active Sep 16, 2018
Lua-style coroutines
View lua_coroutines.py
"""
Lua-style coroutines.
Examples taken from https://www.lua.org/pil/9.html.
"""
import types
class Coroutine:
@dcoles
dcoles / producer_consumer.py
Created Sep 15, 2018
Coroutines in Python
View producer_consumer.py
"""Producer/Consumer coroutines."""
import asyncio
q = asyncio.Queue(7)
def reader(iterable):
"""Producer."""
it = iter(iterable)
while True:
@dcoles
dcoles / proxy.go
Created Sep 9, 2018
HTTP Proxy in Go
View proxy.go
package main
import (
"bufio"
"fmt"
"io"
"log"
"net"
"net/http"
)
View tee.c
/**
* Print size and contents of a PIPE
* Author: David Coles <coles.david@gmail.com>
*/
#define _GNU_SOURCE
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
View fifo_size.py
# Print the number of bytes unread in a fifo.
# David Coles <coles.david@gmail.com>
import argparse
import ctypes
import fcntl
import os
import sys
import termios
View designer.html
<link rel="import" href="../core-scaffold/core-scaffold.html">
<link rel="import" href="../core-header-panel/core-header-panel.html">
<link rel="import" href="../core-menu/core-menu.html">
<link rel="import" href="../core-item/core-item.html">
<link rel="import" href="../core-icon-button/core-icon-button.html">
<link rel="import" href="../core-toolbar/core-toolbar.html">
<link rel="import" href="../core-menu/core-submenu.html">
<link rel="import" href="../google-map/google-map.html">
<polymer-element name="my-element">
View build_arsmagicka.sh
#!/bin/bash
set -e
MINECRAFT_SERVER=minecraft_server.jar
MINECRAFT_SERVER_ARS=minecraft_server_ars.jar
FORGE=minecraftforge-universal-1.4.5-6.4.1.410.zip
ARS=ArsMagica_Open_Beta_RC_4.62.113
View xinput.py
# Simple Wrapper around XInput API
#
# Author: David Coles <coles.david@gmail.com>
import ctypes
from ctypes.wintypes import BYTE, WORD, SHORT, DWORD
class XInputGamepad(ctypes.Structure):
_fields_ = [
@dcoles
dcoles / inline.py
Created Nov 14, 2012
Inline assembly in Python
View inline.py
import ctypes
import sys
import os
import errno
FUNC = ctypes.CFUNCTYPE(None)
PROT_NONE = 0
PROT_READ = 1
PROT_WRITE = 2
View Main.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
/**
* @param args the command line arguments
*/