Skip to content

Instantly share code, notes, and snippets.

View ziyoudefeng's full-sized avatar

ziyoudefeng

  • XiDian university
  • Xi'an
View GitHub Profile

Keybase proof

I hereby claim:

  • I am ziyoudefeng on github.
  • I am hzshao (https://keybase.io/hzshao) on keybase.
  • I have a public key ASA99Osnhqmitdd4gmbG_Qn7jApHosjjF7dcLW6fmTQtNQo

To claim this, I am signing this object:

@ziyoudefeng
ziyoudefeng / type.js
Created November 16, 2013 14:10 — forked from jonbretman/type.js
(function (root) {
var type = function (o) {
// handle null in old IE
if (o === null) {
return 'null';
}
// handle DOM elements
// answer to http://weibo.com/1915548291/z2UtyzuvQ
// see also http://www.cnblogs.com/baiyanhuang/archive/2012/11/11/2764914.html
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <boost/noncopyable.hpp>
#include <boost/ptr_container/ptr_vector.hpp>
#include <fstream>
#include <iostream>

Learn JavaScript concepts with the Chrome DevTools

Authored by Peter Rybin , Chrome DevTools team

In this short guide we'll review some new Chrome DevTools features for "function scope" and "internal properties" by exploring some base JavaScript language concepts.

Closures

Let's start with closures – one of the most famous things in JS. A closure is a function, that uses variables from outside. See an example:

#include <assert.h>
#include <stdio.h>
#include <vector>
int buysell(const std::vector<int>& prices)
{
assert(!prices.empty());
size_t lowestBuy = 0;
size_t lowestBuySoFar = 0;
size_t highestSell = 0;
@ziyoudefeng
ziyoudefeng / waiter.h
Created September 4, 2013 01:19 — forked from chenshuo/waiter.h
#include <boost/noncopyable.hpp>
#include <pthread.h>
#include <stdlib.h>
// a superfluous check for pedantic people
inline void CHECK_SUCCESS(int ret)
{
if (ret != 0)
{
abort();
@ziyoudefeng
ziyoudefeng / gist:4618854
Last active December 11, 2015 15:08
面向对象的本质
摘自:http://my.oschina.net/HardySimpson/blog/38985
1:对象的生命周期 、数据访问的权限。我在实际编码中发现有下面几种
数据权限 生命周期
数据对象 直接读写内部数据 完成一次操作
普通对象 直接读,通过方法或函数来写 按需使用
/* simple strstr: use strchr to look for first character */
/* will change pointer value: str1*/
char *strstr(const char *str1, const char *str2)
{
int n;
n = strlen(str2);
for (;;) {
str1 = strchr(str1, str2[0]);
@ziyoudefeng
ziyoudefeng / 1markov.c
Last active December 10, 2015 03:58
这里是《程序设计实践》第四章-接口里面的一些代码。个人觉得这些代码还需要再看看,理解理解接口(库函数)的设计。 PS:如需要重新阅读,下次读英文版这章的内容。 读中文版的感觉有点痛苦!思维会混乱。
/* 运行结果好像不正确 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
enum {
NPREF = 2,
NHASH = 4093,
MAXGEN = 10000
};
@ziyoudefeng
ziyoudefeng / getline.rb
Created December 13, 2012 13:19
Programming Ruby
#大多数Ruby语句会返回值,这意味着可以把它们当条件使用。例如,gets方法从标准输入流返回下一行,或者当到达文件结束时返回nil。
#因为Ruby在条件中把nil当作一个假值对待,可以像下面这样来处理文件中的行。
while line = gets
puts line.downcase
end