Skip to content

Instantly share code, notes, and snippets.

View clausecker's full-sized avatar

Robert Clausecker clausecker

View GitHub Profile
@clausecker
clausecker / paeth.diff
Created August 24, 2012 20:47
Improvement for the Paeth transformation
diff --git a/image.c b/image.c
index f22fc6f..36fbe46 100644
--- a/image.c
+++ b/image.c
@@ -257,9 +257,9 @@ void image_transform_fast_rev( struct image *image )
void image_transform( struct image *image )
{
int x, y, i, width, height, aerr, berr, cerr, ia, ib, ic;
- struct pixel p;
+ struct pixel a, b, c, p;
@clausecker
clausecker / gist:3729225
Created September 15, 2012 18:38
Counter comparison
/* counter_stdio.c */
#include <stdio.h>
int main() {
int i = 0;
for (;;i++) fwrite(&i,sizeof i,1,stdout);
}
@clausecker
clausecker / ppm_test.go
Created April 5, 2013 21:22
Testing file for the implementation of fmt.Fscanf
package ppm
import "fmt"
import "io"
import "testing"
// io.Reader for TestFscanf. We use our own reader to be sure that pushing back
// is not supported.
type fscanfTestReader struct {
content []byte
@clausecker
clausecker / golang.nanorc
Last active March 29, 2017 14:18
nanorc file for go
syntax "go" "\.go$"
# types
color green "\<(bool|u?int(8|16|32|64)?|float(32|64)|complex(64|128)|byte|rune|uintptr|string|error)\>"
color green "\<((<-[[:space:]]*)chan|chan[[:space:]]*<-|const|func|interface|map|struct|type|var)\>"
# predefined functions
color blue "\<(append|cap|close|complex|copy|delete|imag|len|make|new|panic|print|println|real|recover)\>"
# control flow
#!/bin/bash
# usage: bench.sh <number of commits>
FILE=foo
BENCHDIR=bench-$1
git init $BENCHDIR
cd $BENCHDIR
#include <stdint.h>
extern uint32_t
read_le32(
uint8_t data[4]
) {
register uint32_t res = 0;
res |= data[0] << 0;
res |= data[1] << 8;
set -e
# preprocess an assembly file with cc -E, throwing out C code from system
# header files in the process. This is neccessary as some Linux headers with
# valuable symbolic constants also contain C code we do not want. This script
# gets rid of these.
#
# Please notice that this script does not remove C code from header included
# from local includes. Please also notice that this script eats line directives
# from included files.
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>
#define SHELL "/bin/sh"
extern int main(int, char*[]);
static int readingend(int, int, const char*);
@clausecker
clausecker / echo.c
Created October 26, 2014 16:05
My implementation of echo(1)
/*-
* Copyright (c) 2014 Robert Clausecker <[email protected]>
*/
#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
#include <stdlib.h>
#include "err.h"
/*-
* Copyright (c) 2014 Robert Clausecker
*/
/*
* parse_mode() - parse an octal or symbolic mode string into a mode_t
*/
#define _XOPEN_SOURCE 700
#include <stdlib.h>