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 / fancy-git-bash-prompt.sh
Created January 20, 2009 20:19 — forked from woods/git_svn_bash_prompt.sh
A fancy bash prompt showing some git status.
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
BLUE="\[\033[0;34m\]"
LIGHT_RED="\[\033[1;31m\]"
LIGHT_GREEN="\[\033[1;32m\]"
WHITE="\[\033[1;37m\]"
LIGHT_GRAY="\[\033[0;37m\]"
COLOR_NONE="\[\e[0m\]"
@snaewe
snaewe / read_with_timeout.cc
Created September 4, 2011 07:50
boost::asio - async read with timeout
void set_result(optional<error_code>* a, error_code b)
{
a->reset(b);
}
template <typename MutableBufferSequence>
void read_with_timeout(tcp::socket& sock,
const MutableBufferSequence& buffers)
{
optional<error_code> timer_result;
deadline_timer timer(sock.io_service());
@snaewe
snaewe / hashapass.sh
Created November 15, 2011 11:05
Hashapass command line tool
#!/bin/bash
#hashapass.com method for generating passwords
#script by Simon Elmir
export IFS="" #read will now preserve whitespace
read -rp "parameter: " PARAMETER
read -rsp "password: " PASSWORD
echo
echo -n "$PARAMETER" \
| openssl dgst -sha1 -binary -hmac "$PASSWORD" \
| openssl enc -base64 \
@snaewe
snaewe / run_many.cpp
Created November 25, 2011 15:38
run many jobs in a boost::asio::io_service
// Fixed example from: http://thisthread.blogspot.com/2011/04/multithreading-with-asio.html
void run (int tNumber) // 1.
{
boost::asio::io_service svc; // 2.
boost::thread_group threads;
{
std::auto_ptr<boost::asio::io_service::work> work(new boost::asio::io_service::work(svc)); //3.
for (int i = 0; i < tNumber; ++i) // 4.
#include <boost/interprocess/streams/vectorstream.hpp>
#include <vector>
#include <string>
typedef std::vector<char> CharVec;
typedef boost::interprocess::basic_vectorstream<CharVec> vectorstream;
typedef boost::interprocess::basic_ivectorstream<CharVec> ivectorstream;
typedef boost::interprocess::basic_ovectorstream<CharVec> ovectorstream;
int main()
@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}
# Eine einfache Ausgabe von Membern eines Objektes erreicht man mit
# (vorausgesetzt objekt.intMember und objekt.strMember existieren)
print "%(intMember)d %(strMember)s" % vars(objekt)
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();
@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);
@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) ) );
}