Skip to content

Instantly share code, notes, and snippets.

@mobius
mobius / cloudSettings
Last active March 3, 2020 01:10
vscode setting
{"lastUpload":"2020-03-03T01:09:57.408Z","extensionVersion":"v3.4.3"}
@mobius
mobius / reflect_inputlayout.cpp
Created March 23, 2018 08:19
Reflect DX11 Vertex shader to create input layout
HRESULT CreateInputLayoutDescFromVertexShaderSignature( ID3DBlob* pShaderBlob, ID3D11Device* pD3DDevice, ID3D11InputLayout** pInputLayout )
{
// Reflect shader info
ID3D11ShaderReflection* pVertexShaderReflection = NULL;
if ( FAILED( D3DReflect( pShaderBlob->GetBufferPointer(), pShaderBlob->GetBufferSize(), IID_ID3D11ShaderReflection, (void**) &pVertexShaderReflection ) ) )
{
return S_FALSE;
}
// Get shader info
@mobius
mobius / links.md
Last active July 22, 2021 02:52 — forked from Leandros/links.md
Writing a Modern Rendering Engine
bool PatchManager::GetMD5(const u8 *pBuffer, u32 uBufLen, u8 *rgbHash)
{
BOOL bResult = FALSE;
HCRYPTPROV hProv = 0;
HCRYPTHASH hHash = 0;
DWORD cbRead = 0;
DWORD cbHash = 0;
CHAR rgbDigits[] = "0123456789ABCDEF";
// Get handle to the crypto provider
@mobius
mobius / bloated_code.cc
Last active July 15, 2016 09:50
c++ seasoning
auto f = begin(expanded_panels_) + fixed_index;
// 发现其实expanded_panels其实是根据cur_panel_center已经排好序了
auto p = lower_bound(begin(expanded_panels_), f,
[&](const ref_ptr<Panel>& e){ return center_x <= e->cur_panel_center(); });
rotate(p, f, f + 1);
// 总结
// 上面代码更加高效
// 更加清楚表达含义,review代码的人不用去考虑边界条件因为算法都保证好了
// 以上代码只是选择单个panel移动,但是非常容易扩展成多个panel向右移动
@mobius
mobius / value_semantics.cxx
Created July 7, 2016 12:51
value_semantics.cxx
#include "stdafx.h"
#include <iostream>
#include <memory>
#include <vector>
#include <string>
#include <algorithm>
#include <cassert>
#include <chrono>
#include <thread>
#include <future>
@mobius
mobius / convert_winform.py
Created April 5, 2016 07:48
convert winform designer generated InitializeComponents to ironpython script
# remove various cast
replace \(\([\w.]+\)
with (
# change this with self
# change size 10F to 10
replace (\d+)F
with $1
# replace } as ,) replace { as ( when AddRange
@mobius
mobius / markdownWorker.js
Last active May 1, 2016 18:21
visual studio code markdown for mathjax syntax
/*!--------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
/**
* marked - a markdown parser
* Copyright (c) 2011-2014, Christopher Jeffrey. (MIT Licensed)
* https://github.com/chjj/marked
*/
function Lexer(e) {
this.tokens = [], this.tokens.links = {}, this.options = e || marked.defaults, this.rules = block.normal, this.options.gfm && (this.options.tables ? this.rules = block.tables : this.rules = block.gfm)
@mobius
mobius / test.cc
Created January 31, 2013 00:58
fast test for lambda function
#include <stdio.h>
#include <functional>
void foo( int i )
{
auto f = [=]() { printf("%d\n", i); };
f();
}
@mobius
mobius / gist:4618319
Created January 24, 2013 07:25
Putty with tmux with Solarized theme
https://github.com/seebi/tmux-colors-solarized
https://github.com/altercation/solarized/tree/master/putty-colors-solarized
https://puttytray.goeswhere.com/
https://github.com/altercation/ethanschoonover.com/blob/master/projects/solarized/README.md