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 / 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
@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));

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 / version.py
Last active March 5, 2019 20:25 — forked from ampledata/version.py
# -*- coding: utf-8 -*-
# Author: Douglas Creager <dcreager@dcreager.net>
# 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.
@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 / boost_sleep_millisec.cpp
Created February 28, 2013 08:16
avoid compiler warning "C4244: 'argument' : conversion from '__int64' to 'long"
void sleepMillisec( long milliseconds )
{
boost::this_thread::sleep(
boost::get_system_time() +
boost::posix_time::milliseconds( std::max<long>(milliseconds,0) ) );
}
@snaewe
snaewe / run_iosvc_in_thread.cpp
Last active October 11, 2015 01:38
Run boost::asio::io_service::run in a thread
// -*- c++ -*-
// compile with: "g++ -D_WIN32_WINNT=0x501 run_iosvc_in_thread.cpp -lboost_thread -lboost_system -lwsock32 -o run_iosvc_in_thread"
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include <boost/bind.hpp>
#include <boost/scoped_ptr.hpp>
int main()
{
boost::scoped_ptr<boost::asio::io_service> m_ioServicePtr(new boost::asio::io_service);
inline
CORBA::LongLong msecs_since_midnight()
{
using namespace boost::posix_time;
using boost::gregorian::date;
using boost::numeric_cast;
ptime now = second_clock::local_time();
time_duration td = now.time_of_day();
return td.total_milliseconds();
# Eine einfache Ausgabe von Membern eines Objektes erreicht man mit
# (vorausgesetzt objekt.intMember und objekt.strMember existieren)
print "%(intMember)d %(strMember)s" % vars(objekt)
@snaewe
snaewe / get-tree-from-commit.sh
Created August 23, 2012 09:13
git: get tree from commit
# Das tree Object zu einem commit Object erhält man z.B. mit...
git show commitish^{tree}