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 / 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;
@thinkhy
thinkhy / gist:774395
Created January 11, 2011 13:13
CopyFile_Perl
####################################################################################
# Description: Copy error files to another directory
# Usage:
# Creator: thinkhy
# Date: 2010.01.13
####################################################################################
use strict;
use warnings;
use Cwd;
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 / 关于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 / 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 / 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);
@thinkhy
thinkhy / Create Bitmap File(Win32)
Created January 18, 2011 03:06
Create Bitmap File(Win32)
void SaveBitmap(HBITMAP hResult, wstring strBmpFile)
{
BITMAP bmp = {0};
GetObject(hResult, sizeof(BITMAP), &bmp);
BITMAPINFO bmpInfo = {0};
bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpInfo.bmiHeader.biWidth = bmp.bmWidth;
bmpInfo.bmiHeader.biHeight = bmp.bmHeight;
bmpInfo.bmiHeader.biPlanes = 1;
@thinkhy
thinkhy / wincore.cpp
Created January 25, 2011 10:07
MFC_wincore
#include "stdafx.h"
#ifndef _AFX_NO_OCC_SUPPORT
#include "occimpl.h"
#endif
#pragma warning(disable:4706)
#define COMPILE_MULTIMON_STUBS
#include <multimon.h>
#pragma warning(default:4706)