Skip to content

Instantly share code, notes, and snippets.

View hugg95's full-sized avatar
💭
等雨来

dengdeng hugg95

💭
等雨来
View GitHub Profile
@hugg95
hugg95 / keepalive
Created September 29, 2016 03:17 — forked from shi-yan/keepalive
Correct way to set tcp socket keepalive on Win, Mac and Linux. Verified with Wireshark.
void setTcpKeepalive(SOCKET &sockfd)
{
const uint32_t keepaliveIntervalSec = 10;
#ifdef _WIN32
tcp_keepalive keepaliveParams;
DWORD ret = 0;
keepaliveParams.onoff = 1;
keepaliveParams.keepaliveinterval = keepaliveParams.keepalivetime = keepaliveIntervalSec * 1000;
WSAIoctl(sockfd, SIO_KEEPALIVE_VALS, &keepaliveParams, sizeof(keepaliveParams), NULL, 0, &ret, NULL, NULL);
@hugg95
hugg95 / randomColor.less
Created September 20, 2016 03:37 — forked from juanbrujo/randomColor.less
Mixin to generate random color in LESS
.randomColor(){
@randomColor: `Math.floor(Math.random()*16777215).toString(16)`;
@colorHex: e(@randomColor);
@color: ~"#@{colorHex}";
}
// USE
body {
.randomColor();
@hugg95
hugg95 / html5-formdata-polyfilll.js
Created August 19, 2016 03:31 — forked from Rob--W/html5-formdata-polyfilll.js
FormData polyfill for Web Workers.
/*
* FormData for XMLHttpRequest 2 - Polyfill for Web Worker
* (c) 2014 Rob Wu <rob@robwu.nl>
* License: MIT
* - append(name, value[, filename])
* - XMLHttpRequest.prototype.send(object FormData)
*
* Specification: http://www.w3.org/TR/XMLHttpRequest/#formdata
* http://www.w3.org/TR/XMLHttpRequest/#the-send-method
* The .append() implementation also accepts Uint8Array and ArrayBuffer objects
@hugg95
hugg95 / why-curry-helps.md
Created July 22, 2016 01:55 — forked from jcouyang/why-curry-helps.md
为什么要柯里化(why-curry-helps)slide http://git.io/why-curry-helps 📈

还记得 Haskell Curry吗,

多巧啊, 人家姓 Curry 名 Haskell, 难怪 Haskell 语言会自动柯里化, 呵呵. 但是不奇怪吗, 为什么要柯里化呢. 为什么如此重要导致 Haskell 会默认自动柯里化所有函数, 不就是返回一个部分配置好的函数吗.

我们来看一个 Haskell 的代码.

max 3 4
(max 3) 4
@hugg95
hugg95 / tornado的mysql异步操作
Created July 21, 2016 10:18 — forked from stableShip/tornado的mysql异步操作
tornado的mysql异步操作
#在tornado中使用异步mysql操作
>在使用tornado框架进行开发的过程中,发现tornado的mysql数据库操作并不是一步的,造成了所有用户行为的堵塞.tornado本身是一个异步的框架,要求所有的操作都应该是异步的,但是数据库这一层就把整个服务器都拖住了.
##查找到的解决办法:
1. 使用异步的mysql操作库. 查找了一下,有两个比较完善的异步操作库
一个是[AsyncTorndb](https://github.com/mayflaver/AsyncTorndb),国人自己写的异步操作,看了一下,好像不错的样子,但是没有响应的测试用例,不敢用.
一个是[Tornado-MySQL](https://github.com/PyMySQL/Tornado-MySQL)是对PyMySQL的异步化的一个库,测试用例,文档,都比较齐全,可以尝试使用.