小编Yve*_*omb的帖子

如何检查我的字符串是否只是数字

我如何检查我的字符串是否只包含数字?

我不记得了.有什么像isnumeric?

c#

21
推荐指数
5
解决办法
5万
查看次数

如何让我的Android应用程序出现在超省电模式下

一些三星设备具有超省电模式,可关闭wifi,转动屏幕灰度并限制几个基本应用的使用.

但它确实允许您添加一些可以使用的应用程序.这些应用包括Facebook和WhatsApp.如何让我的应用程序出现在此列表中?我必须对应用程序进行哪些更改才能显示在此列表中?或者此列表是否基于三星维护的白名单?

android power-saving samsung-mobile

21
推荐指数
1
解决办法
4269
查看次数

代码重复的任何正当理由?

我目前正在审查一个非常古老的C++项目,并在那里看到许多代码重复.

例如,有一个包含5个MFC消息处理程序的类,每个消息处理程序包含10行相同的代码.或者,每个地方都有一个5行代码段用于非常具体的字符串转换.在这些情况下,减少代码重复不是问题.

但我有一种奇怪的感觉,我可能会误解某些东西,并且最初有这种重复的原因.

什么可能是重复代码的正当理由?

c++ language-agnostic code-duplication

20
推荐指数
6
解决办法
2350
查看次数

ASP.NET MVC安全清单

有吨的有关设计和安全发展(甚至在SO一堆职位)好论文,但他们似乎专注于什么,你应该做的.

然而,我所追求的是一个像黑客一样的思维清单.完成开发后应该完成的简单操作列表,以确保解决方案的安全性.

(更新:我最感兴趣的是黑盒清单 - "去一个页面,试试这个和那个"的东西,但白盒清单也可能是有意义的.)


这是我到目前为止所提出的:

安全黑盒清单

  • 提交不正确/恶意数据(这里的示例?)以确保输入通过javascript验证类型,长度,格式和范围.
  • 关闭客户端验证并重复上述步骤,以确保这一点
    • 你不仅要检查javascript,还要在服务器端验证
    • 输入在服务器上验证类型,长度,格式和范围
    • 自由形式输入被消毒
    • 包含输入的输出用HtmlEncode和编码UrlEncode
  • 在查询字符串中插入极大量的数据,http://www.example.com/foo?bar=HugeAmountOfData以确保约束输入并进行边界检查.
  • 通过GET访问POST操作,以确保"表单提交"操作仅限于POST.
  • 如果适用,请上传大小/格式不正确的文件(大文件,空文件,带有重命名扩展名的可执行文件等),以确保正常处理上传.
  • (如何从UI检查?)确保绝对URL用于导航.
  • 以没有正确权限的用户身份访问URL,以确保通过操作/控制器属性显式地测试权限.
  • 访问提供不存在详细信息的URL(如不存在的产品ID,您无权访问的项目等),以确保返回正确的错误(404或403等).
  • 通过HTTP访问敏感页面,以确保它仅通过HTTPS可用.

安全白盒清单

Web层.

  • 在调试模式下,中断代码以便抛出异常,以确保它安全失败.确保捕获异常并记录详细消息,但不要将信息泄露给客户端.
  • 如果适用,请确保MVC操作仅限于POST/GET,特定用户角色,还有其他任何内容?.
  • 确保POST操作附带[ValidateAntiForgeryToken]属性以防止跨站点请求伪造攻击.
  • 确保Response.Write(直接或间接)永远不会用于显示用户输入.
  • 确保未在查询字符串或表单字段中传递敏感数据.
  • 确保您的安全决策不依赖于HTTP标头信息.

服务层.

  • 在调试模式下,中断代码以便抛出异常,以确保它安全失败.确保捕获异常并记录详细消息,但不要将信息泄露给客户端.
  • 确保在更新数据库中的任何内容时,您在事务中操作.

数据库层.

  • 确保检索存储过程不使用,SELECT *但始终明确指定列列表.
  • 确保更新/删除存储过程在事务(通过@@TRANCOUNT等)中运行并显式提交/回滚它.

评论?更正?缺少步骤?

使其成为社区维基,您可以随意编辑.

security asp.net-mvc

19
推荐指数
1
解决办法
3029
查看次数

Web窗体模型绑定:如何省略不可见控件的绑定?

我正在使用.NET Framework版本4.5.1的WebForms的新模型绑定功能.我希望实现的是,根据一些条件排除一些双向绑定.

我非常喜欢Scott Guthrie撰写的(希望现在很有名)博客文章系列.我使用Web Forms Model Binding Part 3:更新和验证(ASP.NET 4.5系列)中的第二种方法实现编辑页面

这就是我所拥有的:(简化,在ElementEdit.aspx中):

<asp:FormView runat="server" ID="FormViewElement" RenderOuterTable="false" DefaultMode="Edit" DataKeyNames="ElementId"
    ItemType="Business.Entities.Element"
    SelectMethod="GetElement"
    UpdateMethod="UpdateElement">
    <EditItemTemplate>
        <asp:Panel runat="server" DefaultButton="ButtonSpeichern">
            <fieldset>
                /*some databound controls*/
                <asp:Panel runat="server" Visible="<%# !Item.CurrentElementData.SomeCondition() %>">
                    /*more databound controls*/
                </asp:Panel>
                /*the submit button ("ButtonSpeichern")*/
            </fieldset>
        </asp:Panel>
    </EditItemTemplate>
</asp:FormView>
Run Code Online (Sandbox Code Playgroud)

如您所见,包裹的内部面板上的可见性存在"更多数据绑定控制"的条件.当条件为真时,这些应该仅绑定,并且它们是可见的.否则它们不应该绑定而不能更改值.

更新的工作方式类似于Scott的帖子(简化,在xxPage.cs中),它是Type Element的通用基类:

protected virtual bool UpdateEntity(int id) {
    T existing = UseCase.GetItem(id); //gets the original element    

    TryUpdateModel(existing); //SHOULD NOT update the invisible databound controls, but …
Run Code Online (Sandbox Code Playgroud)

c# asp.net controls webforms model-binding

19
推荐指数
1
解决办法
1196
查看次数

Cloudflare和nginx:重定向太多

我正在尝试设置NGINX和cloudflare.我在谷歌上读过这个,但没有解决我的问题.我的cloudflare目前很活跃.我删除了cloudflare中的所有页面规则,但之前有domain.com和www.domain.com使用HTTPS.我认为这可能导致问题所以我删除了它.这是我的defaultNGINX文件,目的是只允许通过域名访问,并禁止访问网站的IP值:

server{

  #REDIRECT HTTP TO HTTPS

  listen 80 default;
  listen [::]:80 default ipv6only=on; ## listen for ipv6
  rewrite ^ https://$host$request_uri? permanent;

}

server{

  #REDIRECT IP HTTPS TO DOMAIN HTTPS       

    listen 443;
    server_name numeric_ip;
    rewrite ^ https://www.domain.com; 

}

server{

  #REDIRECT IP HTTP TO DOMAIN HTTPS

    listen 80;
    server_name numeric_ip;
    rewrite ^ https://www.domain.com;

}

server {

         listen 443 ssl;
         server_name www.domain.com domain.com;
         #rewrite ^ https://$host$request_uri? permanent;
         keepalive_timeout 70;

         ssl_certificate     /ssl/is/working.crt;
         ssl_certificate_key /ssl/is/working.key;

         ssl_session_timeout 1d;
         ssl_session_cache shared:SSL:50m;

         #ssl_dhparam /path/to/dhparam.pem; …
Run Code Online (Sandbox Code Playgroud)

redirect nginx cloudflare

19
推荐指数
3
解决办法
2万
查看次数

没有名为_cffi_backend的模块

我的Linux rhel-5中有python2.6.我已经安装了pip和所需的CFFI包.当我尝试运行示例CFFI程序时,它说:

ffi = FFI()

初始化文件"/usr/lib/python2.6/site-packages/cffi/api.py",第56行

import _cffi_backend as backend
Run Code Online (Sandbox Code Playgroud)

ImportError:没有名为_cffi_backend的模块

什么可能是错误的错误.我在安装过程中遗漏了什么.我已经安装了pip,wheel,pycparser,pytest,cffi ....

python-2.6

18
推荐指数
7
解决办法
2万
查看次数

为什么折叠事件和行为会占用如此多的内存?

我目前正在探索使用基本容器为FRP网络提供更多结构的可能性,从而更容易创建更复杂的事件网络.

注意:我使用ordrea反应性香蕉也有同样的问题,所以我想这个问题不是特定于所选的frp实现.


在这个特殊情况下,我使用一个简单Matrix的存储Events:

newtype Matrix (w :: Nat) (h :: Nat) v a where
   Matrix :: Vector a -> Matrix w h v a

-- deriving instances: Functor, Foldable, Traversable, Applicative
Run Code Online (Sandbox Code Playgroud)

Matrix基本上只是一个薄的包装器Data.Vector,我将使用的大多数功能基本上与相应Vector的功能相同.值得注意的例外是索引,但这应该是自我解释的.


有了这个,我可以定义事件的矩阵,Matrix 10 10 (Event Double)并且能够定义基本的卷积算法:

applyStencil :: (KnownNat w, KnownNat h, KnownNat w', KnownNat h')
             => M.Matrix w' h' (a -> c)
             -> M.Matrix w h (Event a)
             -> M.Matrix w h …
Run Code Online (Sandbox Code Playgroud)

haskell fold frp

17
推荐指数
0
解决办法
654
查看次数

键盘隐藏片段中的EditTexts

编辑:我需要使用键盘,但它隐藏了我的EditText,我需要它滚动,所以键盘没有隐藏它.

我正在使用三星平板电脑.

我的风格:

parent="android:Theme.Holo.NoActionBar.Fullscreen"
Run Code Online (Sandbox Code Playgroud)

这些EditText字段位于可滚动视图中,如下所示:

片段布局:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_height="match_parent"
         android:layout_width="match_parent"
         android:paddingBottom="@dimen/activity_vertical_margin"
         android:paddingLeft="@dimen/activity_horizontal_margin"
         android:paddingRight="@dimen/activity_horizontal_margin"
         android:paddingTop="@dimen/activity_vertical_margin">

<ScrollView
    android:layout_height="wrap_content"
    android:layout_width="match_parent">

    <LinearLayout
        android:layout_height="match_parent"
        android:layout_marginBottom="20dp"
        android:layout_width="match_parent"
        android:orientation="vertical">

        <TextView
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_width="wrap_content"
            android:text="@string/depot_code"/>

        <EditText
            android:hint="@string/enter_depot_code"
            android:id="@+id/etlocationId"
            android:imeOptions="actionNext"
            android:inputType="number"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_width="wrap_content"
            android:lines="1"
            android:maxLength="12"
            android:singleLine="true">

            <requestFocus/>
        </EditText>

        <TextView
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_width="wrap_content"
            android:text="@string/name"/>

        <EditText
            android:hint="@string/enter_name"
            android:id="@+id/etname"
            android:imeOptions="actionNext"
            android:inputType="textPersonName"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_width="wrap_content"
            android:lines="1"
            android:maxLength="24"
            android:singleLine="true"/>

        <TextView
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_width="wrap_content"
            android:text="@string/street"/>

        <EditText
            android:hint="@string/enter_street"
            android:id="@+id/etstreet"
            android:imeOptions="actionNext"
            android:inputType="textPostalAddress"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_width="wrap_content"
            android:lines="1"
            android:maxLength="24"
            android:singleLine="true"/>

        <TextView
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_width="wrap_content" …
Run Code Online (Sandbox Code Playgroud)

android android-fragments samsung-mobile window-soft-input-mode imeoptions

17
推荐指数
2
解决办法
1万
查看次数

Android 9(Pie)Only:Context.startForegroundService()然后没有调用Service.startForeground() - 在奥利奥上工作正常

我们调整了我们对Oreo的持续通知,并且效果很好.现在,仅在Pie上(在Oreo设备上没有发生),我们得到了标题错误.Pie中的前台服务有什么变化我错过了吗?

这是前台服务的onCreate代码 - >

override fun onCreate() {
    super.onCreate()

    val notification: Notification = NotificationCompat.Builder(this, packageName)
            .setSmallIcon(R.drawable.status_notification_icon)
            .setContentTitle(getString(R.string.ongoing_notify_temp_title))
            .setContentText(getString(R.string.ongoing_notify_temp_message))
            .setGroup(AppConstants.NOTIFICATION_GROUP_ONGOING)
            .setColor(ContextCompat.getColor(this, R.color.custom_blue))
            .build()

    startForeground(ONGOING_NOTIFY_ID, notification)

    appSettings = AppSettings(this)

    weatherLookUpHelper = WeatherLookUpHelper()
    MyRoomDatabase.getInstance().invalidationTracker.addObserver(onChange)

    retrieveCurrentLocation()
    createAlarmManager()
}
Run Code Online (Sandbox Code Playgroud)

如您所见,我们只是创建通知然后调用startForeground.关于为什么这段代码会产生标题错误的任何想法?

侧注:Fabric Crashlytics显示此崩溃仅发生在运行Pie的像素设备(像素,像素xl,像素2,像素2 xl)上

编辑:我们的清单中有前台权限

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
Run Code Online (Sandbox Code Playgroud)

android android-9.0-pie

17
推荐指数
1
解决办法
9499
查看次数