Categories Archives: snippet

Raspberry PI controlling an Arduino via the pyfirmata protocol

The Raspberry PI is good for a lot of things from computer clusters to home automation but its missing a few things such as a real time clock, terminal/barrel power connector, or  Analog pins.  The Arduino has analog pins that can be read by the USB virtual serial port from the Raspberry PI. In MagPI issue 7, has a great article on [...]

NiceDog nano php web framework

Last week I started on a simple web app that only has three pages. After I got the prototype working I wanted to clean up the code and switch over to using a more robust framework. Normally I would use something like CakePHP (PHP MVC framework). But since this web app is so small and didn’t need all the extra [...]

Light painting with Processing

I have always liked light panting and light graffiti. But there are things that I don’t like about it, it takes along time, its process incentive, you can do it live. After searching around the internet I found this video Visual Performance – Lichtfaktor vs Optix from Jens Heinen on Vimeo Live light painting! The application does not [...]

How to find the text column header of a CListCtrl in MFC

  How to find the text column header of a CListCtrl in MFC CString GetColumnName( CListCtrl * list, int nCol ) {     CString strNome;     CHeaderCtrl* pHdr = list->GetHeaderCtrl();     if ( pHdr )         if ( nCol < pHdr->GetItemCount() )         {             HDITEM hdi;             hdi.mask = HDI_TEXT;             hdi.pszText = strNome.GetBuffer( [...]

Dump a CListCtrl

This snippet dumps the content of a CListCtrl in to a file. It also gets the number of columns in the list.   int GetColumnsCount( CListCtrl * list ) {     if( list != NULL )     {         const CHeaderCtrl * pHeaderCtrl = (CHeaderCtrl*) list->GetDlgItem(0);         if( pHeaderCtrl != NULL ) {             return  pHeaderCtrl->GetItemCount() [...]

How to create a menu and submenu on right click in MFC

  void ::OnNMRClickBacnetTree(NMHDR *pNMHDR, LRESULT *pResult) {     CPoint ptScreen;     SendMessage(WM_CONTEXTMENU, (WPARAM) m_hWnd, GetMessagePos() );     if (! GetCursorPos(&ptScreen))     {         return ;     }     // Select an element under the right click     CPoint ptClient(ptScreen);     m_BACnetTree.ScreenToClient(&ptClient);        // Create the right click menu     CMenu rightClickMenu;     rightClickMenu.CreatePopupMenu();     rightClickMenu.AppendMenu(MF_STRING,1021,_T("One")); [...]

C++ name mangling hell

I found this post on Experts exchange about C++ name mangling hell. I have run in to this problems a few times, it drives me nuts as I always forget about it when trying to use LoadLibrary and GetProcAddress. #ifdef FIRSTINDLL_EXPORTS #define FIRSTINDLL_API extern “C” __declspec(dllexport) #else #define FIRSTINDLL_API extern “C” __declspec(dllimport) #endif // Exported [...]

Insert new post in to wordpress from php

This code snippet should let you add a new post to your wordpress database 2.5.1 require_once(‘wp-config.php’); // create post object class wm_mypost {     var $post_title;     var $post_content;     var $post_status;    /* publish, private */     var $post_author;    /* author user id (optional) */     var $post_name;      /* slug (optional) */     var $post_type;      /* ’page’ or ’post’ (optional, defaults to ’post’) */     var $comment_status; /* open or closed for commenting (optional) */     var $post_category ;  } // initialize post object $wm_mypost = new wm_mypost(); $wm_mypost->post_title    = "Title2 ". date( ’r' ); $wm_mypost->post_content  = "content3"; $wm_mypost->post_status   = ’publish’;  $wm_mypost->post_author   = 1; // Catagorys $post_category = split("," , "one"); foreach($post_category as $key=>$val) {     $post_category[$key] = get_cat_ID($val); } $wm_mypost->post_category =  $post_category ;  // Optional; uncomment as needed // $wm_mypost->post_type = ’page’; // $wm_mypost->comment_status = ’closed’; // feed object to wp_insert_post $post_ID = wp_insert_post($wm_mypost); echo date( ’r' ) . "\n"; echo "post_ID:". $post_ID . "\n"; 

How to make a CMinMaxAvg class

I got asked how to create a simple averaging class. If you where feeling smart you could enhance this class in to a template class for a object that has the =,+,>,< operator. But I’m feeling lazy today. class CMinMaxAvg { private : int m_count; int m_total; int m_min; int m_max; public: CMinMaxAvg() { m_count [...]

NSIS – tips and tricks

I create a lot of windows application to make things easier for my customers. The simple act of coping a file from an email to a certain directory can become the most complicated tasks for a certain type of customer. I use an Scriptable Install System provided by NullSoft called NSIS (Nullsoft Scriptable Install System). [...]