Skip to content

Instantly share code, notes, and snippets.

View thinkhy's full-sized avatar
🐕
On vacation

thinkhy thinkhy

🐕
On vacation
View GitHub Profile
@thinkhy
thinkhy / debug-pintos-cs162.md
Last active August 29, 2015 14:22
How to Debug Pintos

How to Debug Pintos

Pull latest docker image from docker.io

  sudo docker pull thinkhy/cs162-pintos

Run container

@thinkhy
thinkhy / cs162-2015-notes.md
Last active August 29, 2015 14:23
CS162 2015 Notes
@thinkhy
thinkhy / CMU-440-Project0.md
Created June 27, 2015 15:19
CMU-440-Project0

15-440 Project 0 Project 0: Implementing a multi-client echo server Due Thursday, January 30, 2014 at 11:59pm The goal of this assignment is to get up to speed on the Go programming language and to help remind you about the basics of socket programming that you learned in 15-213. In this assignment you will implement a simple multi-client echo server in Go: every message sent by a client should be echoed to all connected clients. Server Characteristics Your multi-client echo server must have the following characteristics:

@thinkhy
thinkhy / gist:772306
Created January 10, 2011 03:29
Write_Log
sub getTime
{
my $time = shift || time();
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time);
$year += 1900;
$mon ++;
$min = '0'.$min if length($min) < 2;
$sec = '0'.$sec if length($sec) < 2;
void WriteLog(CString strLog)
{
EnterCriticalSection(g_cs);
static CString strFileName;
if (strFileName.IsEmpty())
{
strFileName.GetBuffer(MAX_PATH);
::GetModuleFileName(NULL, strFileName.GetBuffer(0), MAX_PATH);
::PathRemoveFileSpec(strFileName.GetBuffer(0));
::PathAppend(strFileName.GetBuffer(0), L"Log.txt");
@thinkhy
thinkhy / Draw Bitmap
Created January 13, 2011 02:42
Draw Bitmap in a windows base on MFC
void CMainFrame::DrawView(HBITMAP hbmp)
{
ASSERT(hbmp != NULL);
CView *pView = GetActiveView();
ASSERT(pView != NULL);
// pView->Invalidate(TRUE);
@thinkhy
thinkhy / APUE: readn and writen
Created January 16, 2011 03:00
APUE: readn and writen
#include "apue.h"
ssize_t /* Read "n" bytes from a descriptor */
readn(int fd, void *ptr, size_t n)
{
size_t nleft;
ssize_t nread;
nleft = n;
while (nleft > 0) {
@thinkhy
thinkhy / 关于Socket的recv与send原理
Created January 16, 2011 02:55
关于Socket的recv与send
http://topic.csdn.net/u/20080414/14/7e4737fe-53c5-443a-b38a-7735c423e4aa.html
对于send函数:
send函数只负责将数据提交给协议层。
当调用该函数时,send先比较待发送数据的长度len和套接字s的发送缓冲区的长度,如果len大于s的发送缓冲区的长度,该函数返回SOCKET_ERROR;
如果len小于或者等于s的发送缓冲区的长度,那么send先检查协议是否正在发送s的发送缓冲中的数据;
如果是就等待协议把数据发送完,如果协议还没有开始发送s的发送缓冲中的数据或者s的发送缓冲中没有数据,那么send就比较s的发送缓冲区的剩余空间和len;
如果len大于剩余空间大小,send就一直等待协议把s的发送缓冲中的数据发送完,如果len小于剩余空间大小,send就仅仅把buf中的数据copy到剩余空间里(注意并不是send把s的发送缓冲中的数据传到连接的另一端的,而是协议传的,send仅仅是把buf中的数据copy到s的发送缓冲区的剩余空间里)。
如果send函数copy数据成功,就返回实际copy的字节数,如果send在copy数据时出现错误,那么send就返回SOCKET_ERROR;
@thinkhy
thinkhy / Windows 播放声音
Created January 16, 2011 14:56
Windows播放Wave声音的代码
#pragma comment(lib, "winmm.lib")
// call example
// 支持绝对路径和相对路径
::PlaySound(strSoundFile.c_str(), NULL, SND_ASYNC|SND_NOWAIT|SND_FILENAME);
@thinkhy
thinkhy / Windows 播放声音
Created January 16, 2011 14:56
Windows播放Wave声音的代码
#pragma comment(lib, "winmm.lib")
// call example
// 支持绝对路径和相对路径
::PlaySound(strSoundFile.c_str(), NULL, SND_ASYNC|SND_NOWAIT|SND_FILENAME);