Skip to content

Instantly share code, notes, and snippets.

/**
* merge sort
**/
var arr = [8,7,9,30,13,8,99,124, 5];
//var arr = [1,10,9];
var newArr = [];
var ii = 0;
@zhiyelee
zhiyelee / .gitignore
Last active December 10, 2015 17:20
mocha_sinon_chai TEST DEMO
node_modules
@zhiyelee
zhiyelee / getip.php
Created March 31, 2012 02:41
twtter get ip
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Get IP</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<?php
$domains = array('api.twitter.com', 'twitter.com');
@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
@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 / 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 / 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 / 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 / README.md
Last active August 29, 2015 14:00
Introduction to YUI Test

Introduction to the YUI Test

@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 ++;