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
def SolveLinearEquationSystem(coeffMatrix, valVector):
# create the augmented matrix
augMatrix = []
for i in range(0, len(coeffMatrix)):
augMatrix.append(coeffMatrix[i] + [valVector[i]])
for i in range(0, len(augMatrix) - 1):
# find row containing largest ith col ele then swap with row i
# ensure scaling factor will never exceed 1
# otherwise, round-off error may be bring about due to different magnitude order
@kingsamchen
kingsamchen / csapp_exer_2.c
Last active December 20, 2015 15:19
implementation for chapter 2 exercises of CSAPP
/*
2.58
just test byte order
*/
int is_big_endian()
{
unsigned short b = 0x1234;
byte* pb = (byte*)&b;
if (*pb == 0x12)
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);
@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();
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;
/* 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);
@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>
class MT_Queue {
public:
struct ELEMENT {
int thread_num;
int request_num;
};
typedef ELEMENT* PELEMENT;
MT_Queue(int max_elements);
~MT_Queue();
@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.
#
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;