Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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())
@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 / mason_jar_port_tube.js
Last active August 29, 2015 14:17
Mason Jar Port Tube
function main() {
return union(
// The tube
difference(
cylinder({r:16, h:28, fn:100}),
cylinder({r:15, h:28, fn:100})
),
// The flange
difference(
cylinder({r:20, h:2, fn:100}),
@campaul
campaul / game.go
Created March 6, 2015 04:42
Centered player example
package main
import (
"fmt"
"github.com/nsf/termbox-go"
)
func tbPrint(x, y int, fg, bg termbox.Attribute, msg string) {
for _, c := range msg {
termbox.SetCell(x, y, c, fg, bg)
Python 3.4.2 (default, Jan 12 2015, 11:38:40)
[GCC 4.9.2 20141224 (prerelease)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> def foo(x=[]):
... x.append('1')
... return x
...
>>> foo()
['1']
>>> foo()