Skip to content

Instantly share code, notes, and snippets.

View maxbeutel's full-sized avatar

Max maxbeutel

View GitHub Profile
<?php
date_default_timezone_set('Europe/Berlin');
$dayList = array(
new DateTime('2012-03-01'),
new DateTime('2012-03-02'),
new DateTime('2012-03-03'),
new DateTime('2012-03-04'),
new DateTime('2012-03-05'),
@maxbeutel
maxbeutel / mkdir.sh
Last active August 29, 2015 14:25
php recursive mkdir permissions gone wrong
$ rm -rf /tmp/foo
$ rm -rf /tmp/quo
$ mkdir -p -m 777 /tmp/quo/quox/quark
$ php -r 'mkdir("/tmp/foo/bar/baz/bang", 0777, true);'
$ stat -c "%a %n" /tmp/quo/quox/quark
777 /tmp/quo/quox/quark
$ stat -c "%a %n" /tmp/foo/bar/baz/bang
755 /tmp/foo/bar/baz/bang
$ stat -c "%a %n" /tmp/quo
755 /tmp/quo
@maxbeutel
maxbeutel / .emacs
Last active January 31, 2016 03:39
My humble .emacs configuration file
;; moved to https://github.com/maxbeutel/my-emacs-config
@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
*/
@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 / 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
g++ main.cpp -I./external/include -I./hazelcast/include -I./hazelcast/generated-sources/include ./build/libHazelcastClient3.7-SNAPSHOT_64.a
@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;
}
@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 / 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 };