Skip to content

Instantly share code, notes, and snippets.

View cdwfs's full-sized avatar

Cort cdwfs

View GitHub Profile
@cdwfs
cdwfs / retval_check.h
Created July 18, 2014 23:30
Return value error-checking macro generator
/**
* Handy meta-macro to simplify repetitive error checking for APIs where every function returns
* an error code (e.g. CUDA, C11 threads, most of the Windows API, etc.)
*
* Example usage:
* #define CUDA_CHECK(expr) RETVAL_CHECK(cudaSuccess, expr)
* ...
* CUDA_CHECK( cudaMemcpy(dst, src, size, cudaMemcpyHostToDevice) );
*
* To disable the checks in release builds, just redefine the macro:
@cdwfs
cdwfs / track_followers.py
Last active February 9, 2024 22:47
Python script to track changes to a user's list of Twitter followers
#!/usr/bin/env python
# Usage:
# 1) Install the Python Twitter Tools (PTT) from http://mike.verdone.ca/twitter/
# (or just "easy_install twitter").
# 2) Run "twitter-follow -o blahblahblah" and follow the instructions to set up
# OAuth. This gives the twitter-follow script read-only access to your account.
# Technically, it doesn't even need to be *your* account that you authorize,
# since the script is only querying public follower information.
# 3) Modify the value of "my_handle" to the username of the Twitter user whose
@cdwfs
cdwfs / http_server.py
Last active February 16, 2018 21:36
Python script to run an HTTP server that only accepts connections from localhost. Primarily intended as a workaround for cross-origin requests preventing you from loading local assets in your local JS scripts.
import argparse
import os
import os.path
import sys
parser = argparse.ArgumentParser()
parser.add_argument("-p", "--port", type=int, help="Port to open for HTTP connections", default=80)
parser.add_argument("-d", "--dir", help="Root directory to serve", default=".")
args = parser.parse_args()