Skip to content

Instantly share code, notes, and snippets.

View Natumsol's full-sized avatar
🎯
Focusing

青岚 Natumsol

🎯
Focusing
View GitHub Profile
@Natumsol
Natumsol / flatten.js
Created April 1, 2015 01:48
flatten a JavaScript array
function flatten(arr) {
var result = [];
for(var i = 0, length = arr.length; i < length; i ++ ){
var value = arr[i];
if(!Array.isArray(value)){
result.push(value);
} else {
result = result.concat(flatten(value));//递归调用
}
}

iPhone 通过微信内置浏览器访问网页时得到 User Agent 是:

Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_3 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Mobile/10B329 MicroMessenger/5.0.1

Android 通过微信内置浏览器访问网页时得到 User Agent 是:

Mozilla/5.0 (Linux; U; Android 2.3.6; zh-cn; GT-S5660 Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 MicroMessenger/4.5.255
define(function(require, exports, module) {
/**
* @param {[type]}
* @return {[type]}
*/
var code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
function strToBase64(bitString) {
var result = "";
var tail = bitString.length % 6;
@Natumsol
Natumsol / centos6.5_nginx
Created March 14, 2016 14:22 — forked from ifels/centos6.5_nginx
centos 6.5 nginx安装与配置
第一步,在/etc/yum.repos.d/目录下创建一个源配置文件nginx.repo:
cd /etc/yum.repos.d/
vim nginx.repo
填写如下内容:
[nginx]
name=nginx repo
@Natumsol
Natumsol / nginx.sh
Created March 14, 2016 14:41
CentOS Nginx 启动脚本
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: NGINX is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
@Natumsol
Natumsol / LazyMan.js
Created September 10, 2016 02:41
LazyMan
function _LazyMan(name) {
this.tasks = [];
var self = this;
var fn =(function(n){
var name = n;
return function(){
console.log("Hi! This is " + name + "!");
self.next();
}
@Natumsol
Natumsol / render.js
Last active November 23, 2016 09:14
markdown render function
function render(data) {
// data = data.replace(/^ {1,}/g, "&nbsp;");
data = data.split("\n").map(function (value) {
return value.replace(/^[ ]{1,}/g, function (match) {
return (new Array(match.length * 4 + 1)).join("&nbsp;");
})
}).join("\n")
var html = md.render(data).replace(/\n/g, "<br />");
$("#target").html(html.replace(/&amp;/g, "&"));
@Natumsol
Natumsol / download_egghead_videos.md
Created December 7, 2016 15:29 — forked from ldong/download_egghead_videos.md
download egghead videos

Download videos from egghead

Go to the egghead website, i.e. Building a React.js App

run

$.each($('h4 a'), function(index, video){
  console.log(video.href);
});
@Natumsol
Natumsol / poll.js
Last active April 14, 2017 01:03
轮询 Demo
var URL= "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22nome%2C%20ak%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";
/* 响应处理函数 */
function dealWithData(data) {
// 处理响应数据
console.log(data, Date.now());
setTimeout(send, 1000); // 一秒后,再次轮询一次
}
/* 发送请求 */
function send() {
@Natumsol
Natumsol / keywordStatistics.js
Created April 14, 2017 01:07
统计关键字词频
/**
* @param article String
* @param keywords Array
*/
function statistics(articles, keywords) {
var frequency = {}
, alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
for (var i = 0; i < keywords.length; i++) {
frequency[keywords[i]] = 0;
}