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;
}
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;
}
inline bool CodeHasEHaSwitch()
{
bool dtorCalled = false;
struct CCheckEHaSwitch
{
CCheckEHaSwitch( bool& dtorCalled) : dtorCalled( dtorCalled ) {}
~CCheckEHaSwitch() { dtorCalled = true; }
bool& 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
Clean your glass shower
Reheat Pizza
HWND prevWindow = NULL;
HWND hwnd;
for ( ;; )
{
hwnd = FindWindowEx( HWND_MESSAGE, prevWindow, L"OleMainThreadWndClass", NULL );
if ( !hwnd )
break;
if ( GetWindowThreadProcessId( hwnd, NULL ) == GetCurrentThreadId() )
#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;
#if _DEBUG | |
file://===================================================================== | |
========= | |
// WinQueryPerformance | |
// Outputs and resets the performance counter. | |
// (For multiple timers, see CPerformanceTimer) | |
// | |
// Use it like so: | |
// | |
// WinQueryPerformance( 0 ); |
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
Create clock.cs:
public class Clock
{
public System.String Now()
{
return "Don't know the time";
}
}