走过海棠暮

文章 0 评论 0 浏览 24

走过海棠暮 2024-10-18 03:37:56

在我看来,您描述的问题的唯一架构模式是: 抽象

确保坚持使用不同供应商提供的资源,例如存储、队列等。为每个供应商创建抽象层。

希望这有帮助。考虑到云提供商的服务存在差异,我认为这不是一个超级简单的任务

In my opinion, the only architectural pattern to the problem you describe is: abstraction

Make sure to stick to using resources that are offered across various vendors,like storage, queue, etc. Create abstraction layers for each of them.

Hope this helps. I don't think its a super simple task to do, given the variability of the services across cloud providers

最小化云锁定风险的架构策略?

走过海棠暮 2024-10-18 00:52:34

在评论中与@DerrickCoetzee 讨论后,我有时间重新考虑这个答案。事实是,答案实际上可能是在某些服务器上解决此问题的唯一方法。我曾建议给予数据库通用写访问权限,这无疑是不安全的。我发现,这是我唯一可以拥有的解决方案的原因是我的服务器已禁用 php 的写访问权限。 php 无法创建新文件,并且我无法将数据库的所有者更改为 apache 或没有 root 访问权限的“nobody”,这使得更好的解决方案变得不可能。

本质上,我的服务器已经锁定了 php,只有在每个人都可以写的情况下它才可以写。在我看来,这是一个糟糕的服务器设置,导致了这种安全风险,正如 @Derrick 所建议的,sqlite 数据库可能只应用于私人使用或仅服务器访问。有些系统未设置为安全地利用此功能。如果您发现 php 没有写入权限,并且您没有机器的 root 访问权限,则应考虑联系您的系统管理员或切换到 MySQL(如果可用)。

话虽这么说,当数据库不敏感或者只有一小部分人知道时,我发现以下解决方案对于快速原型解决方案非常方便。


我之前的回答:

我今天也遇到了同样的问题!我对 php 和 sqlite 还很陌生,但还是很顺利。突然间,我遇到了这个巨大的障碍(一天没有进展),因为我的 sqlite 数据库中缺少插入,如问题发布者所述。这里的区别因素是没有错误消息或异常,如果将execute语句放入if子句中,只会返回false。

所以,我终于找到了一种方法来获得插入工作,但我不能 100% 确定它是否安全。如果您认为有更好的方法,我将不胜感激。

主要问题是您试图让用户写入文件系统上的文件。但是,默认情况下,文件夹和文档仅对外部人员具有读取访问权限。因此,您需要为您的数据库(user.db)及其文件夹(./db)提供可写访问权限。

因此,您需要进入目录并输入:

chmod 777 ./db
chmod 766 ./db/user.db

这为我解决了这个问题,所以我希望它也能帮助您。我不知道是否有更好的方法,但这看起来很合乎逻辑。

I have had time to reconsider this answer after discussion with @DerrickCoetzee in the comments. The truth is, the answer may in fact be the only way to fix this problem on some servers. I had suggested to give universal write access to the database, which is admittedly unsafe. The reason, I have found, why that was the only solution I could have is that my server has disabled write access for php. php is incapable of making new files, and I am unable to change the owner of the database to apache or "nobody" without root access, which makes a better solution impossible.

Essentially, my server has locked down php such that it can only write if everyone can write. In my opinion, this is a bad server setup, which led to this security risk and as @Derrick suggests, an sqlite db should probably only be used for private use or server-access-only. Some systems are not setup to take advantage of this safely. If you find php has no write access and you do not have root access to the machine, you should consider contacting your system administrator or switch to MySQL if it's available.

That being said, I find the following solution very handy for quick, prototyping solutions, when the db is not sensitive, or will only be known about by a small select group of people.


My previous answer:

I had this exact same problem today! I am pretty new to php and sqlite, but was chugging along. All of a sudden I hit this massive roadblock (no progress for a day) from lack of insert into my sqlite database as described by the question poster. The distinguishing factor here is that there is no error message or exception, only the return of false if you put the execute statement into an if clause.

So, I was finally able to figure out a way to get insertion to work, but I am not 100% certain if it is safe or not. I'd appreciate any comments if you think there's a better way.

The main problem is that you are trying to let your users write to a file on your file system. However, by default folders and documents only have read access for outsiders. Therefore, you need to give both your database (user.db) and it's folder (./db) writable access others.

So, you need to go the directory and type in:

chmod 777 ./db
chmod 766 ./db/user.db

That fixed this problem for me, so I hope it helps you out, too. I don't know if there is a better way or not, but it seems rather logical.

无法通过 php PDO 插入 SQLite 数据库

走过海棠暮 2024-10-17 23:04:57

您可能会看到的另一种解决方案是使用引用属性。

    class User(db.Model):
        name = db.StringProperty()
        datejoined = db.DateTimeProperty(auto_now_add=True)

    class Content(db.Model):
        user = db.ReferenceProperty(User,collection_name='matched_content')
        text = db.StringProperty()
        datemod= db.DateTimeProperty(auto_now_add = True)

    content = db.get(content_key)
    user_name = content.user.name

    #looking up all of the content for a particular user
    user_content = content.user.matched_content

    #create new content for a user
    new_content = Content(reference=content.user)

An alternative solution you may see is using referenceproperty.

    class User(db.Model):
        name = db.StringProperty()
        datejoined = db.DateTimeProperty(auto_now_add=True)

    class Content(db.Model):
        user = db.ReferenceProperty(User,collection_name='matched_content')
        text = db.StringProperty()
        datemod= db.DateTimeProperty(auto_now_add = True)

    content = db.get(content_key)
    user_name = content.user.name

    #looking up all of the content for a particular user
    user_content = content.user.matched_content

    #create new content for a user
    new_content = Content(reference=content.user)

Google App Engine Python 数据存储

走过海棠暮 2024-10-17 19:37:07

@msalvadores 代码答案的 C# 版本

void Main()
{
    int[] numbers = {3,9,8,4,5,7,10};
    int target = 15;
    sum_up(new List<int>(numbers.ToList()),target);
}

static void sum_up_recursive(List<int> numbers, int target, List<int> part)
{
   int s = 0;
   foreach (int x in part)
   {
       s += x;
   }
   if (s == target)
   {
        Console.WriteLine("sum(" + string.Join(",", part.Select(n => n.ToString()).ToArray()) + ")=" + target);
   }
   if (s >= target)
   {
        return;
   }
   for (int i = 0;i < numbers.Count;i++)
   {
         var remaining = new List<int>();
         int n = numbers[i];
         for (int j = i + 1; j < numbers.Count;j++)
         {
             remaining.Add(numbers[j]);
         }
         var part_rec = new List<int>(part);
         part_rec.Add(n);
         sum_up_recursive(remaining,target,part_rec);
   }
}
static void sum_up(List<int> numbers, int target)
{
    sum_up_recursive(numbers,target,new List<int>());
}

C# version of @msalvadores code answer

void Main()
{
    int[] numbers = {3,9,8,4,5,7,10};
    int target = 15;
    sum_up(new List<int>(numbers.ToList()),target);
}

static void sum_up_recursive(List<int> numbers, int target, List<int> part)
{
   int s = 0;
   foreach (int x in part)
   {
       s += x;
   }
   if (s == target)
   {
        Console.WriteLine("sum(" + string.Join(",", part.Select(n => n.ToString()).ToArray()) + ")=" + target);
   }
   if (s >= target)
   {
        return;
   }
   for (int i = 0;i < numbers.Count;i++)
   {
         var remaining = new List<int>();
         int n = numbers[i];
         for (int j = i + 1; j < numbers.Count;j++)
         {
             remaining.Add(numbers[j]);
         }
         var part_rec = new List<int>(part);
         part_rec.Add(n);
         sum_up_recursive(remaining,target,part_rec);
   }
}
static void sum_up(List<int> numbers, int target)
{
    sum_up_recursive(numbers,target,new List<int>());
}

找出所有可能的数字组合以达到给定的总和

走过海棠暮 2024-10-17 19:22:10

AFAIK GUID/UUID 不是适用于任何智能卡产品的标准卡实例标识方式。例如,SIM 卡是使用文件 EF_ICCID(ICC 标识)(ETSI TS 102 221 V6.15.0 (2010-02))的内容来识别的,因此您可以通过正常的 UICC 文件访问 API 获取它。 ATR 用于卡类型识别 (ISO/IEC 7816-4)。卡上的 GUID/UUID 特定于某些智能卡制造商/产品或智能卡应用程序。

因此,对于 GUID/UUID,您应该至少识别产品和制造商文档或使用该特定卡的人员可以回答您是否可以检索此信息以及如何检索(使用标准 API - 例如,如果它存储在 EF 或专有文件中)一个小程序。

从终端端来说,这通常是在经过一些安全验证后使用 SELECT/READ* 或 GET DATA APDU 来完成的。

AFAIK GUID/UUID is not a standard card instance identification mean applicable for any smartcard product. For example, SIM cards are rather identified using the content of a file EF_ICCID (ICC Identification) (ETSI TS 102 221 V6.15.0 (2010-02)) so you can get it through normal UICC file access APIs. The ATR is used for card type identification (ISO/IEC 7816-4). GUID/UUID presence on card is specific to some smartcard manufacturer/product or smartcard application.

So for GUID/UUID you should identify at least the product and the manufacturer doc or someone working with that specific card can answer you if this information is retrievable and how (using standard APIs - e.g. if it's stored in a EF- or proprietary) from an applet.

From terminal side this is usually done using SELECT/READ* or GET DATA APDUs after some security verifications.

Java卡函数获取智能卡GUID/UUID?

走过海棠暮 2024-10-17 18:07:40

我建议您编写一个单独的函数来从数据库中检索值。另外,您应该使用参数化查询来避免 SQL 注入:

public IEnumerable<int> GetPluginIds(int profileId)
{
    using (var connection = new SqlConnection("SOME CONNECTION STRING"))
    using (var cmd = connection.CreateCommand())
    {
        connection.Open();
        cmd.CommandText = "SELECT plugin_id FROM profiles_plugins WHERE profile_id = @profile_id";
        cmd.Parameters.AddWithValue("@profile_id", profileId);
        using (var reader = cmd.ExecuteReader())
        {
            while (reader.Read())
            {
                yield return reader.GetInt32(0);
            }
        }
    }
}

然后像这样调用该函数:

// get the profile_id from session
int profileId = Convert.ToInt32(Session["cod"]);

// fetch associated plugin ids
int[] pluginIds = GetPluginIds(profileId).ToArray();

// store the resulting array into session
Session["pluginIds"] = pluginIds;

I would recommend you writing a separate function for retrieving values from the database. Also you should use parametrized queries to avoid SQL injection:

public IEnumerable<int> GetPluginIds(int profileId)
{
    using (var connection = new SqlConnection("SOME CONNECTION STRING"))
    using (var cmd = connection.CreateCommand())
    {
        connection.Open();
        cmd.CommandText = "SELECT plugin_id FROM profiles_plugins WHERE profile_id = @profile_id";
        cmd.Parameters.AddWithValue("@profile_id", profileId);
        using (var reader = cmd.ExecuteReader())
        {
            while (reader.Read())
            {
                yield return reader.GetInt32(0);
            }
        }
    }
}

and then call the function like this:

// get the profile_id from session
int profileId = Convert.ToInt32(Session["cod"]);

// fetch associated plugin ids
int[] pluginIds = GetPluginIds(profileId).ToArray();

// store the resulting array into session
Session["pluginIds"] = pluginIds;

单个表的多行

走过海棠暮 2024-10-17 16:48:06

这是 Mick 的答案,但针对 Swift 4。(IndexPath 替换了 NSIndexPath,后者带有一个空 IndexPath,因为 nil 会使 Swift 崩溃。此外,您可以使用 == 比较 IndexPath 的两个实例)

声明 ExpandedIndexPath 属性。

var expandedIndexPath = IndexPath()

可选的 viewDidLoad 部分。

expandedIndexPath = IndexPath(row: 1, section: 2)

然后是 didSelectRow 部分。

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    tableView.beginUpdates()

    if indexPath == expandedIndexPath {
        expandedIndexPath = IndexPath()
    } else {
        expandedIndexPath = indexPath
    }

    tableView.endUpdates()
}

然后是 heightForRow 部分。

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    if indexPath == expandedIndexPath {
        return 100
    }

    return 44
}

This is Mick's answer but for Swift 4. (IndexPath replaces NSIndexPath, which comes with an empty IndexPath as nil would crash Swift. Also, you can compare two instances of IndexPath using ==)

Declare the expandedIndexPath property.

var expandedIndexPath = IndexPath()

Optional viewDidLoad part.

expandedIndexPath = IndexPath(row: 1, section: 2)

Then the didSelectRow part.

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    tableView.beginUpdates()

    if indexPath == expandedIndexPath {
        expandedIndexPath = IndexPath()
    } else {
        expandedIndexPath = indexPath
    }

    tableView.endUpdates()
}

Then the heightForRow part.

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    if indexPath == expandedIndexPath {
        return 100
    }

    return 44
}

UITableViewCell 单击展开

走过海棠暮 2024-10-17 11:47:57

border-left: 2px Solid greyborder-right: 2px Solid grey 应用于其中一列怎么样?

How about you apply border-left: 2px solid gray or border-right: 2px solid gray to one of the columns?

在布局中不显眼地插入垂直分隔线

走过海棠暮 2024-10-17 05:23:30

除了@schwiz 的回答之外,您还可以重新考虑您的设计。这里有必要使用2个activity吗?为什么?在这种情况下,使用 2 个活动有什么好处?不过,如果没有看到一些具体细节,我们确实无法回答。

Along with @schwiz's answer, you could also rethink your design. Is it necessary to use 2 activities here? Why? What benefit does using 2 activities provide in this case? We really can't answer without seeing some specifics though.

我怎样才能同时进行 2 个活动

走过海棠暮 2024-10-17 04:44:59

您是否尝试过使用图表向导进行调试?看来您的黑色数据点位于您提供的数据的中间。将它们移至开始/结束位置,看看是否有帮助。

Have you tried debugging using the Chart Wizard? It seems your black data points are located in the middle of your supplied data. Move them to the start/finish and see if that helps.

Google Charts API Z 索引

走过海棠暮 2024-10-17 04:23:57

客户端应将日期时间从本地时间转换为 GMT / UTC,然后再将其发送到数据库。

The client should convert the datetimes from local time to GMT / UTC before sending them to database.

MySql GMT 日期和时区

走过海棠暮 2024-10-17 00:12:16

对于索引集合,您可以执行以下操作:

for(int i = 0; i < col.Length;i++)
{
  if (predicate(col[i]))
    return true;
}
return false;

但对于非索引 IEnumerable,这是不可能的,因为它不提供索引器。这将是框架中的实现(通过反射):

public static bool Any<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
{
    if (source == null)
    {
        throw Error.ArgumentNull("source");
    }
    if (predicate == null)
    {
        throw Error.ArgumentNull("predicate");
    }
    foreach (TSource local in source)
    {
        if (predicate.Invoke(local))
        {
            return true;
        }
    }
    return false;
}

当它迭代 IEnumerable 的所有元素时,不会获得任何性能提升。然而,这个方向上的任何“优化”都会属于过早优化,如果存在性能问题,它更有可能在你的算法中比在这个函数中得到解决。

For indexed collections you could the following:

for(int i = 0; i < col.Length;i++)
{
  if (predicate(col[i]))
    return true;
}
return false;

but for non-indexed IEnumerable<T>, this is not possible, as it doesn't supply an indexer. This would be the implementation in the framework (via reflection):

public static bool Any<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
{
    if (source == null)
    {
        throw Error.ArgumentNull("source");
    }
    if (predicate == null)
    {
        throw Error.ArgumentNull("predicate");
    }
    foreach (TSource local in source)
    {
        if (predicate.Invoke(local))
        {
            return true;
        }
    }
    return false;
}

As it iterates over all elements of the IEnumerable<T>, there is no performance gain to be had. However, any "optimization" in this direction would fall under premature optimization, if there is a performance problem, it is more likely to be fixed in your algorithm than in this function.

在列表上使用 Any 等时的任何性能增益

走过海棠暮 2024-10-16 23:44:57

我遇到了与此类似的问题,尽管它似乎没有根据他的代码解释OP的情况;我只是想把它放在这里以防其他人遇到这个问题。

我将标题视图保留在实例变量中。在我的 viewDidLoad 中,我检查该变量是否为零,如果是,则创建视图,保留实例变量并将其设置为它,并将 tableHeaderView 设置为它。问题是这个条件只会成立一次,因为我的实例变量在我第一次创建它之后就永远不会为零;但是,当出现内存警告时,表视图的 tableHeaderView 属性设置为 nil,因此不会再有标题视图,即使我仍然有在实例变量中查看。

解决方案是更改检查以查看表视图的 tableHeaderView 属性是否为零(然后每次设置为 nil 时重新创建标头视图),或者(因为在此如果我仍然将视图保留在实例变量中),则将赋值移至 if 块之外的 tableHeaderView ,因此每次运行 viewDidLoad 时,我们都会确保将标题视图重新分配给 tableHeaderView,以防它设置为 nil。

I had a similar problem to this, though it doesn't seem to explain the OP's situation based on his code; I just want to put it here in case anyone else comes across this.

I retain my header view in an instance variable. In my viewDidLoad I check to see if this variable is nil, if it is then I create the view, retain and set the instance variable to it and set tableHeaderView to it. The problem is that this condition will only be true once, because my instance variable will never be nil after the first time I create it; however, the table view's tableHeaderView property will be set to nil when there's a memory warning, so there won't be a header view any more, even though I still have the view in an instance variable.

The solution was either to change the check to see if the table view's tableHeaderView's property is nil (and then re-create the header view every time that gets set to nil), or (since in this case I still have the view retained in an instance variable) to move the assignment to tableHeaderView outside of the if-block, thus every time viewDidLoad is run, we will make sure to re-assign the header view to tableHeaderView in case it got set to nil.

自定义UITableView headerView在内存警告后消失

走过海棠暮 2024-10-16 23:06:59

Thread 类有一个 Abort 方法允许您终止线程。也就是说,终止线程的正确方法是使用一些共享资源来指示线程是否应该继续或停止。例如,在线程内部,您可以实现一种机制,在循环中测试此静态变量的值并跳出循环。在主线程上,当您决定终止后台线程时,只需设置静态变量的值,线程就会自行停止。

这是一个示例:

 private static volatile bool _shouldTerminate = false;

在线程内部:

while (!_shouldTerminate)
{
    // .. do something useful
}

当您决定从另一个线程停止该线程时:

_shouldTerminate = true;

The Thread class has an Abort method which allows you to terminate the thread. This being said the proper way to terminate a thread is to use some a shared resource which indicates whether the thread should continue or stop. For example inside the thread you could implement a mechanism which tests the value of this static variable in a loop and break out of the loop. On the main thread when you decide to terminate the background thread simply set the value of the static variable and the thread will simply stop by itself.

Here's an example:

 private static volatile bool _shouldTerminate = false;

and inside the thread:

while (!_shouldTerminate)
{
    // .. do something useful
}

and when you decide to stop the thread from another thread:

_shouldTerminate = true;

获取正在运行的线程

走过海棠暮 2024-10-16 22:51:42

您必须启用http扩展:

http://www.php.net/manual/en/http.setup.php" php.net/manual/en/http.setup.php

或者你可以尝试新的 HTTP_Request2:

sudo pear install --alldeps HTTP_Request2-alpha

然后:

$req = new HTTP_Request2('your.url');
$req->setMethod('POST');
$req->setHeader("content-type", $mimeType);
$req->setBody('');
$response = $req->send();

You must enable http extension:

http://www.php.net/manual/en/http.setup.php

Or you can try new HTTP_Request2:

sudo pear install --alldeps HTTP_Request2-alpha

And then:

$req = new HTTP_Request2('your.url');
$req->setMethod('POST');
$req->setHeader("content-type", $mimeType);
$req->setBody('');
$response = $req->send();

PHP HTTP 请求

更多

推荐作者

泪是无色的血

文章 0 评论 0

yriii2

文章 0 评论 0

1649543945

文章 0 评论 0

g红火

文章 0 评论 0

嘿哥们儿

文章 0 评论 0

旧城烟雨

文章 0 评论 0

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