灯角

文章 0 评论 0 浏览 23

灯角 2024-11-17 17:01:56

拥有一个可以执行具有特定功能的任何程序的包装程序非常有用,无需在目标程序上设置功能。这样的包装器对于从构建目录运行软件(其中 setcap 会很麻烦)或运行像 Python 这样的解释器(在其中不合适)特别有用。

正如其他答案中所解释的,环境功能解决了这个问题,但它们仅从内核 4.3 开始可用。可以通过让包装器直接加载目标程序而不是使用 exec 来解决此问题。我的意思是打开可执行文件,映射相关部分,设置堆栈等,然后跳转到其代码。这是一项相当复杂的任务,但幸运的是,Wine 项目中的 wine-preloader 程序正是这样做的(以及一些与此目的无关的其他事情)。

以 root 身份运行类似的内容来设置包装器:

cp /usr/bin/wine-preloader /path/to/wrapper
setcap cap_net_raw+ep /path/to/wrapper # set whatever capabilities you need

现在我们有了一个 wine-preloader 的副本,它能够运行具有这些功能的任何程序:

/path/to/wrapper /path/to/executable arguments...

这可行,但有一些陷阱:

  • 目标程序必须是可执行文件的路径,它无法在 PATH 中找到程序。
  • 如果目标程序是带有解释器的脚本 (#!),则该方法不起作用。
  • wine-preloader 打印一条关于无法找到某些内容的消息(但它仍然可以正常运行程序)。

It is useful to have a wrapper program that can execute any program with specific capabilities, without having to set capabilities on target programs. Such a wrapper is particularly useful to run software from a build directory (where setcap would be cumbersome) or to run interpreters like Python (where it would be inappropriate).

As explained in other answers, ambient capabilities solve this, but they are only available since kernel 4.3. It is possible to work around this problem by having the wrapper load the target program directly instead of using exec. By that, I mean open the executable, map relevant sections, set up the stack, etc., and jump to its code. This is a pretty complicated task, but luckily the wine-preloader program from the Wine project does exactly that (and some other things that are irrelevant for this purpose).

Run something like this as root to set up the wrapper:

cp /usr/bin/wine-preloader /path/to/wrapper
setcap cap_net_raw+ep /path/to/wrapper # set whatever capabilities you need

Now we have a copy of wine-preloader that is able to run any program with those capabilities:

/path/to/wrapper /path/to/executable arguments...

This works but there are some pitfalls:

  • The target program must be a path to an executable, it cannot find programs in PATH.
  • It does not work if the target program is a script with an interpreter (#!).
  • The wine-preloader prints a message about not being able to find something (but it still runs the program fine).

fork 和 execve 继承非特权父进程'能力

灯角 2024-11-17 15:13:56

除了上述答案之外,如果您想在应用程序位于前台时触发某些操作:

您可以使用名为onResume()的事件来触发您的应用程序当您的应用程序从之前的静止状态中获得关注时,即,如果您的应用程序位于后台(暂停/最小化...)

protected void onResume()
{
    super.onResume();

    //call user-defined function here
}

In addition to the above answer, in-case you want to trigger some action when your app is at the foreground:

You could use the event called onResume() to trigger your own function when your app takes the spotlight from a previously resting state, i.e, if your app was at the background(paused/minimized...)

protected void onResume()
{
    super.onResume();

    //call user-defined function here
}

如何显示屏幕已锁定?

灯角 2024-11-17 06:33:52

Rails 可以轻松上传图像,但从手写笔捕获图像超出了 Web 应用程序的范围。

Rails can easily upload images, but capturing an image from a stylus somehow is beyond the scope of web applications.

使用 Ruby on Rails 在 Web 中捕获签名

灯角 2024-11-17 03:42:56

如果您满足于使用 Intent 调用 Twitter(这意味着您需要已安装的 Twitter 应用程序才能正常工作),您可以通过以下方式访问 Twitter:

try{
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_TEXT, "It's a Tweet!" + "#MyApp");
    intent.setType("text/plain");
    final PackageManager pm = getPackageManager();
    final List<?> activityList = pm.queryIntentActivities(intent, 0);
    int len =  activityList.size();
    for (int i = 0; i < len; i++) {
        final ResolveInfo app = (ResolveInfo) activityList.get(i);
        if ("com.twitter.android.PostActivity".equals(app.activityInfo.name)) {
            final ActivityInfo activity=app.activityInfo;
            final ComponentName name=new ComponentName(activity.applicationInfo.packageName, activity.name);
            intent=new Intent(Intent.ACTION_SEND);
            intent.addCategory(Intent.CATEGORY_LAUNCHER);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
            intent.setComponent(name);
            intent.putExtra(Intent.EXTRA_TEXT, "It's a Tweet!" + "#MyApp");
            startActivity(intent);
            break;
        }
    }
} catch(final ActivityNotFoundException e) {
    Log.i("Twitter intent", "no twitter native", e );
}

If you are content with calling Twitter using Intent (meaning that you will need the Twitter app already installed for this to work), you can access Twitter with something like this:

try{
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_TEXT, "It's a Tweet!" + "#MyApp");
    intent.setType("text/plain");
    final PackageManager pm = getPackageManager();
    final List<?> activityList = pm.queryIntentActivities(intent, 0);
    int len =  activityList.size();
    for (int i = 0; i < len; i++) {
        final ResolveInfo app = (ResolveInfo) activityList.get(i);
        if ("com.twitter.android.PostActivity".equals(app.activityInfo.name)) {
            final ActivityInfo activity=app.activityInfo;
            final ComponentName name=new ComponentName(activity.applicationInfo.packageName, activity.name);
            intent=new Intent(Intent.ACTION_SEND);
            intent.addCategory(Intent.CATEGORY_LAUNCHER);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
            intent.setComponent(name);
            intent.putExtra(Intent.EXTRA_TEXT, "It's a Tweet!" + "#MyApp");
            startActivity(intent);
            break;
        }
    }
} catch(final ActivityNotFoundException e) {
    Log.i("Twitter intent", "no twitter native", e );
}

Android Twitter 应用程序 - 不起作用

灯角 2024-11-17 02:59:43

不确定您所说的货币是什么意思 -

这会为千位分隔符添加逗号,并强制输入两位小数,

输入可以是带或不带逗号的数字字符串、减号和小数,或者是数字

function addCommas2decimals(n){
    n= Number(String(n).replace(/[^-+.\d]+/g, ''));
    if(isNaN(n)){
        throw new Error('Input must be a number');
    }
    n= n.toFixed(2);
    var rx=  /(\d+)(\d{3})/;
    return n.replace(/^\d+/, function(w){
        while(rx.test(w)){
            w= w.replace(rx, '$1,$2');
        }
        return w;
    });

}
var s= '1234567.890123'
addCommas2decimals(s)

/*  returned value: (String)
1,234,567.89
*/

Not sure what you mean by currency-

this adds commas for thousands separators and forces two decimal places

input can be a string of digits with or without commas, minus sign and decimal, or a number

function addCommas2decimals(n){
    n= Number(String(n).replace(/[^-+.\d]+/g, ''));
    if(isNaN(n)){
        throw new Error('Input must be a number');
    }
    n= n.toFixed(2);
    var rx=  /(\d+)(\d{3})/;
    return n.replace(/^\d+/, function(w){
        while(rx.test(w)){
            w= w.replace(rx, '$1,$2');
        }
        return w;
    });

}
var s= '1234567.890123'
addCommas2decimals(s)

/*  returned value: (String)
1,234,567.89
*/

字符串用 JavaScript 固定?

灯角 2024-11-17 01:58:02

您可以无需访问表单控件,您需要执行以下操作:runat="server"

  • 表单方法应为 POST 类型。
  • 该标签应该有一个名为 NAME 的属性。因为它是在form[]中作为key使用的。
  • Html 控件应该在代码隐藏中访问。

Html

<form id="form1" runat="server" >   
    <input type="text" name="txtName" value="hidden text" />
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />   
</form>

C# 代码:

protected void Button1_Click(object sender, EventArgs e)
{
    string s = Page.Request.Form["txtName"];
}

You can access the form control without having runat="server" you need to do following

  • The form method should be of type POST.
  • The tag should have an attribute called NAME. Because it is used as key in form[].
  • Html control should be access in code behind.

Html

<form id="form1" runat="server" >   
    <input type="text" name="txtName" value="hidden text" />
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />   
</form>

C# Code:

protected void Button1_Click(object sender, EventArgs e)
{
    string s = Page.Request.Form["txtName"];
}

如何在不使用runat服务器的情况下访问代码隐藏中的html控件值?

灯角 2024-11-16 22:44:43

您需要在请求期间保留完全相同的数据模型(即您通过 value 属性引用的数据模型)表单提交就像在请求显示初始表单期间一样。这些症状表明您正在使用请求范围的 bean,并且数据模型的加载基于表单提交期间缺少的某些请求参数和/或在 bean 的(后)构造期间未完成加载。

将 bean 放入视图范围和/或重新安排数据加载逻辑应该可以修复它。

You need to preserve exactly the same data model (i.e. the one which you have referenced by the value attribute of the <h:dataTable>) in during the request of the form submit as it was during the request of displaying the initial form. The symptoms indicate that you're using a request scoped bean and that the loading of the data model is based on some request parameter which is missing during the form submit and/or the loading is not being done during bean's (post)construction.

Putting the bean in the view scope and/or rearranging the data loading logic should fix it.

为什么复合组件不在 中调用?

灯角 2024-11-16 19:10:11

当前版本的 Go AppEngine SDK 中允许的字段类型仅有 如下

  • 有符号整数(int、int8、int16、int32 和 int64)、
  • bool、
  • string、
  • float32 和 float64、
  • 基础类型为上述预声明类型之一的任何类型、
  • *Key、
  • appengine.BlobKey、
  • []byte(长度最多 1 MB),
  • 上述任何一个的切片(长度最多 100 个元素)。

鉴于此,似乎有两种方法可以做到这一点。一种是维护一组键来指向给定评论的投票。然而,对于任何相当受欢迎的评论来说,这可能会达到 100 个元素的限制。

另一种方法是在每个投票结构中存储一个指向评论的“指针”,如下所示:

type Vote struct {
    User string
    Score int
    CommentKey *datastore.Key
}    

type Comment struct {
    Author  string
    Content string
    Date    datastore.Time
}

然后,当您去查询它时,您需要分两步进行。首先,您会得到您感兴趣的评论(在本例中,只是恰好返回的第一个评论)。其次,您查询“指向”该评论的所有投票:

q := datastore.NewQuery("Comment").Limit(1)
comments := make([]Comment, 0, 1)
var err os.Error
var keys []*datastore.Key
if keys, err = q.GetAll(c, &comments); err != nil {
    // handle the error
}

comment := comments[0]
vq := datastore.NewQuery("Vote").Filter("CommentKey=", keys[0])

votes := make([]Vote, 0, 10)
if _, err := vq.GetAll(c, &votes); err != nil {
    // handle the error
}

The only types that are allowed for fields in the current version of the Go AppEngine SDK are as follows:

  • signed integers (int, int8, int16, int32 and int64),
  • bool,
  • string,
  • float32 and float64,
  • any type whose underlying type is one of the above predeclared types,
  • *Key,
  • appengine.BlobKey,
  • []byte (up to 1 megabyte in length),
  • slices of any of the above (up to 100 elements in length).

Given that, there appear to be two ways to do this. One is to maintain a slice of keys to point to the Votes of a given Comment. However this is likely to run up against the 100 element limit for any reasonably popular comment.

The other approach is to store a "pointer" to the comment in each vote struct like this:

type Vote struct {
    User string
    Score int
    CommentKey *datastore.Key
}    

type Comment struct {
    Author  string
    Content string
    Date    datastore.Time
}

Then when you go to query it you need to do it in two steps. First you get the Comment you're interested in (in this case just the first one that happens to be returned). Second, you query for all the votes that "point" to that comment:

q := datastore.NewQuery("Comment").Limit(1)
comments := make([]Comment, 0, 1)
var err os.Error
var keys []*datastore.Key
if keys, err = q.GetAll(c, &comments); err != nil {
    // handle the error
}

comment := comments[0]
vq := datastore.NewQuery("Vote").Filter("CommentKey=", keys[0])

votes := make([]Vote, 0, 10)
if _, err := vq.GetAll(c, &votes); err != nil {
    // handle the error
}

如何在 Go 中的 App Engine 上实现一对多?

灯角 2024-11-16 13:42:14

我认为您正在尝试使 HtmlHelper::css 方法执行不应执行的操作。根据文档:

(需要混合 $path)-- CSS 的名称
样式表或包含的数组
CSS 样式表的名称。如果 $path 是
以“/”为前缀,路径将是
相对于您的网络根目录
应用程序。否则,该路径将
通常与您的 CSS 路径相关
webroot/css

cake.generic.css 文件确实应该使用 $this->Html->css(' 放置在 app/webroot/css 文件夹中cake.generic') 您在视图中使用的代码。

以下是 API 文档的链接:HtmlHelper 类文档

I think you are trying to make the HtmlHelper::css method do something that it isn't supposed to do. According to the documentation:

(mixed $path required) -- The name of a CSS
style sheet or an array containing
names of CSS stylesheets. If $path is
prefixed with '/', the path will be
relative to the webroot of your
application
. Otherwise, the path will
be relative to your CSS path, usually
webroot/css
.

The cake.generic.css file should indeed be placed within the app/webroot/css folder using the $this->Html->css('cake.generic') code that you are using in your view.

Here's a link to the API documentation: HtmlHelper Class documentation

CakePHP 未输出正确的 CSS 路径

灯角 2024-11-16 12:28:00

作为一般经验法则,浏览器评估的选择器越少越好。

如果 .error 用于多个标记,则 p.error 不一定比 .error “更糟”。例如 div.error (请参阅底部的脚注)。

但如果它只在一个段落中使用,那么拥有 p.error 只会让浏览器更加努力地工作,即

首先它必须找到具有类属性 error 的所有元素然后仅通过 p 标签来过滤它们。

以下是一些有关优化浏览器渲染对 Google 页面速度的有趣读物地点。


脚注

但是,如果您需要在多个标签上使用一个类,最好只放入适用于这些标签的 css 样式,而不是尝试将其分开。例如

.error
{
   color:red;
}

h1
{
font-size:2em;
}

p
{
   font-size:0.8em;
}


<h1 class="error">Bad Heading!</h1>
<p class="error">bad!</p>

,无论如何,这种方式都不需要为类添加标签前缀。

我希望这有帮助!

As a general rule of thumb, the less selectors a browser has to evaluate the better.

p.error isn't necessarily "worse" than .error, if .error is used for multiple tags. e.g. div.error (see a foot note at the bottom).

But if it's only used on a paragraph anyway, then having p.error is just making the browser work harder i.e.

First it will have to find all elements with the class attribute error and then filter these by only having tags that are p.

Here is some interesting reading on Optimize browser rendering on Google's Page Speed site.


Foot Note

However if you need to use a class on multiple tags, it's probably best only to put in the css styles which apply to those tags instead of trying to separate it. e.g.

.error
{
   color:red;
}

h1
{
font-size:2em;
}

p
{
   font-size:0.8em;
}


<h1 class="error">Bad Heading!</h1>
<p class="error">bad!</p>

So that kind of defeats the need to prefix classes with tags anyway.

I hope this helps!

特定于元素的 CSS 选择器不好吗?

灯角 2024-11-16 12:26:41

至少你想剥离 EUI-64 off,即地址的最后 64 位。更现实的是,您希望剥离更多内容以真正实现私有,因为剩余部分仍将仅标识一个子网(即可能是一栋房子)

IPv6 全局寻址是非常分层的,来自 RFC2374

 | 3|  13 | 8 |   24   |   16   |          64 bits               |
 +--+-----+---+--------+--------+--------------------------------+
 |FP| TLA |RES|  NLA   |  SLA   |         Interface ID           |
 |  | ID  |   |  ID    |  ID    |                                |
 +--+-----+---+--------+--------+--------------------------------+
 <--Public Topology--->   Site
                       <-------->
                        Topology
                                 <------Interface Identifier----->

问题是如何私密才足够私密?剥离 64 位后,您就识别出了 LAN 子网,而不是用户。再除去 16 个,您就确定了一个小型组织,即 ISP 的客户,例如具有多个子网的公司/分支机构。去掉接下来的 24 个,您基本上就只能识别出 ISP 或真正的大型组织。

您可以使用与 IPv4 地址完全相同的位掩码来实现这一点,但问题变成了一个法律问题,即“我需要剥离多少内容才能符合特定立法”,而不是技术问题。

At the very least you want to strip the EUI-64 off, i.e the last 64 bits of the address. more realistically you want to strip quite a lot more to really be private, since the remaining part will still identify only one subnet (i.e. one house possibly)

IPv6 global addressing is very hierarchical, from RFC2374:

 | 3|  13 | 8 |   24   |   16   |          64 bits               |
 +--+-----+---+--------+--------+--------------------------------+
 |FP| TLA |RES|  NLA   |  SLA   |         Interface ID           |
 |  | ID  |   |  ID    |  ID    |                                |
 +--+-----+---+--------+--------+--------------------------------+
 <--Public Topology--->   Site
                       <-------->
                        Topology
                                 <------Interface Identifier----->

The question becomes how private is private enough? Strip 64 bits and you've identified a LAN subnet, not a user. Strip another 16 on top of that and you've identified a small organisation, i.e. a customer of an ISP, e.g. company/branch office with several subnets. Strip the next 24 off an you've basically identified an ISP or really big organisation only.

You can implement this with a bitmask exactly like you would for an IPv4 address, the question becomes a legal one though of "how much do I need to strip to comply with the specific legislation", not a technical one at that point though.

匿名 IPv6 地址

灯角 2024-11-16 11:48:05

您可以尝试这个链接

您可以在以下位置使用 WebBrowser 控件
使用第二个 Web 浏览器的设计模式
控件设置为视图模式。

为了放置WebBrowser控件
在设计模式下,您可以使用
以下代码。

这段代码是一个超级精简的代码
所见即所得编辑器的版本之一
我们的软件产品。

只需创建一个新表单,删除一个
WebBrowser控件就可以了,然后把这个
在form_load中

Me.WebBrowser1.Navigate("about:blank")
Application.DoEvents()
Me.WebBrowser1.Document.OpenNew(False).Write("<html><body><div id=""editable"">Edit this text</div></body></html>")

'turns off document body editing
For Each el As HtmlElement In Me.WebBrowser1.Document.All
    el.SetAttribute("unselectable", "on")
    el.SetAttribute("contenteditable", "false")
Next

'turns on editable div editing
With Me.WebBrowser1.Document.Body.All("editable")
    .SetAttribute("width", Me.Width & "px")
    .SetAttribute("height", "100%")
    .SetAttribute("contenteditable", "true")
End With

'turns on edit mode
Me.WebBrowser1.ActiveXInstance.Document.DesignMode = "On"
'stops right click->Browse View
Me.WebBrowser1.IsWebBrowserContextMenuEnabled = False

You can try this one link

You can use the WebBrowser control in
design mode with a second WebBrowser
control set in view mode.

In order to put the WebBrowser control
in design mode, you can use the
following code.

This code is a super stripped down
version of a WYSIWYG editor for one of
our software products.

Simply create a new form, drop a
WebBrowser control on it, and put this
in the form_load

Me.WebBrowser1.Navigate("about:blank")
Application.DoEvents()
Me.WebBrowser1.Document.OpenNew(False).Write("<html><body><div id=""editable"">Edit this text</div></body></html>")

'turns off document body editing
For Each el As HtmlElement In Me.WebBrowser1.Document.All
    el.SetAttribute("unselectable", "on")
    el.SetAttribute("contenteditable", "false")
Next

'turns on editable div editing
With Me.WebBrowser1.Document.Body.All("editable")
    .SetAttribute("width", Me.Width & "px")
    .SetAttribute("height", "100%")
    .SetAttribute("contenteditable", "true")
End With

'turns on edit mode
Me.WebBrowser1.ActiveXInstance.Document.DesignMode = "On"
'stops right click->Browse View
Me.WebBrowser1.IsWebBrowserContextMenuEnabled = False

渲染 HTML 的最佳控件

灯角 2024-11-16 11:44:15

我猜这是由 带有资产管道的 Rails 3.1,link_to :确认消息显示两次?

您的开发环境中已经预编译了资源,<%= stylesheet_link_tag "application" %> 将扩展为多个标记,包括每个 CSS 文件,其中之一是 global.css

I would guess this is caused by the same problem as described in Rails 3.1 with Asset Pipeline, link_to :confirm message showing twice?.

You have precompiled assets in your development environment and <%= stylesheet_link_tag "application" %> will expand into multiple tags including each CSS file, one of them being global.css.

Rails 3.1 CSS 文件加载两次?

灯角 2024-11-16 11:04:40

您不应该抛出 Exception 类的实例。您应该抛出一个从Exception派生的类的实例。

您可以创建自己的异常类(如果您有框架尚未涵盖的内容,您应该出于习惯),然后您可以选择您希望 Visual Studio 中断的异常。

创建异常类后,转到“调试”-->“异常...”,然后选择要让调试器中断的异常。

You should not be throwing an instance of an Exception class. You should throw an instance of a class derived from Exception.

You can create your own exception class (and you should out of habit if you have something that's not already covered by the framework) then you can select the exceptions you want Visual Studio to break on.

Once you've created your exception class, go to Debug-->Exceptions... and then pick the exceptions you want to have the debugger break on.

如何在 C# 中抛出静默异常?

灯角 2024-11-16 10:40:10

您没有正确初始化新元素。

n->next = NULL; 添加到 createNode 函数中。

You're not initializing the new elements correctly.

Add n->next = NULL; to the createNode function.

链表C错误

更多

推荐作者

浪漫人生路

文章 0 评论 0

620vip

文章 0 评论 0

羞稚

文章 0 评论 0

走过海棠暮

文章 0 评论 0

你好刘可爱

文章 0 评论 0

陌若浮生

文章 0 评论 0

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文