Skip to content

Instantly share code, notes, and snippets.

@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 / 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() )

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

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".
@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;
@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 / teach.md
Created May 20, 2014 03:54
How to teach
  • I hear, I forget
  • I see, I remember
  • I do, I understand

(Thanks Bob)

@kasajian
kasajian / Linux.md
Created May 20, 2014 04:02
Linux / Ubuntu

Stuff to do after installing

How to mount the Windows host drive from within an Ubuntu

Assuming NAT is used, and the host port is 192.168.234.2, the host's 'C:' drive (i.e. using default share C$) is mounted to Ubuntu's folder /mnt/hostc

  • First create the mount point:

    mkdir /mnt/hostc chown zumaubuntu:zumaubuntu x

@kasajian
kasajian / Pi.md
Created May 20, 2014 04:04
Yet Another Reference to Pi
3.
14159 26535 89793 23846 26433 83279 50288 41971 69399 37510
58209 74944 59230 78164 06286 20899 86280 34825 34211 70679
82148 08651 32823 06647 09384 46095 50582 23172 53594 08128
48111 74502 84102 70193 85211 05559 64462 29489 54930 38196
44288 10975 66593 34461 28475 64823 37867 83165 27120 19091
45648 56692 34603 48610 45432 66482 13393 60726 02491 41273
72458 70066 06315 58817 48815 20920 96282 92540 91715 36436
78925 90360 01133 05305 48820 46652 13841 46951 94151 16094
@kasajian
kasajian / CSLogger.md
Last active August 23, 2017 21:46
Poor Man's C Sharp Logger

Brain-dead simplistic logger

    var message = ".....";
    System.IO.File.AppendAllText(System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData), "log.txt"), string.Format("{0}\r\n", message));

Then type %localappdata% from the Run dialog to display the folder containing log.txt. Or type %localappdata%\log.txt

A method taking variable number of arguments

private static void Log(string format, params object[] parameters)