Skip to content

Instantly share code, notes, and snippets.

@rgov
rgov / gist:3641765
Created September 5, 2012 18:17
Using ToT libclang from Python
import os, sys
import subprocess
import ctypes, ctypes.util
llvmconfig = '/Users/rzg/Projects/llvm/build/Release+Asserts/bin/llvm-config'
def getllvmconfig(flag):
return subprocess.check_output([ llvmconfig, '--' + flag ]).rstrip()
# Patch ctypes.cdll.LoadLibrary to respect search paths.
real_LoadLibrary = ctypes.cdll.LoadLibrary
@rgov
rgov / gist:4554315
Created January 17, 2013 07:25
Patch to socat-1.7.2.1 to prevent a conflict with stdbool.h
diff --git a/mytypes.h b/mytypes.h
index f625314..143fabf 100644
--- a/mytypes.h
+++ b/mytypes.h
@@ -7,7 +7,9 @@
/* some types and macros I miss in C89 */
+#ifndef __bool_true_false_are_defined
typedef enum { false, true } bool;
import subprocess, tempfile
def which(name):
w = subprocess.Popen([ '/usr/bin/which', name ], stdout=subprocess.PIPE)
stdout, _ = w.communicate()
return stdout.rstrip()
class Tor(object):
'''
@rgov
rgov / gist:4751973
Created February 11, 2013 02:04
Installing Windows
@rgov
rgov / gist:5033600
Last active December 14, 2015 05:09
; http://rise4fun.com/Z3/empty?frame=1&menu=0
(set-logic QF_BV)
(set-info :smt-lib-version 2.0)
(declare-fun c0 () (_ BitVec 32))
(declare-fun c1 () (_ BitVec 32))
(declare-fun c2 () (_ BitVec 32))
(declare-fun c3 () (_ BitVec 32))
(declare-fun c4 () (_ BitVec 32))
(declare-fun c5 () (_ BitVec 32))
(declare-fun c6 () (_ BitVec 32))
@rgov
rgov / gist:5079983
Last active December 14, 2015 11:38

The following blog post appeared on my personal website on January 7, 2007 with the title "Senseless Web Filtering." A week or so later I received this letter from the school:


My school uses Websense to filter students' Web access. The network administrator has restricted a handful of categories, including "Freeware and Software Downloads," "Tasteless," "Shopping," among dozens others. All outgoing page requests are checked against Websense's master database, and the connection is denied if the URL shows up in one of the restricted categories.

I am frequently prevented from accessing a legitimate page that is blocked for questionable reasons. Examples include KrazyDad, blocked for his amazing mathematical screensavers, and Kotaku, blocked under the broad category of "Games." In the case

@rgov
rgov / dawg.py
Last active December 15, 2015 15:39
Generates a directed acyclic word graph for efficient membership testing for a word list.
#!/usr/bin/env python
'''
An implementation of "Incremental Construction of Minimal Acyclic Finite-State
Automata" by J. Daciuk, et al.
Data structures also inspired by "The World's Fastest Scrabble Program" by
A. W. Appel & G. J. Jacobson.
Ryan Govostes, 1 April 2013
'''
@rgov
rgov / gist:5415912
Created April 18, 2013 20:22
Building a curve for @mdznr
Let's widen the circle to have a radius of 1.
Solve x^2 + (y - 1)^2 = 1, you get
y = 1 +/- Sqrt[1 - x^2]
Focus on the bottom-right part of the circle first, from x = 0 to 1:
y = 1 - Sqrt[1 - x^2]
Let's make the right half of this curve repeat. Instead of using x, we'll use
@rgov
rgov / twintersect.py
Last active December 16, 2015 19:49
Hastily-written set intersection of a Twitter user's followed and follower lists.
#!/usr/bin/env python
# Uses the python twitter tools library: http://mike.verdone.ca/twitter/
from twitter import *
import os, sys, time
# Hm what is this? https://gist.github.com/rhenium/3878505
CONSUMER_KEY = ''
CONSUMER_SECRET = ''
cat <<EOF | openssl base64 -d | clang -o /dev/null -x c -
IyAxICIbWzJKG1tIG1swbRtbOG1zZ3JrdRtbMjhtG1s1RCsbWzhtYmh3dHIbWzI4
bRtbNUQtG1s4bW90ZmJ2G1syOG0bWzVELRtbOG1uY3BnbxtbMjhtG1s1RC0bWzht
b2F1cG4bWzI4bRtbNUQtG1s4bWx5bXJsG1syOG0bWzVELRtbOG1kcGpmbBtbMjht
G1s1RC0bWzhtbHlsbGYbWzI4bRtbNUQtG1s4bW1ybGR3G1syOG0bWzVELRtbOG1u
ZmpxZhtbMjhtG1s1RC0bWzhtenVhc3obWzI4bRtbNUQtG1s4bXp6eG9qG1syOG0b
WzVELRtbOG1nb3lzahtbMjhtG1s1RC0bWzhtdmlyd3MbWzI4bRtbNUQtG1s4bWNo
emdiG1syOG0bWzVELRtbOG13dmN3dhtbMjhtG1s1RC0bWzhtemNjbnIbWzI4bRtb
NUQtG1s4bXB6YWlpG1syOG0bWzVELRtbOG1qa3N2ZRtbMjhtG1s1RC0bWzhtbGFh
bGobWzI4bRtbNUQtG1s4bWV5aHNmG1syOG0bWzVELRtbOG1ramN3aBtbMjhtG1s1