Skip to content

Instantly share code, notes, and snippets.

@zhiyelee
zhiyelee / animal_rabbit.js
Last active August 29, 2015 13:56
__proto__
var animal = { eats: true }
var rabbit = { jumps: true }
rabbit.__proto__ = animal // inherit
console.log(rabbit.eats) // true
var animal = { eats: true }
rabbit = Object.create(animal);
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="instanceof cross iframe" />
<meta charset="utf-8">
<title>instanceof cross iframe</title>
</head>
<body>
<iframe id="fr" ></iframe>
@zhiyelee
zhiyelee / description.markdown
Last active August 29, 2015 13:57
gView sample -- this description will be showed in the head of the page and used as the title. I just want to make this description long enough.

View gists in a more grace page.

Usage

visit http://g.zhiye.li/:gistid to view the gist, eg

// for below gitst 
https://gist.github.com/zhiyelee/9403314
@zhiyelee
zhiyelee / 236-a.js
Last active August 29, 2015 13:59
codeforces
// http://codeforces.com/contest/236/problem/A
function judge(str) {
var arr = str.split('');
var obj = {};
var len = 0;
for (var i = 0; i < arr.length; i++) {
if (!obj[arr[i]]) {
obj[arr[i]] = 1;
len ++;
@zhiyelee
zhiyelee / README.md
Last active August 29, 2015 14:00
Introduction to YUI Test

Introduction to the YUI Test

@zhiyelee
zhiyelee / crc_and_md5.md
Last active August 29, 2015 14:04
When is CRC more appropriate to use than MD5/SHA1?

When is it appropriate to use CRC for error detection versus more modern hashing functions such as MD5 or SHA1? Is the former easier to implement on embedded hardware?

http://stackoverflow.com/questions/996843/when-is-crc-more-appropriate-to-use-than-md5-sha1

by @defines http://stackoverflow.com/a/996873/775783
CRC works fine for detecting random errors in data that might occur, for example, from network interference, line noise, distortion, etc.

CRC is computationally much less complex than MD5 or SHA1. Using a hash function like MD5 is probably overkill for random error detection. However, using CRC for any kind of security check would be much less secure than a more complex hashing function such as MD5.

@zhiyelee
zhiyelee / st.md
Last active August 29, 2015 14:08
Why do Unix man pages use double backticks in place of double quotes?

Original link in stackoverflow: http://unix.stackexchange.com/q/73989/87921

I've noticed that man pages and other documents formatted by Unix utilities often use double backticks `` followed by double single quotes '' to wrap quoted phrases instead of the double quote character ". Single quotes are similarly replaced. Why is this?

Here are a couple examples, from the man page for grep:

 To find all occurrences of the pattern `.Pp' at the beginning of a line:

       $ grep '^\.Pp' myfile
@zhiyelee
zhiyelee / npm_folder_structures.md
Last active August 29, 2015 14:10
Cycles, Conflicts, and Folder Parsimony - NPM Folder Structures

Cycles are handled using the property of node's module system that it walks up the directories looking for node_modules folders. So, at every stage, if a package is already installed in an ancestor node_modules folder, then it is not installed at the current location.

Consider the case above, where foo -> bar -> baz. Imagine if, in addition to that, baz depended on bar, so you'd have: foo -> bar -> baz -> bar -> baz .... However, since the folder structure is: foo/node_modules/bar/node_modules/baz, there's no need to put another copy of bar into .../baz/node_modules, since when it calls require("bar"), it will get the copy that is installed in foo/node_modules/bar.

This shortcut is only used if the exact same version would be installed in multiple nested node_modules folders. It is still possible to have a/node_modules/b/node_modules/a if the two "a" packages are different versions. However, without repeating the exact same package multiple times, an infinite regress will always be pr

@zhiyelee
zhiyelee / Makefile
Last active August 29, 2015 14:23 — forked from isaacs/Makefile
# Hello, and welcome to makefile basics.
#
# You will learn why `make` is so great, and why, despite its "weird" syntax,
# it is actually a highly expressive, efficient, and powerful way to build
# programs.
#
# Once you're done here, go to
# http://www.gnu.org/software/make/manual/make.html
# to learn SOOOO much more.
@zhiyelee
zhiyelee / post-receive.sh
Created March 5, 2012 10:18
hooks/post-receive.sh
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a she ll session *as a function*
GEM_PATH=$GEM_PATH:/usr/local/rvm/gems/ruby-1.9.2-p290
PATH=$PATH:/usr/local/rvm/gems/ruby-1.9.2-p290/bin
GIT_WORK_TREE=$HOME/octopress/ git checkout -f
cd $HOME/octopress/
bundle install
bundle exec rake generate