initialization


//多列listview
SMCListView * pMcListView = FindChildByName2<SMCListView>("mclv_test");
if(pMcListView)
{
IMcAdapter *pAdapter = new CTestMcAdapterFix;
pMcListView->SetAdapter(pAdapter);
pAdapter->Release();
}

class CTestMcAdapterFix : public SMcAdapterBase
{
#define NUMSCALE 100000
public:
struct SOFTINFO
{
const wchar_t * pszSkinName;
const wchar_t * pszName;
const wchar_t * pszDesc;
float fScore;
DWORD dwSize;
const wchar_t * pszInstallTime;
const wchar_t * pszUseTime;
};

SArray<SOFTINFO> m_softInfo;

public:
CTestMcAdapterFix()
{
SOFTINFO info[] =
{
{
L"skin_icon1",
L"鲁大师",
L"鲁大师是一款专业的硬件检测,驱动安装工具",
5.4f,
15 * (1 << 20),
L"2015-8-5",
L"今天"
},
{
L"skin_icon2",
L"PhotoShop",
L"强大的图片处理工具",
9.0f,
150 * (1 << 20),
L"2015-8-5",
L"今天"
},
{
L"skin_icon3",
L"QQ7.0",
L"腾讯公司出品的即时聊天工具",
8.0f,
40 * (1 << 20),
L"2015-8-5",
L"今天"
},
{
L"skin_icon4",
L"Visual Studio 2008",
L"Microsoft公司的程序开发套件",
9.0f,
40 * (1 << 20),
L"2015-8-5",
L"今天"
},
{
L"skin_icon5",
L"YY8",
L"YY语音",
9.0f,
20 * (1 << 20),
L"2015-8-5",
L"今天"
},
{
L"skin_icon6",
L"火狐浏览器",
L"速度最快的浏览器",
8.5f,
35 * (1 << 20),
L"2015-8-5",
L"今天"
},
{
L"skin_icon7",
L"迅雷",
L"迅雷下载软件",
7.3f,
17 * (1 << 20),
L"2015-8-5",
L"今天"
}
};


for (int i = 0; i < ARRAYSIZE(info); i++)
{
m_softInfo.Add(info[i]);
}
}

virtual int getCount()
{
return m_softInfo.GetCount()*NUMSCALE;
}

SStringT getSizeText(DWORD dwSize)
{
int num1 = dwSize / (1 << 20);
dwSize -= num1 *(1 << 20);
int num2 = dwSize * 100 / (1 << 20);
return SStringT().Format(_T("%d.%02dM"), num1, num2);
}

virtual void getView(int position, SWindow * pItem, pugi::xml_node xmlTemplate)
{
if (pItem->GetChildrenCount() == 0)
{
pItem->InitFromXml(xmlTemplate);
}

SOFTINFO *psi = m_softInfo.GetData() + position%m_softInfo.GetCount();
pItem->FindChildByName(L"img_icon")->SetAttribute(L"skin", psi->pszSkinName);
pItem->FindChildByName(L"txt_name")->SetWindowText(S_CW2T(psi->pszName));
pItem->FindChildByName(L"txt_desc")->SetWindowText(S_CW2T(psi->pszDesc));
pItem->FindChildByName(L"txt_score")->SetWindowText(SStringT().Format(_T("%1.2f 分"), psi->fScore));
pItem->FindChildByName(L"txt_installtime")->SetWindowText(S_CW2T(psi->pszInstallTime));
pItem->FindChildByName(L"txt_usetime")->SetWindowText(S_CW2T(psi->pszUseTime));
pItem->FindChildByName(L"txt_size")->SetWindowText(getSizeText(psi->dwSize));
pItem->FindChildByName2<SRatingBar>(L"rating_score")->SetValue(psi->fScore / 2);
pItem->FindChildByName(L"txt_index")->SetWindowText(SStringT().Format(_T("第%d行"), position + 1));

SButton *pBtnUninstall = pItem->FindChildByName2<SButton>(L"btn_uninstall");
pBtnUninstall->SetUserData(position);
pBtnUninstall->GetEventSet()->subscribeEvent(EVT_CMD, Subscriber(&CTestMcAdapterFix::OnButtonClick, this));
}

bool OnButtonClick(EventArgs *pEvt)
{
SButton *pBtn = sobj_cast<SButton>(pEvt->sender);
int iItem = pBtn->GetUserData();

if (SMessageBox(NULL, SStringT().Format(_T("Are you sure to uninstall the selected [%d] software?"), iItem), _T("uninstall"), MB_OKCANCEL | MB_ICONQUESTION) == IDOK)
{//删除一条记录
DeleteItem(iItem);
}
return true;
}

//删除一行,提供外部调用。
void DeleteItem(int iPosition)
{
if (iPosition >= 0 && iPosition < getCount())
{
int iItem = iPosition % m_softInfo.GetCount();
m_softInfo.RemoveAt(iItem);
notifyDataSetChanged();
}
}

SStringW GetColumnName(int iCol) const {
return SStringW().Format(L"col%d", iCol + 1);
}

struct SORTCTX
{
int iCol;
SHDSORTFLAG stFlag;
};

bool OnSort(int iCol, SHDSORTFLAG * stFlags, int nCols)
{
if (iCol == 5) //最后一列“操作”不支持排序
return false;

SHDSORTFLAG stFlag = stFlags[iCol];
switch (stFlag)
{
case ST_NULL:stFlag = ST_UP; break;
case ST_DOWN:stFlag = ST_UP; break;
case ST_UP:stFlag = ST_DOWN; break;
}
for (int i = 0; i < nCols; i++)
{
stFlags[i] = ST_NULL;
}
stFlags[iCol] = stFlag;

SORTCTX ctx = { iCol,stFlag };
qsort_s(m_softInfo.GetData(), m_softInfo.GetCount(), sizeof(SOFTINFO), SortCmp, &ctx);
return true;
}

static int __cdecl SortCmp(void *context, const void * p1, const void * p2)
{
SORTCTX *pctx = (SORTCTX*)context;
const SOFTINFO *pSI1 = (const SOFTINFO*)p1;
const SOFTINFO *pSI2 = (const SOFTINFO*)p2;
int nRet = 0;
switch (pctx->iCol)
{
case 0://name
nRet = wcscmp(pSI1->pszName, pSI2->pszName);
break;
case 1://score
{
float fCmp = (pSI1->fScore - pSI2->fScore);
if (fabs(fCmp) < 0.0000001) nRet = 0;
else if (fCmp > 0.0f) nRet = 1;
else nRet = -1;
}
break;
case 2://size
nRet = (int)(pSI1->dwSize - pSI2->dwSize);
break;
case 3://install time
nRet = wcscmp(pSI1->pszInstallTime, pSI2->pszInstallTime);
break;
case 4://user time
nRet = wcscmp(pSI1->pszUseTime, pSI2->pszUseTime);
break;

}
if (pctx->stFlag == ST_UP)
nRet = -nRet;
return nRet;
}
};

在项目设置中把优化的相关部分去掉即可。

  • c++常规:调试信息格式:选 程序数据库(/Zi)或(/ZI), 注意:如果是库的话,只能(Zi)
  • c++优化:优化: 选  禁止(/Od)
  • 连接器:调试:生成调试信息: 选  是 (/DEBUG)

静修一:挺尸式——行气通脉

20191120_064841.png

方法一】平躺,将双腿放置于瑜伽椅上,体会下背部的放松。双臂自然放置于体侧。觉知自己的呼吸,在每一次呼气时,将身体重量沉向背部,安全交给地面。

【方法二】将瑜伽毯的一头卷起 2-3 折,横放于腋窝下方的中背部。如下图

20191120_064857.png

可双腿伸展平卧,也可以延续“方法一”的卧法。觉知呼吸中胸腔的变化,体会这样的卧姿 5 分钟后呼吸的改变。

20191120_064909.png

仰卧挺尸式,在瑜伽中,并不等同于睡觉。而是充满觉知的观照。观照身体与呼吸的每一点变化。而在中国传统运动中,也常以仰卧之姿来行气通脉。

挺尸式不建议在柔软的床上进行,床垫有弹性不利于舒展。

阅读全文 »

自适应满屏

CSS 方面:去掉所有元素的外间距、内边距,html 和 body 宽高设为 100%,canvas 元素 display 设为 block
JS 方面:监听窗口的 resize 事件,在窗口大小改变的同时调整 canvas 的大小。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="jquery-3.1.1.js"></script>
<style>
* {
margin: 0;
padding: 0;
}
html, body {
height: 100%;
width: 100%;
}
canvas {
display: block;
background: #D6F8FF;
}
</style>
<script type="text/javascript">
$(function() {
//添加窗口尺寸改变响应监听
$(window).resize(resizeCanvas);
//页面加载后先设置一下canvas大小
resizeCanvas();
});

//窗口尺寸改变响应(修改canvas大小)-20 会两边留白一部分
function resizeCanvas() {
$("#canvas").attr("width", $(window).get(0).innerWidth- 20) ;
$("#canvas").attr("height", $(window).get(0).innerHeight- 20) ;
};
</script>
</head>
<body>
<canvas id="canvas" style="background: #D6F8FF"></canvas>
</body>
</html>

如果字体模糊

var getPixelRatio = function (context) {
var backingStore = context.backingStorePixelRatio ||
context.webkitBackingStorePixelRatio ||
context.mozBackingStorePixelRatio ||
context.msBackingStorePixelRatio ||
context.oBackingStorePixelRatio ||
context.backingStorePixelRatio || 1;
return (window.devicePixelRatio || 1) / backingStore;
};

var ratio = getPixelRatio(ctx);
context.fillStyle = 'red'
ctx.font = "14px Arial";
ctx.fillText("5分钟 15分钟 30分钟 60分钟 日线 周线 月线 季线 半年线 年线", 20 * ratio, 20 * ratio);

create backend account

python manage.py createsuperuser

Username (leave blank to use ‘sh’): <admin登陆账号>
Email address:  <你的邮箱地址>
Password: <密码>
Password (again): <确认密码>

html 中引用js等静态资源

settings.py 文件尾部添加

STATIC_URL = '/static/'
HERE = os.path.dirname(os.path.abspath(__file__))
HERE = os.path.join(HERE, '../')
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
os.path.join(HERE, 'static/'),
)

html中引用

<script src="../static/js/main.js"></script>

RESTful api service

pip install djangorestframework

Declare it in INSTALED_APPS on settings.py

INSTALLED_APPS = [
#...
'rest_framework'
]

Install django-rest-framework-mongoengine Dependencies

pip install mongoengine
pip install django-rest-framework-mongoengine

使用 mongodb

安装 djongo 来操作
pip install djongo

settings.py 里面修改如下。

DATABASES = {
'default': {
'ENGINE': 'djongo',
'NAME': 'mongoTest',
'HOST':'mongodb://admin:admin@localhost/mongoTest',
'USER':'admin',
'PASSWORD':'admin'

}
}

// 这里必须,否则会出错
import mongoengine
mongoengine.connect('mongoTest', host='localhost:27017')

建完库之后,更新一下表结构

python manage.py migrate
python manage.py createsuperuser

转载记录一下
作者:果汁凉茶丶
链接:https://www.jianshu.com/p/7bb4896be61c
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

Canvas 和 SVG 都是 HTML5 中推荐的也是主要的 2D 图形绘制技术

Canvas 提供画布标签和绘制 API,技术比较新,注重栅格图像处理。

SVG 是一套独立的矢量图形语言,成为 W3C 标准已经有十几年,发展缓慢。

20191117_103836.png

Canvas 基于像素,提供 2D 绘制函数,是一种 HTML 元素类型,依赖于 HTML,只能通过脚本绘制图案;

SVG 为矢量图,提供一系列图形元素(Rect,Path,Circle,Line…);还有完整的动画,时间机制,本身就能独立使用,也可以嵌入到 HTML 中。

20191117_103900.png

适用场景

Canvas 提供功能更原始,动态渲染和大数据量绘制

依赖分辨率
不支持事件处理器
弱的文本渲染能力
能够以.png 或 .jpg 格式保存结果图像
最适合图像密集型游戏,其中的许多对象会被频繁的重绘。

SVG 功能更完善,适合静态图片展示,高保证文档查看和打印的应用场景;

不依赖分辨率
支持事件处理器
最适合带有大型渲染区域的应用程序(比如谷歌地图)
复杂度高会减慢渲染速度(任何过度使用 DOM 的应用都不快)
不适合游戏应用

这本书还不错,比较系统的讲了如何应付负面情绪,并且给出了具体的操作建议。推荐阅读
正好微信读书有免费阅读体验,就看了一下,全书 365 页,稍微厚点。 用了 2.5 小时看完
还需要反复的看几遍,加深理解。

首先要知道,情绪主宰着你的健康,这个非常有意义。
然后要认识到人的 6 种基本需求情绪

20191116_214244.png 20191116_230308.png

方法比较简单实用,但是因为还没有通过操作获得实质性的结果,所以目前不好说是否可行。
书不厚 171 页,看一下也无妨。

原理就是激活血清素,平衡脑内神经冲动。

下面的两个实操方法:

  1. 日光浴 5-30 分钟,早上最好,激活血清素
  2. 韵律运动,5-30 分钟,激活血清素

这里面韵律运动,指的是有节奏的运动都可以,咀嚼口香糖也算,但是要注意一点,就是头脑要集中在运动上,不能分心,比如看电视,看书,这些都会激活工作脑,影响激活血清素

20191115_215155.png 20191115_215213.png 20191115_215231.png 20191115_215244.png

log4rs是一个高效的日志库框架,借鉴了 java 的 Logback 和 log4j。
提供了输出到文件和控制台两种方式。
输出到文件时,你可能需要限制文件大小,文件拆分,文件回滚功能,这些log4rs都提供了。