Skip to content

Instantly share code, notes, and snippets.

Avatar

David Coles dcoles

View GitHub Profile
@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
@dcoles
dcoles / windows-nfs.rs
Created Sep 7, 2019
Example of NFC using Windows Proximity APIs in Rust
View windows-nfs.rs
// Example of NFC using Windows Proximity APIs
// Tested using Sony RC-S380 (make sure you enable NFP in the driver).
use winrt::*; // import various helper types
use winrt::windows::foundation;
use winrt::windows::networking::proximity;
use std::{thread, time};
const URL: &str = "https://dcoles.net";
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 / appimage.sh
Last active Feb 23, 2020
Run AppImage container
View appimage.sh
#!/bin/bash
# Run AppImage container
set -e
function _mount {
local target
target="$(mktemp --tmpdir --directory appimage.XXXXXXXXXX)"
/bin/mount --types squashfs -o offset="${2:-0}" --read-only -- "${1}" "${target}"
echo "${target}"
}
@dcoles
dcoles / windows-nfc.py
Created Sep 7, 2019
Example of NFC using Windows Proximity class
View windows-nfc.py
"""
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
@dcoles
dcoles / halloween.py
Created Jul 17, 2019
Halloween for Phillips Hue
View halloween.py
# 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 / nginx-build.sh
Created Jul 16, 2019
Nginx out-of-tree build
View nginx-build.sh
#!/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
View minijail-9-makefile.patch
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 Jun 17, 2019
List implementation in Jsonnet
View list.libsonnet
{
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 / alarmtimer.py
Created Mar 20, 2012
POSIX Alarm Timers example using Python ctypes
View alarmtimer.py
#!/usr/bin/env python
# POSIX Alarm Timer example using Python ctypes
#
# Author: David Coles <coles.david@gmail.com>
# Date: 2012-03-19
#
# To the extent possible under law, the author(s) have dedicated all copyright
# and related and neighboring rights to this software to the public domain
# worldwide. This software is distributed without any warranty.