Skip to content

Instantly share code, notes, and snippets.

View snaewe's full-sized avatar

Stefan Naewe snaewe

  • Planet Earth (UTC+2)
View GitHub Profile
@snaewe
snaewe / init_python_with_threads.cpp
Last active December 14, 2015 08:09
The correct way to initialize an embedded Python interpreter in a program that uses multiple threads.
// From http://wiki.blender.org/index.php/Dev:2.4/Source/Python/API/Threads
void start_python()
{
Py_NoSiteFlag = 1;
Py_SetProgramName("my_program_name");
Py_Initialize();
PyEval_InitThreads();
PyThreadState *py_tstate = PyGILState_GetThisThreadState();
PyEval_ReleaseThread(py_tstate);
@snaewe
snaewe / version.py
Last active March 5, 2019 20:25 — forked from ampledata/version.py
# -*- coding: utf-8 -*-
# Author: Douglas Creager <[email protected]>
# This file is placed into the public domain.
# Calculates the current version number. If possible, this is the
# output of “git describe”, modified to conform to the versioning
# scheme that setuptools uses. If “git describe” returns an error
# (most likely because we're in an unpacked copy of a release tarball,
# rather than in a git working copy), then we fall back on reading the
# contents of the RELEASE-VERSION file.

Keybase proof

I hereby claim:

  • I am snaewe on github.
  • I am snaewe (https://keybase.io/snaewe) on keybase.
  • I have a public key whose fingerprint is 0E3E 3B5F 9344 7F55 F461 88C3 A327 C9B2 2095 D5A5

To claim this, I am signing this object:

@snaewe
snaewe / strftime.c
Created September 6, 2016 07:05
Test if strftime sets errno
#include <time.h>
#include <stdio.h>
#include <errno.h>
int main(int argc, char* argv[])
{
time_t t = time(0);
char mbstr[100] = { 0 };
printf("errno: %d\n", errno);
size_t s = strftime(mbstr, sizeof(mbstr), ((argc>1) ? argv[1] : "%c"), localtime(&t));
@snaewe
snaewe / sudify.sh
Created November 3, 2016 07:16
run anything under sudo
#!/bin/bash
PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin
case ${0##*/} in
sudify)
if [ $# -eq 1 ]; then
pushd ${0%/*} > /dev/null
if [ -e $1 ]; then
echo "ERROR: Can't sudify $1"
popd > /dev/null
exit 1