Skip to content

Instantly share code, notes, and snippets.

@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')
import mock
print(mock.MagickMock() == mock.ANY)
print(mock.ANY == mock.MagickMock())
@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
@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 / 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 / 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 / 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,
)*)))