Skip to content

Instantly share code, notes, and snippets.

@campaul
campaul / tarnish.rs
Created December 11, 2015 01:52
Simple HTTP proxy in Rust.
/*
Simple HTTP proxy in Rust. Hard coded to proxy rust-lang.org.
*/
extern crate hyper;
use std::io::Read;
use hyper::Client;
use hyper::header::Connection;
@campaul
campaul / raw_develop.py
Last active May 1, 2018 10:48
Develop a RAW image by using ctypes to call libraw.
# This file was my first attempt at using libraw with ctypes. For a more
# complete project check out https://github.com/photoshell/rawkit
# Usage: python raw_develop.py some/raw/file.cr2 some/destination/file.ppm
from ctypes import *
import sys
libraw = cdll.LoadLibrary('libraw.so.10')
@campaul
campaul / iron_response_macro.rs
Created February 22, 2017 01:25
Simple response! macro for Iron with example.
extern crate iron;
use iron::prelude::*;
macro_rules! response {
( $( $x:expr ),* ) => {
{
Ok(Response::with(($(
$x,
)*)))
@campaul
campaul / unique.py
Created September 10, 2016 00:59
Generates unique filenames.
# Generates a new unique filename if the provided filename already exists,
# otherwise just return the provided filename.
# Usage: python unique.py name/of/file
import os
import sys
def increment(filename):
last = filename.split()[-1]
@campaul
campaul / otr-fingerprints
Last active December 19, 2015 12:19
OTR Fingerprints
456D7BC4 6B19C7A7 F2136C0C 24B43C27 85AB4C8D
EB67EE95 3DF5AEDA AB4D3C81 A784D0E7 98AF49A0
940AAD6D 130F674D 7C9C99B9 CA6C4CD7 35DC21DA
0B1FCE0E 61A29864 737DF8BD 47413821 94CFF83D
119A3473 7C31A5B9 E20A6024 5DA365D8 F360071A
@campaul
campaul / lru.js
Created December 19, 2012 06:50
A concise JavaScript LRU cache.
this.cache = (function() {
// Inserts a node into a circular double linked list
var insert = function(head, node) {
return (((node.prev = head.prev).next = node).next = head).prev = node;
};
// Removes a node from a circular double linked list
var remove = function(node) {
return ((node.prev.next = node.next).prev = node.prev) && node;
};
@campaul
campaul / color_picker.py
Created November 25, 2015 08:54
Samples a color from the screen and prints the hex value to the terminal.
# Samples a color from the screen and prints the hex value to the terminal.
# Usage: `python color_picker.py` and then click somewhere to sample.
from gi import require_version
require_version('Gdk', '3.0')
require_version('Gtk', '3.0')
from gi.repository import Gdk
from gi.repository import Gtk
@campaul
campaul / resume.tex
Last active October 2, 2015 23:37
LaTeX source for my resume.
\documentclass[margin, 11pt]{res}
\usepackage{enumitem}
\usepackage{setspace}
\setlength{\oddsidemargin}{-.125in}
\setlength{\topmargin}{-.125in}
\setlength{\textheight}{10in}
\begin{document}
@campaul
campaul / gtk_example.py
Last active August 29, 2015 14:27
Off main thread GTK example
# Inverted version of the first example from https://wiki.gnome.org/Projects/PyGObject/Threading
# GTK runs in the spawned thread instead of the other way around.
import threading
import time
from gi.repository import GLib, Gtk, GObject
# yay hacks
import mock
print(mock.MagickMock() == mock.ANY)
print(mock.ANY == mock.MagickMock())