我一直在使用我的这个脚本FOREVER,我一直用"〜/"来扩展我的主目录.我今天上班了,它停止了工作:
#if ( $output eq "" ) { $output = "~/tmp/find_$strings[0].rslt" } # BROKEN
if ( $output eq "" ) { $output = "$ENV{HOME}/tmp/find_$strings[0].rslt" } #WORKS
...
open OUT_FILE, ">$output" or die "cant open $output : $!";
Run Code Online (Sandbox Code Playgroud)
关于为什么会突然停止工作的任何想法?
错误看起来像:
cant open stephen/tmp/find_coverp.rslt : No such file or directory at /user/stephen/bin/find.pl line 137.
Run Code Online (Sandbox Code Playgroud) 如何将8位字节转换为7位字节(Base 256到Base 128)
我希望做这样的事情:
public string BytesToString(byte[] in)
{
}
public byte[] StringToBytes(string in)
{
}
Run Code Online (Sandbox Code Playgroud)
我知道base64可用,但它扩展了一个字节数组太多了.
我已经看到了很多关于每次执行不多次伪随机数生成器的建议,但从未附带过彻底的解释.当然,很容易理解为什么以下(C/C++)示例不是一个好主意:
int get_rand() {
srand(time(NULL));
return rand();
}
Run Code Online (Sandbox Code Playgroud)
因为get_rand每秒调用几次会产生重复的结果.
但是下面的例子不是一个可以接受的解决方案吗?
MyRand.h
#ifndef MY_RAND_H
#define MY_RAND_H
class MyRand
{
public:
MyRand();
int get_rand() const;
private:
static unsigned int seed_base;
};
#endif
Run Code Online (Sandbox Code Playgroud)
MyRand.cpp
#include <ctime>
#include <cstdlib>
#include "MyRand.h"
unsigned int MyRand::seed_base = static_cast<unsigned int>(time(NULL));
MyRand::MyRand()
{
srand(seed_base++);
}
int MyRand::get_rand() const
{
return rand();
}
Run Code Online (Sandbox Code Playgroud)
main.cpp中
#include <iostream>
#include "MyRand.h"
int main(int argc, char *argv[])
{
for (int i = 0; i < 100; i++)
{
MyRand r;
std::cout …Run Code Online (Sandbox Code Playgroud) 我理解IoC容器是什么,并且已经在Structure Map上阅读了.该技术似乎很容易使用.我的问题是,使用IoC容器的适当粒度级别是多少?
我看到IoC的以下可能的应用程序级别:
我知道这个问题的答案是"它取决于",但根据你的经验,那么答案取决于什么?项目规模是一个因素吗?
此外,IoC在哪里使用不合理?
我有一些基本测试类,它们使用测试执行监听器为spring,logging,jndi等设置常用配置,然后由子类继承.这样做是为了测试可以只运行代码而不必担心在运行测试代码之前获取jndi和日志服务.
使用intellij并从项目库调用"运行所有测试",IDE尝试将基本测试类作为单元测试运行,并为我提供"无可运行方法"错误.
我知道我可以在基类中放置一个空的runnable方法,但我希望有一个人有更好的主意.
Base类是:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
"classpath:spring-jndi.xml"
})
@TestExecutionListeners({
Log4JSetupListener.class,
JndiSetupListener.class,
DependencyInjectionTestExecutionListener.class,
DirtiesContextTestExecutionListener.class,
TransactionalTestExecutionListener.class
})
public class SpringAppTestCase extends Assert implements ApplicationContextAware {
protected JndiTemplate jndiTemplate = new JndiTemplate();
@Autowired
protected JdbcTemplate jdbcTemplate;
protected ApplicationContext applicationContext;
public void setApplicationContext(ApplicationContext ac) {
this.applicationContext = ac;
}
//
// @Test
// public void doit(){
// // this would prevent blow up but
// all subclass tests would run an extra method
// }
protected Logger log = Logger.getLogger(getClass().getName());
}
Run Code Online (Sandbox Code Playgroud)
错误: …
我想运行这样的查询:
SELECT * FROM Studio WHERE Id IN (134, 144, 132, 138, 7432, 7543, 2566)
Run Code Online (Sandbox Code Playgroud)
但传递给IN子句的Id数量仅在运行时确定.
我是否必须使用动态SQL,还是可以使用存储过程完成?
更新: 如果有可用的选项,哪一个更好?
谢谢.
有没有办法在java属性文件中指定当前目录?
即:像:
fileLocation={currentDir}/fileName.txt
Run Code Online (Sandbox Code Playgroud) 我是Obj-C的新手,请原谅我,如果这是一个愚蠢的问题:
我如何以Javas枚举的方式实现一些?或者更确切地说:
我想要一个具有一些已知属性的类,这些属性在编译时修复并且每个实例都是唯一的.另外我只想要一种实例类型.
让我举一个Java的例子:
public enum MessageTypes {
DEFAULT("white", "standard", 1),
EXPRESS("red", "expressMessage", 2),
BORADCAST("green", "broadcast", 3);
String color; String tagName; int dbId;
MessageTypes(String color, String tagName, int dbId) {
// you get the idea
}
//some methonds like getEnumByTagName
}
Run Code Online (Sandbox Code Playgroud)
你会如何在Objective-C中做这样的事情?我错过了什么吗?这是一个糟糕的模式吗?
提前致谢!
编辑:对不起,如果我没有说清楚.我知道,obj-c枚举不是我想要的(因为它们只比int的typedef略多).
我想创建一组(特定的单例,不可变)特定类的实例.Apples Dev-Docs中的单例模式没有用,因为我想要一个类的多个不同实例,每个实例在其属性中都有单独的值.
这样做的目的是拥有多个可以作为属性分配给Message的消息类型(大约20个).我的每种消息类型都有(修复和预定义)颜色,属性值(以XML表示)和数字ID.
在Java中,我会在代码示例中使用枚举.但是如何创建不同的MessageType并将它们与Obj-C中的属性相关联?
创建20个MessageType的Sublcasses(每个都有一个包含属性的单例实例)对于这样一个简单的任务和完全的过度杀戮似乎很多工作.
我目前的方法是使用NSArray创建一个包含不同实例的类.首次访问类似+(id)messageTypeForId:NSInteger id_NSArray 的方法是预先填充的.但这感觉完全笨拙而且根本不优雅......
有更令人满意的方法吗?
我正在实现一个登录系统,我相信很多人都知道它是什么,我使用会话来存储用户的ID,并检查它是否访问了需要用户登录的页面.
但我的问题当用户单击注销锚点时,没有任何反应,只要当前页面打开,我仍然可以访问其他页面.
这里是代码使用:
<?
unset($_SESSION["ID"]);
session_destroy();
header('location: ../Home/index.php');
?>
Run Code Online (Sandbox Code Playgroud)
所以任何人都可以帮忙 提前致谢.
如果你的某些类型(即自定义集合)中有一些枚举方法,那么使用LINQ语法或旧学校枚举(for/foreach)是否更好?
使用.NET 3.5是给定的.
我问这是为了获得最大的性能和可读性.该应用程序也设计为并行.
你赞成哪一个?