我正在尝试使用web pack来编译有效javascript代码的内存字符串.我正在使用这里概述的内存fs:https://webpack.github.io/docs/node.js-api.html#compile-to-memory.
所以我正在使用包含原始javascript的字符串,将其写入内存fs,然后web pack解析为该入口点.但是编译在第一个require语句中失败了,大概是因为它无法查找node_modules的实际fs.
有关如何实现这一目标的任何想法?
import webpack from 'webpack';
import MemoryFS from 'memory-fs';
import thenify from 'thenify';
function* compile(code) {
const fs = new MemoryFS();
fs.writeFileSync('/file.js', code);
const compiler = webpack({
entry: { file: '/file.js' },
output: {
path: '/build',
filename: '[name].js'
},
module: {
loaders: [
{ test: /\.json$/, loader: 'json' }
],
}
});
compiler.run = thenify(compiler.run);
compiler.inputFileSystem = fs;
compiler.resolvers.normal.fileSystem = fs; //this is needed for memfs
compiler.outputFileSystem = fs;
const stats = …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的iOS项目中加入UI测试,但是有一件事情继续让我感到震惊的是,你所编写的所有测试似乎都必须从应用程序的开头开始并逐步完成.例如,如果我想测试登录屏幕后面的视图,我的测试必须首先在登录屏幕上运行,输入用户名/密码,单击登录,然后转到我想要测试的视图.理想情况下,登录视图和下一个视图的测试将完全隔离.有没有办法做到这一点,还是我完全错过了UI测试背后的哲学?
我的iPhone应用程序要求始终隐藏状态栏.这通常很容易做到,如果我只在iPhone上运行应用程序,它就有效.但是,如果我在iPad上运行该应用程序,状态栏仍会显示在内容的顶部.那么,无论我的iPhone专用应用程序运行在哪个设备上,如何确保隐藏状态栏?我目前正在我的代码中执行以下操作:
为每个视图控制器调用此方法(我实际上在UIViewController上创建了一个类别,可以自动为任何VC实现此类,但它与在每个vc文件中编写它基本相同):
-(BOOL)prefersStatusBarHidden{
return YES;
}
Run Code Online (Sandbox Code Playgroud)
我还在Info.plist中将"状态栏最初隐藏"设置为YES和"查看基于控制器的状态栏外观"为NO.我也试过检测正在使用和调用的设备
[UIApplication sharedApplication]setSetStatusBarHidden:YES]
Run Code Online (Sandbox Code Playgroud)
在AppDelegate,但也没有运气.所以,我相信我已经尝试过一个人们想要尝试的一切.
我有一个 UICollectionView 显示单元格的垂直列表。它基本上是一个表格视图,但我使用集合视图来控制每个单元格在视图中的放置方式。出于某种原因,集合视图中的最后一个单元格被剪裁了。我可以向上拖动以查看下半部分,但是一旦我松开,集合视图就会弹回原位,遮住最后一个单元格的下半部分。我有一个包含集合视图的 xib,然后我从另一个 xib 注册集合视图单元格。整个视图以编程方式放置在导航控制器中。我的想法是它必须是自动布局的问题。由于我以编程方式将包含集合视图的视图控制器添加到导航控制器,因此集合视图和导航栏之间没有设置任何约束。如果我隐藏实例化的导航栏并在 IB 中拖出一个,则不会剪切集合视图单元格。但我不想这样做。我试过以编程方式添加约束,但这也不起作用。有没有人有什么建议?下面是我如何创建导航控制器并将包含集合视图的视图控制器放入其中。此外,我试图用来添加约束的代码是包含。目前,我正在 didFinishLaunchingWithOptions 中的应用程序委托中执行此操作:m 创建导航控制器并将包含集合视图的视图控制器放入其中。此外,我试图用来添加约束的代码是包含。目前,我正在 didFinishLaunchingWithOptions 中的应用程序委托中执行此操作:m 创建导航控制器并将包含集合视图的视图控制器放入其中。此外,我试图用来添加约束的代码是包含。目前,我正在 didFinishLaunchingWithOptions 中的应用程序委托中执行此操作:
self.homeViewController = [[FFHomeViewController alloc] init];
FFNavigationPanelViewController *navigationController = [[FFNavigationPanelViewController alloc] init];
UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:self.homeViewController];
// frontNavigationController.navigationBarHidden = YES;
UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:navigationController];
NSLayoutConstraint *topConstraint = [NSLayoutConstraint constraintWithItem:self.homeViewController.collectionView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.homeViewController.navigationController.navigationBar attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0];
[self.viewController.frontViewController.view addConstraint:topConstraint];
Run Code Online (Sandbox Code Playgroud) 我正在尝试在网站表单上实现 DataTables。我遇到了一些困难,所以我退后一步,尝试在一个非常基本的表上实现 DataTables。我使用的表格直接来自http://www.datatables.net/usage/。然后我调用了我认为需要的文件,但我仍然无法让 Datatables 处理这个基本的表格。我错过了什么?这是“练习”代码:
<script type="text/javascript" charset="utf-8" src="/media/js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="/media/js/jquery.dataTables.js"></script>
<!--<script type="text/javascript" charset="utf-8" src="/media/src/DataTables.js"></script>-->
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$('#table').dataTable();
} );
</script>
<style type="text/css" title="currentStyle">
@import "/media/css/jquery.dataTables.css";
</style>
<title>Untitled Document</title>
</head>
<table id="table" class="display">
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>etc</th>
</tr>
</thead>
<tbody>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
<td>etc</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
<td>etc</td>
</tr>
</tbody>
</table>
<body>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
谢谢!
我正在开发一个将使用SWRevealViewController类的应用程序.该应用程序到目前为止工作,我可以点击左栏按钮项目带出后视图控制器,但当我在前视图控制器中添加手势识别器时,SWRevealViewController是零.我不知道为什么这样,所以任何帮助将不胜感激.
//not nil here.
SWRevealViewController *revealController = [self revealViewController];
//somehow it becomes nil on the very next line and from then on I can't hold the reference to it
[self.navigationController.navigationBar addGestureRecognizer:[revealController panGestureRecognizer]];
UIBarButtonItem *revealButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"reveal-icon.png"]
style:UIBarButtonItemStyleBordered target:revealController action:@selector(revealToggle:)];
Run Code Online (Sandbox Code Playgroud) 今天我正在阅读有关XOR Swaps的内容,并认为我会尝试在Swift中实现一个可以执行此操作的函数.我成功写了这个函数的非泛型版本:
import UIKit
func xorSwap (inout x: Int, inout y: Int) {
if x != y {
x ^= y
y ^= x
x ^= y
}
}
var a = 10
var b = 20
xorSwap(&a, &b)
println(a) //=> 20
println(b) //=> 10
Run Code Online (Sandbox Code Playgroud)
然后我尝试编写一个通用版本,但编译器抱怨"T与Bool不同".我假设我需要声明符合性的另一个协议,但我不确定那是什么.这是对通用版本的尝试:
import UIKit
func xorSwap<T: Equatable> (inout x: T, inout y: T) {
if x != y {
x ^= y
y ^= x
x ^= y
}
}
var a = 10
var b …Run Code Online (Sandbox Code Playgroud) 我有一个python字典,如下所示:
{'666 -> 999': 4388, '4000 -> 4332': 4383, '1333 -> 1665': 7998, '5666 -> 5999': 4495, '3666 -> 3999': 6267, '3000 -> 3332': 9753, '6333 -> 6665': 7966, '0 -> 332': 877}
Run Code Online (Sandbox Code Playgroud)
键显然都是字符串,但每个键都描绘了一系列数字.我想要做的是根据密钥中的第一个数字对该字典进行排序.有这么快的方法吗?只是在字典上使用sorted并没有帮助,因为字符串"666"在词法上大于字符串"1000".谢谢你的任何建议