Skip to content

Instantly share code, notes, and snippets.

View kingsamchen's full-sized avatar
🐛
Work life balance

0xCCCCCCCC kingsamchen

🐛
Work life balance
View GitHub Profile
const unsigned int ID_MSGBOX_STATIC = 0x0000ffff;
const wchar_t kMsgBoxTitle[] = L"Timed Message Box";
int second_left = 0;
void CALLBACK msgbox_timer(PTP_CALLBACK_INSTANCE instance, void* context,
PTP_TIMER timer)
{
HWND hwnd = ::FindWindow(nullptr, kMsgBoxTitle);
if (hwnd) {
if (second_left == 1) {
int StrToDecInt(const char* str)
{
static const int kMAX = (int)((unsigned)~0 >> 1);
static const int kMIN = -(int)((unsigned)~0 >> 1) - 1;
static const int kMAX_DIV = (int)((unsigned)~0 >> 1) / 10;
static const int kMIN_DIV = (int)((((unsigned)~0 >> 1) + 1) / 10);
static const int kMAX_R = (int)((unsigned)~0 >> 1) % 10;
static const int kMIN_R = (int)((((unsigned)~0 >> 1) + 1) % 10);
int n = 0;
int StrToDecInt(const char* str)
{
static const int kMAX = (int)((unsigned)~0 >> 1);
static const int kMIN = -(int)((unsigned)~0 >> 1) - 1;
static const int kMAX_DIV = (int)((unsigned)~0 >> 1) / 10;
static const int kMIN_DIV = (int)((((unsigned)~0 >> 1) + 1) / 10);
static const int kMAX_R = (int)((unsigned)~0 >> 1) % 10;
static const int kMIN_R = (int)((((unsigned)~0 >> 1) + 1) % 10);
int n = 0;
@kingsamchen
kingsamchen / add_checksum.py
Created January 21, 2014 08:47
one approach for computing checksum
#!/usr/bin/env python
# coding: utf-8
# This file is part of Adblock Plus <http://adblockplus.org/>,
# Copyright (C) 2006-2013 Eyeo GmbH
#
# Adblock Plus is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
class MT_Queue {
public:
struct ELEMENT {
int thread_num;
int request_num;
};
typedef ELEMENT* PELEMENT;
MT_Queue(int max_elements);
~MT_Queue();
@kingsamchen
kingsamchen / IO_Issuer.cpp
Created December 16, 2013 16:35
a tiny tool for issuing high I/O circumstance.
/************************************
** Edition: Demo
** Author: Kingsley Chen
** Date: 2013/11/19
** Purpose: I/O issuer
************************************/
#include "stdafx.h"
#include <conio.h>
#include <string>
/* remove non-alphabet from head and tail */
int main()
{
const char* alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
string text;
while (cin >> text) {
string::size_type begin = text.find_first_of(alphabet);
string::size_type end = text.find_last_of(alphabet) + 1;
text = text.substr(begin, end - begin);
const wstring SHUTDOWN_ACK = L"Server Shutdown";
HANDLE g_requestSubmitted;
HANDLE g_requestReturned;
HWND g_mainDlg;
wstring g_requestText;
UINT APIENTRY ServerThreadFunc(PVOID param)
{
bool isShutdown = false;
@kingsamchen
kingsamchen / MT_Queue.h
Created November 24, 2013 16:34
sample for using SRWLock and Conditional Variables
#pragma once
#include <algorithm>
#include <Windows.h>
class MT_Queue {
public:
MT_Queue(int maxElements);
~MT_Queue();
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
return DialogBox(hInstance, MAKEINTRESOURCE(IDD_DLGMAIN), NULL, DlgProc);