Skip to content

Instantly share code, notes, and snippets.

View maxbeutel's full-sized avatar

Max maxbeutel

View GitHub Profile
@maxbeutel
maxbeutel / hough_transform_xy_coords.rs
Created November 23, 2016 08:20
Hough Transform - back to x/y coordinates
let accumulator_threshold = 2; // Hardcoded value for our simple example how many votes a combination of rho/theta must have
// before we consider it as a line
for theta in 0..houghspace_img_width {
for rho in 0..houghspace_img_height {
let accumulator_value = accumulator[(theta as usize, rho as usize)];
if accumulator_value < accumulator_threshold {
continue;
}
@maxbeutel
maxbeutel / hough_transform_voting.rs
Last active November 23, 2016 08:21
Hough Transform - Voting
// calculate the longest line that can occur in the image (hypotenuse)
let max_line_length = (img_width as f64).hypot(img_height as f64).ceil();
// Create the accumulator matrix, x-axis is angle theta, y-axis is distance rho
let mut accumulator: na::DMatrix<u64> = na::DMatrix::new_zeros(180, max_line_length as usize);
// Flip y axis when reading image, as the image has 0/0 at the top left,
// but it's easier for us to work with when the origin 0/0 is at the bottom left
for y in 0..img_height {
for x in 0..img_width {
@maxbeutel
maxbeutel / hough_transform_accumulator.rs
Last active November 23, 2016 08:17
Hough Transform - create accumulator
let max_line_length = (img_width as f64).hypot(img_height as f64).ceil();
let mut accumulator: na::DMatrix<u64> = na::DMatrix::new_zeros(180, max_line_length as usize);
@maxbeutel
maxbeutel / draw_line.rs
Created November 23, 2016 03:36
Generic function to draw a line using Rust Piston::image crate
// based on http://stackoverflow.com/a/34722500
fn draw_line<T: GenericImage>(img: &mut T, x0: i64, y0: i64, x1: i64, y1: i64, pixel: T::Pixel) {
// Create local variables for moving start point
let mut x0 = x0;
let mut y0 = y0;
// Get absolute x/y offset
let dx = if x0 > x1 { x0 - x1 } else { x1 - x0 };
let dy = if y0 > y1 { y0 - y1 } else { y1 - y0 };
@maxbeutel
maxbeutel / gist:dc4e11373699e53084c92a1acc959daa
Created November 7, 2016 06:12
Emacs - prevent paredit from inserting space before [ { ( in some modes
(defun my-at-expression-paredit-space-for-delimiter-predicate (endp delimiter)
(if (and (member major-mode '(php-mode rust-mode c-mode))
(not endp))
(not (or (and (memq delimiter '(?\[ ?\{ ?\()))))
t))
(add-hook 'paredit-space-for-delimiter-predicates
#'my-at-expression-paredit-space-for-delimiter-predicate)
@maxbeutel
maxbeutel / dedup_by.rs
Created November 7, 2016 06:10
Backport of Vec::dedup_by
// backporting of "Vec::dedup_by" and "Vec::dedup_by_key"
// https://github.com/rust-lang/rust/pull/36743
use std::mem;
trait DedupedVec<T> {
fn dedup_by_key<F, K>(&mut self, mut key: F) where F: FnMut(&mut T) -> K, K: PartialEq;
fn dedup_by<F>(&mut self, mut same_bucket: F) where F: FnMut(&mut T, &mut T) -> bool;
}
g++ main.cpp -I./external/include -I./hazelcast/include -I./hazelcast/generated-sources/include ./build/libHazelcastClient3.7-SNAPSHOT_64.a
@maxbeutel
maxbeutel / memcache_grep
Created March 21, 2016 02:38 — forked from kganser/memcache_grep
Grep for a key in memcache
#!/bin/bash
host=$1
port=${PORT:-11211}
grepfor=$2
echo -e "stats items\nquit" | nc $host $port | cut -d: -f2 | sort -n | uniq | grep -v END | while read i; do echo -e "stats cachedump $i 100000\nquit" | nc $host $port | grep $grepfor; done
@maxbeutel
maxbeutel / Makefile
Last active May 5, 2016 01:23
somewhat clean C makefile with dependencies
### mostly stolen from http://eigenstate.org/notes/makefiles
CC = clang
SHELL = /bin/bash
CFLAGS += -std=c11 -pedantic -Werror -Wall -Wextra -Isrc
DEV_CFLAGS = -O0 -ggdb
SOURCES=$(wildcard src/**/*.c src/*.c)
LIBOBJ=$(patsubst %.c,%.o,$(SOURCES))
@maxbeutel
maxbeutel / UnusedUseSniff.php
Last active November 19, 2015 08:42
Unused use php codesniffer rule, adapted for phpcs2
<?php
use PHP_CodeSniffer_File as CodeSnifferFile;
use PHP_CodeSniffer_Sniff as CodeSnifferSniff;
/**
* Code originally from https://github.com/InterNations/kodierungsregelwerksammlung/blob/master/src/InterNations/Sniffs/Waste/SuperfluousUseStatementsSniff.php
*
* Slightly modified to be compatible with phpcs2, because original sniff from InterNations was not compatible with phpcs2
* because of changes in how phpcs parses doc comment blocks: https://www.squizlabs.com/php-codesniffer/2.0.0a1-released
*/