I've updated my .bashrc because I want the title of an xterm or gnome-term to display the current directory or the currently running process.
here are the relevant lines
export PS1='\[\e]0;$PWD\007\]\u@\h:\W$'
trap 'echo -ne "\e]0;$BASH_COMMAND\007"' DEBUG
Monday, April 19, 2010
Thursday, March 25, 2010
Pooled resource pattern
Time to implement a pattern by means of a c++ template. I've used nearly identical code twice in the same project.
One case is a pool of easy curl objects:
The other a pool of libmemcached objects. This should be an interesting use of templates. I'll post what I come up with soon.
One case is a pool of easy curl objects:
CURL *WebResponse::getFromPool()
{
// all actions with the pool must be locked
boost::mutex::scoped_lock lock(poolMutex);
if (curlPool.empty())
{
CURL *pCurl = curl_easy_init();
if (!pCurl)
throw ("allocation failure CURL");
return pCurl;
}
CURL *p = curlPool.front();
curlPool.pop_front();
return p;
}
void WebResponse::putBackInPool(CURL *pCurl)
{
// all actions with the pool must be locked
boost::mutex::scoped_lock lock(poolMutex);
curlPool.push_back(pCurl);
}
The other a pool of libmemcached objects. This should be an interesting use of templates. I'll post what I come up with soon.
Friday, February 12, 2010
Using stl strings std::string with Windows wide characters
This is much easier than it sounds for example:
#include < string >
#include < algorithm >
//Make a wide char string type.
typedef std::basic_string< wchar_t > wstring;
// initialize a wstring
wstring ws = L"Hello World";
// make the string lower case
std::transform(ws.begin(),ws.end(),ws.begin(),tolower);
#include < string >
#include < algorithm >
//Make a wide char string type.
typedef std::basic_string< wchar_t > wstring;
// initialize a wstring
wstring ws = L"Hello World";
// make the string lower case
std::transform(ws.begin(),ws.end(),ws.begin(),tolower);
Wednesday, January 6, 2010
Windows programmer trick #1 --> FindWindowEx & Dialogs
FindWindowEx can be used to find not just your run of the mill window, but dialogs as well.
The documentation is a bit sparse, but makes reference to the MAKEINTATOM macro, this macro just like MAKEINTRESOURCE (they are practically the same), is used when an API call asks for a string but you have an int.
The secret to finding a Dialog with FindWindowEx is to use MAKEINTATOM like so:
HWND hwndDlg = FindWindowEx(NULL,NULL,MAKEINTATOM(32770),NULL);
32770 is the system atom for a dialog box class.
The above line of code searches for dialog boxes with the desktop as the parent window. Works handy for finding tool-windows etc..
The documentation is a bit sparse, but makes reference to the MAKEINTATOM macro, this macro just like MAKEINTRESOURCE (they are practically the same), is used when an API call asks for a string but you have an int.
The secret to finding a Dialog with FindWindowEx is to use MAKEINTATOM like so:
HWND hwndDlg = FindWindowEx(NULL,NULL,MAKEINTATOM(32770),NULL);
32770 is the system atom for a dialog box class.
The above line of code searches for dialog boxes with the desktop as the parent window. Works handy for finding tool-windows etc..
Subscribe to:
Posts (Atom)
chris' shared items
Twitter Updates
Official blog of Chris Lee Runyan
Fastest C++ in the west.