Skip to content

Instantly share code, notes, and snippets.

View GeekaholicLin's full-sized avatar
💭
I may be slow to respond.

void GeekaholicLin

💭
I may be slow to respond.
View GitHub Profile
@GeekaholicLin
GeekaholicLin / parity.md
Created July 16, 2016 15:34
奇偶检验码的编程思维转换

当我们使用纸和笔上使用我们人的思维来写出偶检验码,而不是编写程序来处理时,可以数'1'的个数来添加。

e.g. 1001001 需要传输这7位二进制数的时候

通过计算'1'的个数,可以知道第8位为'1'(从左往右,从1开始编号),也就是'10010011'。

但是当二进制数很长很长很长的时候,我们只能通过计算机的程序处理时,应该如何转换?

有两种办法

  • 将所有的位进行异或运算。利用的特性是奇数个‘1’进行异或运算时,结果依然为‘1’,所以加上运算结果的‘1’,刚好是偶数个。
@GeekaholicLin
GeekaholicLin / difference.md
Created July 17, 2016 07:59
动态网页、静态网页、动态文档、静态文档和活动文档的区别

动态网页和静态网页是对于用户(client)是否和服务器进行(server)交互而言。常见的静态网页是以.html.htm后缀名结尾的,而动态网页常见的有 以.aspx,.jsp,.php结尾,一般情况下需要与数据库打交道。

而动态文档、静态文档和活动文档与动态网页、静态网页没有必然的联系。(虽然有一点关系,比如静态网页属于静态文档的一种,但纯文档,比如Json和文本文件也属于静态文档),它们的划分依据并不一样。

  • 动态文档指的是,在用户对服务器进行请求,服务器的程序根据请求进行处理,创建动态文档返回服务器。(内容一旦在服务器创建返回则不会再改变)[program at the server creates a document and sends it to client.]
  • 静态文档指的是,在用户请求的时候,直接将请求的静态文档返回。(内容不会改变)[same file sent every request.]
  • 活动文档指的是,服务器返回程序文件副本,让浏览器来根据用户的请求进行变化。比如Java Applet。提供了从浏览器界面访问这些应用程序的功能的方法。只要用户运行活动文档程序,活动文档的内容就可以连续的改变。[ program sent from server and run on the client]

"A dynamic document is the product of a program run by a server as requested by a browser. An active document is the product of a program sent from the server to the client and run at the client site."

@GeekaholicLin
GeekaholicLin / js_debug
Last active August 19, 2016 08:43
js debug
[属性改变时中断调试](http://stackoverflow.com/questions/3401298/how-do-i-find-which-javascript-is-changing-an-elements-style)
@GeekaholicLin
GeekaholicLin / external.md
Created August 25, 2016 12:43
js 学习笔记(杂)

函数对外提供接口的一个方法是,将函数内部的变量、内部函数挂载到window全局对象下即可

(function(){
 function $(){
  //do sth.
 }
  window.$ = $;
})();
$();//succeed
@GeekaholicLin
GeekaholicLin / jq_instantiation,md
Last active December 9, 2016 14:34
jQuery instantiation
在跟着视频一起阅读jQuery的2.0.3源码的时候,发现一个'有意思'的地方,或者说巧妙的地方。
css()等方法是在jQuery原型属性`prototype`的下面定义的,比如jQuery.prototype.css = function(){//do sth.}
但是,我们在调用css()方法的时候,首先使用`$()`[也就是`jQuery()`]获取到一个元素对象,从而调用,例如`$('#top').css();`。但是在源码当中,
当调用jQuery()的时候其实拿到的是init()构造函数的实例。而不是jQuery()构造函数的实例。【因为是jQuery()构造函数的实例,才会向上搜素到该实例的原型对象中的css()等方法】
```javascript
jQuery = function( selector, context ) {
@GeekaholicLin
GeekaholicLin / random_range.md
Created August 29, 2016 13:54
create a random number between min and max
function randomRange(myMin, myMax) {
 
  return Math.floor(Math.random()*(myMax-myMin+1)+myMin); 

}
@GeekaholicLin
GeekaholicLin / string_reversing.md
Created August 29, 2016 15:10
Two simple method achieve reversing the string
function reverseString(str) {
 //method 1.
  str = str.split('').reverse().join('');
  
  //method 2
  /*var str2 = "";
  for(var i = str.length-1;i>=0;i--){
    str2+=str.charAt(i);
 }
@GeekaholicLin
GeekaholicLin / js_Palindromes.md
Created August 29, 2016 15:33
js 去除标点符号/空格且忽略大小写的回文串判定
function palindrome(str) {
  // Good luck!
  // \W -->匹配所有的字母、数字、下划线以外的字符
  str = str.replace(/\W|_/g,'').toLowerCase();
  var arrMaxIndex = str.length -1;
  for(var i = 0;i <=arrMaxIndex/2;i++){
    if(str.charAt(i)!==str.charAt(arrMaxIndex-i)){
      return false;
 }
@GeekaholicLin
GeekaholicLin / titleCase.md
Created August 29, 2016 15:50
transfer the title of all the worlds in the sentence to uppercase
function titleCase(str) {
  var str1 = str.toLowerCase().replace(/\b(\w|')+\b/g, function(str){
  return str.substring(0,1).toUpperCase()+str.substring(1);
  }
  );
  return str1;
}
/*
 /\b(\w|')+\b/g
@GeekaholicLin
GeekaholicLin / sum_range.md
Created August 30, 2016 04:53
Sum All Numbers in a Range
function sumAll(arr) {
  var max = Math.max.apply(null,arr),
  /*How does Math.max.apply() work?See this answer in the Stackoverflow
  http://stackoverflow.com/questions/21255138/how-does-the-math-max-apply-work#answer-21255326
  */
      min = Math.min.apply(null,arr),
      count = max - min + 1,
      sum = ((max+min)*count/2);