Skip to content

Instantly share code, notes, and snippets.

View ziyoudefeng's full-sized avatar

ziyoudefeng

  • XiDian university
  • Xi'an
View GitHub Profile
@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 / Einstein.java
Created November 20, 2012 11:57 — forked from chenshuo/Einstein.java
Einstein's Puzzle
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import JaCoP.constraints.Alldifferent;
import JaCoP.constraints.Distance;
import JaCoP.constraints.XeqC;
import JaCoP.constraints.XeqY;
import JaCoP.constraints.XplusCeqZ;
import JaCoP.core.Domain;
@ziyoudefeng
ziyoudefeng / typoglycemia.cc
Created November 6, 2012 01:39 — forked from chenshuo/typoglycemia.cc
Typoglycemia
// answer to http://blog.zhaojie.me/2012/11/how-to-generate-typoglycemia-text.html
#include <algorithm>
#include <iostream>
#include <string>
#include <assert.h>
#include <ctype.h>
using std::string;
void randomizeWord(char* str, int len)