require

Why doesn't relative_require work on Ruby 1.8.6?

☆樱花仙子☆ 提交于 2019-11-27 17:30:13
问题 I'm learning Ruby (using version 1.8.6) on Windows 7. When I try to run the stock_stats.rb program below, I get the following error: C:\Users\Will\Desktop\ruby>ruby stock_stats.rb stock_stats.rb:1: undefined method `require_relative' for main:Object (NoMethodE rror) I have three v.small code files: stock_stats.rb require_relative 'csv_reader' reader = CsvReader.new ARGV.each do |csv_file_name| STDERR.puts "Processing #{csv_file_name}" reader.read_in_csv_data(csv_file_name) end puts "Total

浅谈前端工程化、模块化、组件化

泄露秘密 提交于 2019-11-27 16:32:41
什么是前端工程化、模块化、组件化? 前端工程化 工程化是一种思想而不是某种技术(当然为了实现工程化我们会用一些技术) 再用一句通俗的话来概括前端工程化:前端工程化就是用做工程的思维看待和开发自己的项目,而不再是直接撸起袖子一个页面一个页面开写 前端模块化 前端工程化是一个高层次的思想,而模块化和组件化是为工程化思想下相对较具体的开发方式,因此可以简单的认为模块化和组件化是工程化的表现形式。 模块化开发, 一个模块就是一个实现特定功能的文件,有了模块我们就可以更方便的使用别人的代码,要用什么功能就加载什么模块。 模块化开发的4点好处:   1 避免变量污染,命名冲突   2 提高代码复用率   3 提高维护性   4 依赖关系的管理 那具体什么是模块化呢?还是举简单的例子,我们要写一个实现A功能的JS代码,这个功能在项目其他位置也需要用到,那么我们就可以把这个功能看成一个模块采用一定的方式进行模块化编写,既能实现复用还可以分而治之,同理在写样式的时候,如果我们需要某种特殊的样式,会在很多地方应用,那么我们也可以采用一定的方式进行CSS的模块化,具体说来,JS模块化方案很多有AMD/CommonJS/UMD/ES6 Module等,CSS模块化开发大多是在less、sass、stylus等预处理器的import/mixin特性支持下实现的 总体而言, 模块化不难理解

第一个gulp程序

不想你离开。 提交于 2019-11-27 15:01:35
说起来惭愧,一直用公司内部的工具,没有用这些红得发紫的东西。今天东抄西拼终于搞出第一个gulp应用。gulp是做什么的,好处在哪儿我不废话了。直入主题吧。 先在D盘下建立一个xxxx目录,然后打开控制台,直接将npm install gulp。 里面多出一个node_modules目录安装成功。 然后xxxx目录下面建一个src目录,里面建一个index.html文件,内容如下或你自己乱写一点东西,我们这个例子主要测试压缩html。 <!DOCTYPE html> <html> <head> <title>TODO supply a title</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width"> </head> <body> <h2>写在前面</h2> <p>本来是想写个如何编写gulp插件的科普文的,突然探究欲又发作了,于是就有了这篇东西。。。翻了下源码看了下<code>gulp.src()</code>的实现,不禁由衷感慨:肿么这么复杂。。。</p> <h2>进入正题</h2> <p>首先我们看下<code>gulpfile</code>里面的内容是长什么样子的,很有express中间件的味道是不是~<br />我们知道<code>.pipe()</code

How does require work with new operator in node.js?

霸气de小男生 提交于 2019-11-27 14:43:08
Let's have a file.js with this code: module.exports.func = function(txt) { this.a = 1; this.b = 2; console.log(txt, this); return this; } Now we have another JS file where we do following: var r1 = new (require('./file')).func('r1'); var r2 = new require('./file').func('r2'); In r1 case it works as intended - r1 contains reference to the newly created object. In r2 case it does not work - r2 gets reference to module.exports from within the file.js. The intention was to create a new object by calling func() constructor. Sure, I can do it also this way which is equal to r1: var r3 = require('.

What is the proper way to use include with or without brackets in php

丶灬走出姿态 提交于 2019-11-27 13:59:26
问题 I already know how to use include , require and even require_once . What I have always practiced is this: for example include 'sample.php'; or require_once 'classes/DB.php'; But in some ways I often see in some forums and tutorials and even here that they are using it like this - include ('sample.php'); and require_once ('classes/DB.php'); . I know that any of this will work, but I just want to know what would you recommend maybe as a good practice? XD and if it's already been asked here

Include PHP file into HTML file [duplicate]

ぃ、小莉子 提交于 2019-11-27 13:46:55
This question already has an answer here: How do I add PHP code/file to HTML(.html) files? 10 answers I'm working on a project that may have to change the same content on all html pages. So I figured I would create a php file and only have to change that so it changes on all pages over the web. The files are saved as: index.html number.php EXAMPLE: ------------------------(HTML FILE)---------------------------- <html> <head> <title>Home</title> </head> <body> <h1>Phone Number</h1> <?php include('number.php') ?> </body> </html> ------------------------(PHP FILE)---------------------------- <

node.js使用Koa搭建基础项目

落爺英雄遲暮 提交于 2019-11-27 13:21:31
Koa 是由 Express 原班人马打造的超轻量服务端框架 与 Express 相比,除了自由度更高,可以自行引入中间件之外,更重要的是使用了 ES6 + async,从而避免了回调地狱 不过也是因为代码升级,所以 Koa2 需要 v7.60 以上的 node.js 环境 一、创建项目   1.手动创建一个项目目录,然后快速生成一个 package.json 文件     $ npm init -y   安装 koa //当前版本 2.4.1     $ npm install koa -s    然后创建一个 app.js const Koa = require('koa'); const app = new Koa(); app.use(async ctx => { ctx.body = 'hello 你好'; }); app.listen(3000);   在cmd中输入node app.js就可以启动项目了,在浏览器输入http://localhost:3000/ 查看效果      或者你在package.json,更改代码:      输入命令,npm start也是一样的,可以运行项目,这样一个最基础的koa应用就好了!   2.利用脚手架 koa-generato 来生成项目     打开cmd,输入:      $ npm install koa

http服务的配置及应用

末鹿安然 提交于 2019-11-27 13:21:02
httpd服务的配置及应用 小尛酒窝 关注 0.6 2018.05.02 22:27* 字数 1696 阅读 13889评论 0喜欢 11 一、httpd服务的配置文件 httpd服务的主配置文件通常为httpd根目录下的conf/httpd.conf文件,通过yum安装的httpd服务的主配置路径通常如下: httpd-2.2:/etc/httpd/conf/httpd.conf httpd-2.4:/etc/httpd/conf/httpd.conf 主配置文件的格式大体分为三部分: Section 1: Global Environment Section 2: 'Main' server configuration Section 3: Virtual Hosts 但httpd-2.4版本中删除了相应的描述,不过大体与httpd-2.2相同。 另外除了主配置文件之外,也存在着其他的配置目录路径,通常在主配置文件中会使用 Include conf.d/*.conf 、 Include conf.modules.d/*.conf (httpd-2.4)类似的语句去调用对应的目录下的配置文件,其路径格式为相对路径,根目录由主配置文件中的Serverroot决定。 本文案例基于 Centos 7.4 httpd-2.4。 二、httpd服务的基础配置 1、修改监听的IP地址和接口

How to catch error of require() or include() in PHP?

感情迁移 提交于 2019-11-27 13:01:58
问题 I'm writing a script in PHP5 that requires the code of certain files. When A file is not available for inclusion, first a warning and then a fatal error are thrown. I'd like to print an own error message, when it was not possible to include the code. Is it possible to execute one last command, if requeire did not work? the following did not work: require('fileERROR.php5') or die("Unable to load configuration file."); Supressing all error messages using error_reporting(0) only gives a white

component: resolve => require(['@/view/index.vue'], resolve) 与component: index区别

假如想象 提交于 2019-11-27 12:14:51
require: 运行时调用,理论上可以运用在代码的任何地方, import:编译时调用,必须放在文件开头 懒加载:component: resolve => require(['@/view/index.vue'], resolve) 用require这种方式引入的时候,会将你的component分别打包成不同的js,加载的时候也是按需加载,只用访问这个路由网址时才会加载这个js 非懒加载:component: index 如果用import引入的话,当项目打包时路由里的所有component都会打包在一个js中,造成进入首页时,需要加载的内容过多,时间相对比较长 vue的路由配置文件(routers.js),一般使用import引入的写法,当项目打包时路由里的所有component都会打包在一个js中,在项目刚进入首页的时候,就会加载所有的组件,所以导致首页加载较慢, 而用require会将component分别打包成不同的js,按需加载,访问此路由时才会加载这个js,所以就避免进入首页时加载内容过多。 来源: https://blog.csdn.net/weixin_37380784/article/details/99671933