Archive

Archive for the ‘Fresh News’ Category

Linux Magazines

March 4th, 2010 No comments

Qt Smart Pointers

February 7th, 2010 No comments

Load a file to a string list

January 22nd, 2010 No comments
#include <vector>
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iterator>

int main(int argc, char* argv[])
{
    std::vector<std::string> v;
    std::ifstream f("e:/test.txt");
    if(f.is_open())
    {
        std::copy(std::istream_iterator<std::string>(f),
                  std::istream_iterator<std::string>(),
                  std::back_inserter(v));
    }
    // проверка
    std::copy(v.begin(), v.end(),
              std::ostream_iterator<std::string>(std::cout, "\n"));

    return 0;
}

rsdn.ru

Convert __DATE__ to unsigned int

January 21st, 2010 No comments
#define YEAR ((((__DATE__ [7] - '0') * 10 + (__DATE__ [8] - '0')) * 10 \
              + (__DATE__ [9] - '0')) * 10 + (__DATE__ [10] - '0'))

#define MONTH (__DATE__ [2] == 'n' ? 0 \
               : __DATE__ [2] == 'b' ? 1 \
               : __DATE__ [2] == 'r' ? (__DATE__ [0] == 'M' ? 2 : 3) \
               : __DATE__ [2] == 'y' ? 4 \
               : __DATE__ [2] == 'n' ? 5 \
               : __DATE__ [2] == 'l' ? 6 \
               : __DATE__ [2] == 'g' ? 7 \
               : __DATE__ [2] == 'p' ? 8 \
               : __DATE__ [2] == 't' ? 9 \
               : __DATE__ [2] == 'v' ? 10 : 11)

#define DAY ((__DATE__ [4] == ' ' ? 0 : __DATE__ [4] - '0') * 10 + (__DATE__ [5] - '0'))

#define DATE_AS_INT (((YEAR - 2000) * 12 + MONTH) * 31 + DAY)

int main (void)
{
  printf ("%d-%02d-%02d = %d\n", YEAR, MONTH + 1, DAY, DATE_AS_INT);
  return 0;
}

Customize the Windows 7 “Send To” Menu

January 16th, 2010 No comments

To get to the SendTo folder, you’ll need to open up an Explorer window, and then paste in the following to the address bar.

%APPDATA%\Microsoft\Windows\SendTo

%APPDATA% is an environment variable that actually maps to something like C:\users\<username>\AppData\Roaming.

Also, common “SendTo” menu is located here: C:\Users\Default\AppData\Roaming\Microsoft\Windows\SendTo

Tags: ,

Create a dmp file from the application

October 25th, 2009 No comments
static LPTOP_LEVEL_EXCEPTION_FILTER m_previousFilter = NULL;


typedef BOOL (WINAPI *MINIDUMPWRITEDUMP)(HANDLE hProcess, DWORD dwPid, HANDLE hFile, MINIDUMP_TYPE DumpType,
                                         CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
                                         CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
                                         CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam);

static LONG WINAPI MyUnhandledExceptionFilter(PEXCEPTION_POINTERS pExceptionInfo)
{
    HMODULE hDll = ::LoadLibrary(_T("DBGHELP.DLL"));
    MINIDUMPWRITEDUMP pDump = (MINIDUMPWRITEDUMP)::GetProcAddress(hDll, "MiniDumpWriteDump");

    _MINIDUMP_EXCEPTION_INFORMATION ExInfo;
    ExInfo.ThreadId = ::GetCurrentThreadId();
    ExInfo.ExceptionPointers = pExceptionInfo;
    ExInfo.ClientPointers = NULL;

    MINIDUMP_CALLBACK_INFORMATION mci;

    // HANDLE hFile - minidamp file name(for example, "test.dmp")

    BOOL bOK = pDump(::GetCurrentProcess(), ::GetCurrentProcessId(),
                     hFile, 1, &ExInfo, NULL, &mci);
}


void main()
{
    // setup our own ExceptionHandler
    m_previousFilter = SetUnhandledExceptionFilter(MyUnhandledExceptionFilter);

    // actial work

    // befoe exit
    if (m_previousFilter)
    {
        SetUnhandledExceptionFilter(m_previousFilter);
    }
}

Parallel Programming

October 22nd, 2009 No comments

count valuable bits in unsigned int

October 14th, 2009 No comments
uint8_t num_of_bits32(uint32_t _arg)
{
    _arg = (_arg & 0x55555555L) + ((_arg >> 1) & 0x55555555L);
    _arg = (_arg & 0x33333333L) + ((_arg >> 2) & 0x33333333L);
    _arg = (_arg + (_arg >> 4)) & 0x0F0F0F0FL;
    _arg = _arg + (_arg >> 8);

    return (uint8_t)(_arg + (_arg >> 16)) & 0x3F;
}

or

int count1(int t)
{
 __asm
 {
        mov edx,t
        mov eax, 0
  cycle : bsf ecx, edx
        jz finish
        inc eax
        inc ecx
        shr edx, cl
        jmp cycle
  finish:
 }
}

Microsoft Application Verifier

September 29th, 2009 No comments

Application Verifier is designed specifically to detect and help debug memory corruptions and critical security vulnerabilities.

This is achieved by monitoring a native application’s interaction with the Windows operating system, profiling its use of objects, the registry, the file system, and Win32 APIs (including heaps, handles, locks, etc), and indicating issues when and where they are discovered.

Application Verifier also includes checks to predict how well an application may perform under various account privileges. These compatibility tests are used in Windows Logo program.

Print verification tests are also available to verify your usage of the print subsystem.

Download

Additional links:

Qt State Machine Overview

September 24th, 2009 No comments