Skip to content

Instantly share code, notes, and snippets.

View datenwolf's full-sized avatar

datenwolf datenwolf

  • Lübeck, Germany, Europe, Earth, Star System "Sol", Milky Way, Virgo Cluster, Universe
View GitHub Profile
#include <malloc.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/prctl.h>
@datenwolf
datenwolf / xscreensaver-lockall
Created May 12, 2015 13:36
Small Python script that locks all XScreenSaver instances running on a system – useful for suspend to … scripts
#!/usr/bin/python2
# vim: set fileencoding=utf-8 syntax=python tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab:
import os, os.path, psutil
def procenv(pid):
try:
env_fd = open(os.path.join('/proc', str(pid), 'environ'), 'r')
environ = env_fd.read()
env_fd.close()
GLuint load_gl_shader_from_sources(
GLenum shader_unit,
char const * const * const sources )
{
GLuint shader = glCreateShader(shader_unit);
if( !shader ) {
goto failed_shader;
}
size_t n_sources = 0;
@datenwolf
datenwolf / cubehelix.c
Last active August 29, 2015 14:20
Cubehelix LUT generator
void
cubehelix(
size_t const n_steps,
uint8_t * const out_lut, /* 3 * n_steps elements, r8b8g8 */
double const start, /* start color */
double const rotations,
double const hue,
double const gamma )
{
size_t i;
@datenwolf
datenwolf / print_arrays.c
Created January 24, 2015 10:01
small explanatory code for OpenGL vertex array draw modes
#include <stdio.h>
typedef long MYenum;
enum {
SINGLES,
PAIRS,
TRIPLES,
};
#include <stdio.h>
#include <GL/glut.h>
#define local_GL_MAX_3D_TEXTURE_SIZE 0x8073
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL | GLUT_DOUBLE);
glutCreateWindow("Max 3D texture size");
@datenwolf
datenwolf / safe_write.c
Created May 9, 2014 16:22
Safely writing to files atomically (write to temporary and rename) with crash safe cleanup handling
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
@datenwolf
datenwolf / gltmultierror.c
Created November 25, 2012 19:42
GLT (OpenGL Tools) multierror printer
#include <stdio.h>
#include <GL/gl.h>
#include <GLT/multierror.h>
void gltPrintMultiError(char const * const prefix)
{
GLenum err;
while( (err = glGetError()) != GL_NO_ERROR) {
switch( err ) {
@datenwolf
datenwolf / mask_creator.py
Created July 11, 2012 14:39 — forked from tonysyu/mask_creator.py
Tool to create polygon mask in Matplotlib
"""
Interactive tool to draw mask on an image or image-like array.
Adapted from matplotlib/examples/event_handling/poly_editor.py
"""
import numpy as np
# import matplotlib as mpl
# mpl.use('tkagg')