Skip to content

Instantly share code, notes, and snippets.

@uhziel
uhziel / SetConsoleCtrlHandler.c
Created January 6, 2012 02:45
Set Console Ctrl Handler in Windows
/*
* filename: SetConsoleCtrlHandler.c
* description:
* This is a example of the SetConsoleCtrlHandler function that is used to
* install a control handler.
* via http://msdn.microsoft.com/en-us/library/ms685049(v=VS.85).aspx
* author: uhziel(uhziel@gmail.com)
* history:
* version date ps
* ------- ---------- --------------------------------
@uhziel
uhziel / pre-commit.sh
Created April 8, 2013 07:28
Subversion server pre-commit hook for Unity3D .meta file. 约束 Assets 目录下添加、删除、移动、改名文件或目录时,必须要携带对应 .meta 文件。 如果提交的 log 中包含"The Shawshank Redemption",可以逃避此规则。
#!/bin/bash
REPOS="$1"
TXN="$2"
SVNLOOK=svnlook
MAGICWORD='The Shawshank Redemption'
# Magic Word: The Shawshank Redemption.
# via http://tortoisesvn.net/docs/nightly/TortoiseSVN_en/tsvn-repository-hooks.html
#include <iostream> // std::cout
enum FruitType
{
Apple,
Pear,
};
int main () {
FruitType enum_type = Pear;
@uhziel
uhziel / cpp_hex2bin.cpp
Last active September 10, 2020 09:17
cpp_hex2bin
void Bin2Hex(const char* buf, size_t len, std::string& out)
{
std::ostringstream ostr;
ostr << std::hex;
ostr.fill('0');
for (size_t i = 0; i < len; i++)
{
unsigned char tmp = buf[i];
ostr << std::setw(2) << static_cast<short>(tmp);
}
#include <iostream>
#include <windows.h>
int main() {
DWORD t1 = 4294967295;
DWORD t2 = 2;
DWORD delta = t2 - t1;
std::cout << "DWORD delta:" << delta << std::endl;
unsigned long long lt1 = 4294967295;
#include "gmock/gmock.h"
#include <gtest/gtest.h>
using ::testing::AtLeast;
using ::testing::InSequence;
class Turtle {
public:
virtual ~Turtle() {}
virtual void PenUp() = 0;
virtual void PenDown() = 0;
@uhziel
uhziel / cpp-traverse-example.cpp
Last active March 24, 2020 00:50
g++ -g -std=c++11 -o cpp-traverse-example cpp-traverse-example.cpp
#include "traverse.h"
struct Point {
int32_t x;
int32_t y;
};
TRAVERSE_STRUCT(Point, FIELD(x) FIELD(y))
/* Expand to
* void visit(traverse::CoutWriter& visitor, Point& obj) {
@uhziel
uhziel / drop_bin_dir_to_me.bat
Created March 23, 2020 02:47
上传符号到自定义windows符号服务器,把文件夹拖动到此批处理文件上即可
@echo off
rem 脚本传入参数(按顺序): <BIN_DIR>
setlocal EnableDelayedExpansion
rem echo BIN_DIR:%1
rem =========== 配置 ===========
rem SYMSTOREPATH 符号服务器地址
rem PRODUCT 你的产品名
rem VERSION 你产品的版本
rem COMMENT 你想加的注释
@uhziel
uhziel / pack_unpack.lua
Last active March 17, 2020 13:05
lua pack and unpack arguments
--return netpack.filter( queue, msg, sz)
local results = table.pack(netpack.filter( queue, msg, sz))
skynet.error("un", table.unpack(results))
return table.unpack(results)
@uhziel
uhziel / python_socket.py
Created March 12, 2020 02:47
the example of using python socket
# -*- coding: utf-8 -*-
import socket
import struct
import threading
TCP_IP = '192.168.1.133'
TCP_PORT = 31436
BUFFER_SIZE = 102400