Skip to content

Instantly share code, notes, and snippets.

Kingsley Chen kingsamchen

View GitHub Profile
View enable_se_debug.cpp
bool SetProcessSEPrivilege(HANDLE process, PrivilegeOption option)
{
DWORD flags = TOKEN_ADJUST_PRIVILEGES;
base::win::ScopedHandle token;
if (!OpenProcessToken(process, flags, token.Receive()))
{
return false;
}
LUID uid;
@kingsamchen
kingsamchen / gen.py
Created Nov 21, 2018
A template for cmake driver
View gen.py
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# 0xCCCCCCCC
import argparse
import os
import shlex
import shutil
import subprocess
View git-contribution-statistics.py
#!python3
# -*- coding: utf-8 -*-
# 0xCCCCCCCC
import re
import shlex
import subprocess
import sys
FIRST_REV = ''
View win32_conditional_variables_sample.cpp
#include <tchar.h>
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <string>
#include <process.h>
#include <Windows.h>
View singleton.cpp
/******************************************************************************
Module: Singleton.cpp
Notices: Copyright (c) 2008 Jeffrey Richter & Christophe Nasarre
******************************************************************************/
#include "resource.h"
#include "..\CommonFiles\CmnHdr.h" /* See Appendix A. */
#include <windowsx.h>
View template_method_and_strategy_pattern.cpp
typedef std::string Record;
class GTAClient {
public:
virtual ~GTAClient() {}
virtual bool Filter(const Record&)
{
return true;
}
View stable_marriage_problem.py
def GetMatePrefList(pref_list, person):
for i in range(len(pref_list)):
if person == pref_list[i][0]:
return pref_list[i][1]
def Match(men_pref_list, women_pref_list):
free_man = []
free_woman = []
for man in men_pref_list:
free_man.append(man[0])
View thread_pool_async_io.cpp
void CALLBACK OverlappedCompletionRoutine(PTP_CALLBACK_INSTANCE instance,
PVOID context,
PVOID overlapped,
ULONG io_result,
ULONG_PTR bytes_transferred,
PTP_IO io)
{
auto ov = static_cast<OVERLAPPED*>(overlapped);
std::cout << "read " << bytes_transferred << std::endl;
std::cout << static_cast<char*>(context);
View threadpool_timer.cpp
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) {
View str2decint.cpp
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;
You can’t perform that action at this time.