🔍 登录 注册
分类:
标签: 共 1222 篇文章

NodeJs创建Web服务

**用法** ``` node [options] [v8 options] [script.js | -e "script"] [arguments] ``` 请看命令行选项文档获取nodejs不同选项的信息和脚本运行方法。 **例子** 一个使用nodejs编写的web服务,输出'hello world': ``` const http = require('http');const hostname = '127.0.0.1';const port = 3000;const server = http.createServer((req, res) => { res.statusCode = 200; res.setHeader('Content-Type', 'text/plain'); res.end('Hello World\n');});server.listen(port, hostname, () => { console.log(`Server running at http://${hostname}:${port}/`);}); ``` 运行

大 大苹果 2017/6/9 👍 0 ⭐ 0 💬 0

JavaScript操作Cookie

设置cookie ``` document.cookie="name="+username; ``` **JS读取cookie:** ``` var username=document.cookie.split(";")[0].split("=")[1]; //JS操作cookies方法! //写cookies function setCookie(name,value) { var Days = 30; var exp = new Date(); exp.setTime(exp.getTime() + Days*24*60*60*1000); document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString(); } ``` **读取cookies** ``` function getCookie(name) { var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)"); if(arr=doc

大 大苹果 2017/6/9 👍 0 ⭐ 0 💬 0

文件上传的两种方式

## [form上传文件2种方式]() <small>2015-07-11 15:05 by ddxueyu, 6482 阅读, 1 评论, [收藏](http://www.cnblogs.com/ddxueyu/archive/2015/07/11/4638414.html#), [编辑](https://i.cnblogs.com/EditPosts.aspx?postid=4638414)</small> **示例1:** 表单里有图片/文件的上传 ``` <form enctype="multipart/form-data" method="post"><input type="file" name="uploadfile"/></form> ``` multipart/form-data 是上传二进制数据 form里面的input的值以**2进制**的方式传过去,所以这里要明白,使用这种格式以后,**后台request就获取不到数据了**。 enctype属性是设置提交数据的格式,指定将数据回发到服务器时浏览器使用的编码类型。 enctype值: appli

大 大苹果 2017/6/9 👍 0 ⭐ 0 💬 0

Git 的安装与权限的控制 (使用Gitolite)

一: Git的安装(centos) (参考 http://www.ccvita.com/tag/git/) 注意: A: Git 没有什么server端和client端之分,Git属于分布式版本控制系统. B: Git 安装步骤 ``` yum install curl curl-devel zlib-devel openssl-devel perl cpio expat-devel gettext-devel wget https://www.kernel.org/pub/software/scm/git/git-2.6.2.tar.gz autoconf ./configure make make install ``` 二: 使用Gitolite来控制Git的权限 (参考 http://blog.it985.com/12344.html) 我使用三台机器来验证gitolite对git权限的控制 1: **192.168.1.250** centos (下文用"**250**机器"称呼) #这个机器作为存放最终版代码,也就所有项目的代码都会提交到这个机器. 2: *

大 大苹果 2017/6/19 👍 0 ⭐ 0 💬 0

NodeJs之co yield的使用,将异步转同步

例如:fs.writeFile是异步方法 ``` function test(){ return co(function *() { yield (() => new Promise((resolve, reject) => { fs.writeFile(path, '', (err) => { if (err) return reject(err); resolve(1); }); }))(); return; });} ``` 调用test; ``` co(function *() { let res = yield test(); console.log(res);}) ```

大 大苹果 2017/6/20 👍 0 ⭐ 0 💬 0

node v6.9.2下使用async/await的方法

使用babel,配置.babelrc ``` { "presets": [ ["env", { "targets": { "node": true } }] ]} ``` 相关依赖package.json ``` { "name": "xxxx", "version": "1.0.0", "description": "xxxx", "main": "./public/index.js", "scripts": { "test": "node ./public/index.js" }, "keywords": [ "xxxx" ], "author": "xxx", "license": "ISC", "devDependencies": { "babel-cli": "^6.24.1", "babel-plugin-transform-async

大 大苹果 2017/7/5 👍 0 ⭐ 0 💬 0

JavaScript的面相对象编程之封装

Javascript是一种基于对象(object-based)的语言,你遇到的所有东西几乎都是对象。但是,它又不是一种真正的面向对象编程(OOP)语言,因为它的语法中没有class(类)。 那么,如果我们要把"属性"(property)和"方法"(method),封装成一个对象,甚至要从原型对象生成一个实例对象,我们应该怎么做呢? 一、 生成实例对象的原始模式 假定我们把猫看成一个对象,它有"名字"和"颜色"两个属性。 ``` var Cat = {     name : '',   color : '' } ``` 现在,我们需要根据这个原型对象的规格(schema),生成两个实例对象。 ``` var cat1 = {}; // 创建一个空对象 cat1.name = "大毛"; // 按照原型对象的属性赋值 cat1.color = "黄色"; var cat2 = {}; cat2.name = "二毛"; cat2.color = "黑色"; ``` 这就是最简单的封装了,把两个属性封装在一个对象里面。但是,这样的写法有两个缺点,一是如果多生成几个实例

大 大苹果 2017/6/9 👍 0 ⭐ 0 💬 0

git的使用笔记

git的使用: ``` usage: git [--version] [--help] [-C <path>] [-c name=value] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path] [-p | --paginate | --no-pager] [--no-replace-objects] [--bare] [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>] <command> [<args>] available git commands in '/usr/libexec/git-core' add checkout cvsexportcommit for-each-ref init-db

大 大苹果 2017/6/9 👍 0 ⭐ 0 💬 0

SQl插入数据时判断是否存在,存在则跳过,不存在则插入

SQl插入数据时判断是否存在,存在则跳过,不存在则插入 ``` insert into test(name) select 'test1' from DUAL WHERE NOT EXISTS(SELECT `name` from test where name = 'test1'); ``` test是表明,test1是要插入的内容,name是对应的字段 首次执行结果 ``` [SQL] insert into test(name) select 'test1' from DUAL WHERE NOT EXISTS(SELECT `name` from test where name = 'test1'); 受影响的行: 1 时间: 0.002s ``` 第二次执行结果 ``` [SQL] insert into test(name) select 'test1' from DUAL WHERE NOT EXISTS(SELECT `name` from test where name = 'test1'); 受影响的行: 0 时间: 0.002s ```

大 大苹果 2017/6/8 👍 0 ⭐ 0 💬 0

MYsql 出现This function has none of DETERMINISTIC, NO SQL解决办法

完整错误描述: ![blob.png](/ueditor/php/upload/image/20170608/1496889613951734.png) This function has none of DETERMINISTIC, NO SQL解决办法 创建存储过程时 出错信息: ERROR 1418 (HY000): This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you \*might\* want to use the less safe log\_bin\_trust\_function\_creators variable) 原因: 这是我们开启了bin-log, 我们就必须指定我们的函数是否是 1 DETERMINISTIC 不确定的 2 NO SQL 没有SQl语句,当然也不会修改数据 3 READS SQL DATA 只是读取数据,当然也不会修改数据 4 MOD

大 大苹果 2017/6/8 👍 0 ⭐ 0 💬 0

PHP的五种设计模式

工厂模式: 最初在设计模式 一书中,许多设计模式都鼓励使用松散耦合。要理解这个概念,让我们最好谈一下许多开发人员从事大型系统的艰苦历程。在更改一个代码片段时,就会发生问题,系统其他部分 —— 您曾认为完全不相关的部分中也有可能出现级联破坏。 该问题在于紧密耦合 。系统某个部分中的函数和类严重依赖于系统的其他部分中函数和类的行为和结构。您需要一组模式,使这些类能够相互通信,但不希望将它们紧密绑定在一起,以避免出现联锁。 在大型系统中,许多代码依赖于少数几个关键类。需要更改这些类时,可能会出现困难。例如,假设您有一个从文件读取的 User 类。您希望将其更改为从数据库读取的其他类,但是,所有的代码都引用从文件读取的原始类。这时候,使用工厂模式会很方便。 工厂模式 是一种类,它具有为您创建对象的某些方法。您可以使用工厂类创建对象,而不直接使用 new。这样,如果您想要更改所创建的对象类型,只需更改该工厂即可。使用该工厂的所有代码会自动更改。 下面是工厂模式的一个示例。 ``` <?php interface IUser { function getName(); }

大 大苹果 2017/6/7 👍 0 ⭐ 0 💬 0

nginx配置允许跨域访问

nginx配置允许跨域访问 ``` location ~ .*\.(php|php5)?$ { add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow-Headers' 'X-Requested-With, Content-Type, Authorization'; add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS'; if ($request_method = 'OPTIONS') {return 204;} #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.co

大 大苹果 2017/6/5 👍 0 ⭐ 0 💬 0