koa-static组件的使用
koa-static组件的使用const path = require('path');app.use(require('koa-static')(path.join(__dirname, './static'), { maxAge: 365 * 24 * 60 * 60,extensions:true}));npm install koa-static --save
Apache之.htaccess文件配置允许跨域
设置允许跨域头Header set Access-Control-Allow-Origin 允许的请求地址设置域名访问<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / #-判断规则,若有多个域名则写多条.(除了以下域名,其他均不允许访问) rewritecond %{http_host} !^tesy.com$ [nc] #rewritecond %{http_host} !^testa1.pw$ [nc] #rewritecond %{http_host} !^testa2.pw$ [nc] #-禁止规则 rewriterule ^.* - [F,L]</IfModule>
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.conf;}
C/C++开发求素数的Nodejs插件
使用C语言开发去素数的nodejs插件,c语言代码如下#include <node.h>#include <stdlib.h>namespace Prime {using v8::FunctionCallbackInfo;using v8::Isolate;using v8::Local;using v8::Object;using v8::String;using v8::Value;using v8::Exception;using v8::Number;// void Method(const FunctionCallbackInfo<Value>& args) {// Isolate* isolate = args.GetIsolate();// args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world"));// }void Prime(const FunctionCallbackInfo<Value>& args){ Isolate* isolate = args.GetIsolate(); int i,
linux node的编译安装
linux下编译安装node:yum install gccyum install gcc-c++yum install openssl*yum install -y bzip2*yum -y install python./configure --prefix=/usr/local/nodemake && make installln -s /usr/local/node/bin/* /usr/local/bincd /usr/local/node/lib/node_modules/npm./configuremake && make install2、修改profile文件: #vi /etc/profile 在里面加入: export PATH="$PATH:/opt/au1200_rm/build_tools/bin" 让环境变量立即生效需要执行如下命令: #source /etc/profile ln -s /usr/bin/npm /usr/local/node/bin/npm
async与await
async与await的用法function test(){ return new Promise((resolve, reject) => { mysql.query(sql, (error, result, fields) => { if (error) { reject(error); } else { resolve([result, fields]); } }) });}async function exceTest() { return await test();}var data = await exceTest();async的使用条件:必须是promise对象
java文件流操作
java文件流操作,源码如下:package code; import java.io.File; import java.io.IOException; public class IOStream { public static void main(String[] args) { File f = new File("F:\\test.txt"); //取得文件路径 System.out.println("文件路径为:" + f.getAbsolutePath()); //得到文件的大小 System.out.println("文件的大小为:" + f.length()); System.out.println("文件可读不:" + f.canRead()); File f1=new File("F:\\test1.txt"); if(!f1.exists()) { //可以创建 try { f1.createNewFile(); } catch (IOException e) { // TOD
java连接sql server数据库
java连接sql server数据库package code; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Statement; public class DbAdapter { Connection con; Statement sm; ResultSet rs; PreparedStatement ps=null; public static void main(String[] args) { DbAdapter s = new DbAdapter(); String sql = "update users set username='1' where username='1'"; s.LinkSql(sql); } public boolean LinkSql(String sql) { try { Cl
java求水仙花数
水仙花数是指一个 n 位正整数 ( n≥3 ),它的每个位上的数字的 n 次幂之和等于它本身。(例如:1^3 + 5^3+ 3^3 = 153)。什么是水仙花数水仙花数只是自幂数的一种,严格来说3位数的3次幂数才称为水仙花数。附:其他位数的自幂数名字一位自幂数:独身数两位自幂数:没有三位自幂数:水仙花数四位自幂数:四叶玫瑰数五位自幂数:五角星数六位自幂数:六合数七位自幂数:北斗七星数八位自幂数:八仙数九位自幂数:九九重阳数十位自幂数:十全十美数package code; /** * * @author Smart * */ public class Narcissistic { public static void main(String[] args) { int i,j,k,m; for(m = 100; m < 1000; m++) { i = m%10; j = (( m-i ) % 100 ) / 10; k = ( m - j * 10 - i ) / 100; if( (k * k * k + j * j * j + i
java程序求素数
java求素数package code; /** * * @author Smart * */ public class Prame { /** * @param args the command line arguments */ public static void main(String[] args) { int a,b; a=0; b=0; for (int i = 101; i <= 200; i++) { for(int j = 2; j < i; j++) { if( i%j == 0 ) a++; } if ( a < 1 ) { b++; System.out.println(i); a = 0; } else a = 0;
java之计算器的实现
java实现计算器程序,代码如下:package code; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.Font; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.regex.Pattern; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.JTextField; /** * * @author Smart * */ p
java之九九乘法表的输出
九九乘法表输出,代码如下:package code; /** * * @author Smart * */ public class Multiply { public static void main(String[] args) { int i,j; for(i = 1; i < 10; i++) { for(j = 1; j <= i; j++) { System.out.print(j + "*" + i + "=" + i * j + "\t"); } System.out.println(""); } } }输出结果如下:1*1=1 1*2=2 2*2=4 1*3=3 2*3=6 3*3=9 1*4=4 2*4=8 3*4=12 4*4=16 1*5=5 2*5=10 3*5=15 4*5=20 5*5=25 1*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36 1*7=7 2