Skip to content

Instantly share code, notes, and snippets.

@kasajian
kasajian / day-of-week.md
Created May 20, 2014 03:52
Formula to find the day of the week given the date

Code:

/* 0 = Sunday, 1 <= m <= 12, y > 1752 or so */
int dayofweek(int y, int m, int d)
{
    static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
    y -= m < 3;
    return (y + y/4 - y/100 + y/400 + t[m-1] + d) % 7;
}
@kasajian
kasajian / EHaSwitch.cpp.md
Created May 20, 2014 03:50
Determine from code if compiled with /EHa switch
inline bool CodeHasEHaSwitch()
{
    bool dtorCalled = false;

    struct CCheckEHaSwitch
    {
        CCheckEHaSwitch( bool& dtorCalled) : dtorCalled( dtorCalled ) {}
        ~CCheckEHaSwitch() {  dtorCalled = true; }
 bool&amp; dtorCalled;

Can also be used as a way to hash a string.

/*    crc16 - crc16 routine
 *
 *    R.K. Irvine
 *
 *    This routine returns the crc16 for the string pointed
 * to by "in".

Bed Sheets

  • After drying my sheets, put both sheets and one pillowcase in the other pillow case. Fold neatly in a square. Next time you change sheets, you just take the one pillow case and all the sheets and pillow case are inside. No need to look for matches.

Clean your glass shower

  • To clean the glass in your shower easily, apply lemon juice to the glass with a sponge. Then, take newspaper and wipe the lemon juice off the glass. It will be clean and sparkle with no scrubbing!

Reheat Pizza

@kasajian
kasajian / COMsHWND.md
Created May 20, 2014 03:41
How to get COM's HWND
        HWND prevWindow = NULL;
        HWND hwnd;
        for ( ;; )
        {
            hwnd = FindWindowEx( HWND_MESSAGE, prevWindow, L"OleMainThreadWndClass", NULL );
            if ( !hwnd )
                break;

 if ( GetWindowThreadProcessId( hwnd, NULL ) == GetCurrentThreadId() )
@kasajian
kasajian / fib.cpp.md
Created May 20, 2014 03:39
Calculate Fibonacci at compile time in C++
#include <stdio.h>

// The following code prints out the first five elements of the
// fibonacci series without calculating the values at runtime.

template <int param>
struct CFibonacci
{
 static const value;
@kasajian
kasajian / perf.cpp
Created May 20, 2014 03:38
C++ Timer for measuring performance
#if _DEBUG
file://=====================================================================
=========
// WinQueryPerformance
// Outputs and resets the performance counter.
// (For multiple timers, see CPerformanceTimer)
//
// Use it like so:
//
// WinQueryPerformance( 0 );

To Disable UAC

Using a Batch file:

REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /v "EnableLUA" /t "REG_DWORD" /d "0" /f

Using Powershell:

 @powershell Set-ItemProperty -Path registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\policies\system -Name EnableLUA -Value 0
@kasajian
kasajian / c_sharp_component_creation.md
Created May 20, 2014 03:23
Command-line component creation with C Sharp

Create clock.cs:

public class Clock
{
     public System.String Now()
     {
	return "Don't know the time";
     }
}