我在Python中看到了decorator 示例:
def makebold(fn):
def wrapped():
return "<b>" + fn() + "</b>"
return wrapped
def makeitalic(fn):
def wrapped():
return "<i>" + fn() + "</i>"
return wrapped
@makebold
@makeitalic
def hello():
return "hello world"
print hello() ## returns <b><i>hello world</i></b>
Run Code Online (Sandbox Code Playgroud)
并且有些好奇它如何在Java中实现,所以我搜索并使用Decorator Design Pattern获得了一些示例.
public class Main {
public static void main(String[] args) {
Wrapper word = new BoldWrapper(new ItalicWrapper());
// display <b><i>hello world</i></b>
System.out.println(word.make("Hello World"));
}
}
public interface Wrapper {
public String make(String str);
}
public class …Run Code Online (Sandbox Code Playgroud) 我SimpleDateFormat format = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");在Windows中使用这种模式并且它可以工作,但是当尝试使用Ubuntu 10.04时它会显示异常play.exceptions.JavaExecutionException: Illegal pattern character 'Y'.
我为此寻找解决方案,发现年份模式必须改为小写:
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");并且它有效.
任何人都可以告诉我为什么在Windows工作的原因,但在Ubuntu如果我使用'Y'而不是'y'不起作用?
注意:
java version "1.7.0_03"
Java(TM) SE Runtime Environment (build 1.7.0_03-b05)
Java HotSpot(TM) Client VM (build 22.1-b02, mixed mode, sharing)java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b04)
Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01, mixed mode)更新24/05/2012
在我的系统中再次检查后,有3个JRE和我的窗口使用JRE1.7默认.但对于Play我使用JRE1.6设置运行.
java windows-7 simpledateformat ubuntu-10.04 playframework-1.x
现在,我只知道如何使用以下方法复制文件:
IStorageFolder dir = Windows.Storage.ApplicationData.Current.LocalFolder;
IStorageFile file = await StorageFile.GetFileFromApplicationUriAsync(
new Uri("ms-appx:///file.txt"));
await file.CopyAsync(dir, "file.txt");
Run Code Online (Sandbox Code Playgroud)
当我尝试复制文件夹和里面的所有内容时,我找不到CopyAsync上面的API .
是否可以复制文件夹和WinRT中的所有内容?
我想从html文件中的按钮通知我的网页视图并触发javascript:
function notify(str) {
window.external.notify(str);
}
Run Code Online (Sandbox Code Playgroud)
使用wv_ScriptNotify(..., ...)以下方式捕获事件
void wv_ScriptNotify(object sender, NotifyEventArgs e)
{
Color c=Colors.Red;
if (e.CallingUri.Scheme =="ms-appx-web" || e.CallingUri.Scheme == "ms-appdata")
{
if (e.Value.ToLower() == "blue") c = Colors.Blue;
else if (e.Value.ToLower() == "green") c = Colors.Green;
}
appendLog(string.Format("Response from script at '{0}': '{1}'", e.CallingUri, e.Value), c);
}
Run Code Online (Sandbox Code Playgroud)
我设置了html文件ms-appx-web并且运行良好,我意识到html文件必须存储到本地文件夹中.所以我改变ms-appx-web:///.../index.html来ms-appdata:///local/.../index.html.
已经在微软论坛中搜索并获得此信息.在那个线程上有一个解决方案使用解析器,但我仍然困惑,它如何通过javascript通知使用window.external.notify?在C#方面哪种事件会从"ScriptNotify"以外的javascript中捕获"通知"?
有从溶液这里使用的解析器,例如,它说使用ms-local-stream://,而不是使用ms-appdata://local,所以我仍然可以使用ScriptNotify事件.但不幸的是ms-appx,使用的例子意味着使用InstalledLocation不是LocalFolder. …
如何在Play项目中的Application.java中设置重载方法?
这是我正在做的一些例子:
Application.java
public class Application extends Controller {
public static void index() {
render();
}
public static void getData() {
renderText("Without Parameter");
}
public static void getData(String name) {
renderText("With Parameter name = " + name);
}
}
Run Code Online (Sandbox Code Playgroud)
路线
# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~
# Home page
GET / Application.index
GET /data Application.getData
# Ignore favicon requests
GET /favicon.ico 404
# Map static resources from the /app/public folder to …Run Code Online (Sandbox Code Playgroud) 我是Python的新手(以Java为基础).我在第3章中发现了Dive Into Python书籍Multi-Variable Assignment.也许你们中的一些人可以帮助我理解这段代码中发生的事情:
>>> params = {1:'a', 2:'b', 3:'c'}
>>> params.items() # To display list of tuples of the form (key, value).
[(1, 'a'), (2, 'b'), (3, 'c')]
>>> [a for b, a in params.items()] #1
['a', 'b', 'c']
>>> [a for a, a in params.items()] #2
['a', 'b', 'c']
>>> [a for a, b in params.items()] #3
[ 1 , 2 , 3 ]
>>> [a for b, b in params.items()] #4
[ 3 …Run Code Online (Sandbox Code Playgroud) 我尝试StringBuilder使用该replace方法替换一些字符串,但不幸的是它像insert方法一样运行.
这是一些代码:
public class StringBuilderReplace {
public static void main(String[] args) {
StringBuilder builder = new StringBuilder();
builder.append("Line 1\n");
builder.append("Line 2\n");
builder.append("Line 3\n");
builder.replace(builder.indexOf("Line 2"), builder.indexOf("Line 2"), "Temporary Line\n");
System.out.println(builder.toString());
}
}
Run Code Online (Sandbox Code Playgroud)
此代码的结果:
Line 1
Temporary Line
Line 2
Line 3
Run Code Online (Sandbox Code Playgroud)
我想要的是:
Line 1
Temporary Line
Line 3
Run Code Online (Sandbox Code Playgroud)
怎么做才能得到我想要的结果?
根据AljoshaBre答案更新
如果我像这样更改代码,它可以工作:
builder.replace(builder.indexOf("Line 2"), builder.indexOf("Line 3"), "Temporary Line\n");
Run Code Online (Sandbox Code Playgroud)
但是出现了新问题,如果下一个字符串(对于这个例子Line 3)我不知道内容怎么办?
这是我的目录的结构:
./archive
/sub1
- file1
- file2
/sub2
- file3
- file4
Run Code Online (Sandbox Code Playgroud)
我尝试使用此命令查找超过6个月删除它的所有文件:
find ./archive -mindepth 1 -mtime +180 -delete
Run Code Online (Sandbox Code Playgroud)
删除所有文件和子目录,我只想file1, file2, file3, file4删除,不包括sub1和sub2,请指教.
我有一个<td>像这样的元素:
<td class="right editable qty">100</td>
我想得到那个(100)里面的值但是遇到了一些问题.
这是我的脚本:
$('#example tbody tr td.qty').change(function () {
var sQty = $(this);
console.log(sQty); // print [<td class="right editable qty">100</td>]
console.log($.text(sQty)); // print nothing
console.log(sQty.val()); // print nothing
console.log(sQty.text()); // print nothing
console.log(sQty.html()); // print <form><input style="width: 100%; height: 100%; " autocomplete="off" name="value"></form>
});
Run Code Online (Sandbox Code Playgroud)
我的脚本有什么遗漏?
我正在使用:DataTables和jeditable
我想将超过30天的所有文件备份到1个存档文件中.
我尝试使用这个脚本:
#!/bin/bash
# Find all files that older than 30 days and store it into backup.tar.gz
find ~/Algorithm/test/PDF -mtime +30 -exec tar czvf backup.tar.gz {} \;
Run Code Online (Sandbox Code Playgroud)
但不幸的是,它只备份了最后一个文件而不是所有文件,我发现上面的脚本只是用最后一个替换backup.tar.gz.
如果我的脚本缺少某些内容,请提供建议.
java ×4
bash ×2
c# ×2
html ×2
python ×2
shell ×2
unix ×2
annotations ×1
copy ×1
datatables ×1
javascript ×1
jeditable ×1
jquery ×1
list ×1
overloading ×1
replace ×1
tuples ×1
ubuntu-10.04 ×1
windows-7 ×1
windows-8 ×1
windows-8.1 ×1
winrt-async ×1