Skip to content

Instantly share code, notes, and snippets.

View zdying's full-sized avatar

zhang zdying

View GitHub Profile
(function (exports) {
function urlsToAbsolute(nodeList) {
if (!nodeList.length) {
return [];
}
var attrName = 'href';
if (nodeList[0].__proto__ === HTMLImageElement.prototype || nodeList[0].__proto__ === HTMLScriptElement.prototype) {
attrName = 'src';
}
nodeList = [].map.call(nodeList, function (el, i) {
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
@zdying
zdying / puppeteer-amazon-list-example.js
Last active September 27, 2018 06:47
Puppeteer amazon list example.
// 引入puppeteer模块
const puppeteer = require('puppeteer');
// puppeteer内置的设备描述信息
const devices = require('puppeteer/DeviceDescriptors');
// 模拟iPhone 6 Plus
const iPhone6P = devices['iPhone 6 Plus'];
async function run() {
console.log('正在获取数据,请查看打开的浏览器窗口...');
// 启动浏览器并设置窗口大小
@zdying
zdying / modify_response.js
Last active March 15, 2018 08:22
modify response content
const fs = require('fs');
const path = require('path');
const http = require('http');
var server = http.createServer((req, res) => {
const oldEnd = res.end;
let body = [];
let isString = false;
@zdying
zdying / template.js
Created June 25, 2017 14:07
simple template engine
console.clear();
function render(template, data){
console.info('render ==>', template, data);
template = template.replace(/\{\{([#^])([^}]+?)\}\}(?:([\s\S]*?)\{\{\/(\2+?)\}\})?/g, function (match, ope, key, content, key1) {
if (key !== key1) {
throw Error(key + ' and ' + key1 + ' does not match.');
}
var value = getValue(data, key);
@zdying
zdying / proxy.js
Created June 25, 2017 07:00
proxy Node.js http/https request without any library
var http = require('http');
var options = {
// proxy server ip
hostname: '127.0.0.1',
// proxy server port
port: 5525,
// the request url (absolute path)
path: 'http://www.example.com/',
method: 'GET',
// should set Host header. or it will be `127.0.0.1:5525`
@zdying
zdying / step-flow-example.js
Created June 8, 2017 07:31
step-flow example
/**
* @file step-flow example
* @author zdyng
*/
'use strict';
const fs = require('fs');
const path = require('path');
const md5 = require('md5');
@zdying
zdying / ActionSheet.js
Created March 29, 2017 15:02
ActionSheetAndroid
/**
* @file ActionSheet API
* @author zdying
* @providesModule ActionSheet
*/
import React, {Component} from 'react';
import {Modal, Text, View, TouchableWithoutFeedback} from 'react-native';
export default class ActionSheet extends Component {
@zdying
zdying / color.js
Created February 13, 2017 05:32
控制台文本颜色
/**
* @file 控制台文本颜色
* @author zdying
*/
'use strict';
(function(){
var colorDisabled = process.argv.indexOf('--no-color') !== -1;
void
function() {
'use strict';
var http = require('http'),
url = require('url'),
net = require('net');
function printError(err, msg, url) {
console.log('%s %s: %s', new Date().toLocaleTimeString(), msg, url, err);
}