灯角

文章 评论 浏览 24

灯角 2024-09-25 01:57:52

Chad,你一定要添加 CSS 内联吗?或者您可以通过在 中添加

(抱歉,忘记添加代码的引号)

Chad, do you necessarily have to add the CSS inline? Or could you maybe be better off by adding a <style> block to your <head>? This will in essence replace the need for a reference to a CSS file as well plus maintain the rule that the actual inline rules override the ones set in the header/referenced css file.

(sorry, forgot to add the quotes for code)

C# 中内联 CSS

灯角 2024-09-24 23:51:48

这对我有用。

来自 https://docs.djangoproject.com/en/2.2/topics/ http/sessions/

使用数据库支持的会话 -

如果您想使用数据库支持的会话,您需要将“django.contrib.sessions”添加到您的 INSTALLED_APPS 设置中。

配置安装后,运行 ma​​nage.py migrate 以安装存储会话数据的单个数据库表。

This worked for me.

From https://docs.djangoproject.com/en/2.2/topics/http/sessions/

Using database-backed sessions -

If you want to use a database-backed session, you need to add 'django.contrib.sessions' to your INSTALLED_APPS setting.

Once you have configured your installation, run manage.py migrate to install the single database table that stores session data.

Django:没有这样的表:django_session

灯角 2024-09-23 23:18:58
if ( pwbuf ) sprintf(username,"%s",pwbuf->pw_name);
else sprintf(username,"%d",user_id);

地道且简洁。如果它被触摸超过 2 或 3 次,我会把它括起来并放在下一行。如果添加日志信息或其他条件,它的可维护性不太好。

#if 0
....
#endif

是否打开调试代码块都很好。另外,还可以避免与尝试阻止注释此类事情相关的编译错误:

/* line comment */
...
/* line comment again */

因为 C 块注释不嵌套。

if ( pwbuf ) sprintf(username,"%s",pwbuf->pw_name);
else sprintf(username,"%d",user_id);

Idiomatic and concise. If it got touched more than 2 or 3 times, I would bracket and next-line it. It's not very maintainable if you add logging information or other conditions.

#if 0
....
#endif

Good to turn on blocks of debug code or not. Also, would avoid compilation errors related to trying to block comment this sort of thing out:

/* line comment */
...
/* line comment again */

Since C block comments don't nest.

为什么使用 #if 0 来注释掉块?

灯角 2024-09-23 22:45:45

编译器会根据您的情况进行一些优化,以便 s1s2 实际上是同一对象。您可以通过使用解决这个问题

String s1 = new String( "Hello" );
String s2 = new String( "Hello" );

,然后您就有两个具有相同文本内容的不同对象。

The compiler does some optimizations in your case so that s1 and s2 are really the same object. You can work around that by using

String s1 = new String( "Hello" );
String s2 = new String( "Hello" );

Then you have two distinct objects with the same text content.

演示使用 Java 进行字符串比较

灯角 2024-09-23 21:22:10

沙盒是您正在寻找的术语。简而言之,只将您希望用户调用的函数导出到 Lua。真的就是这么简单。

Sandbox is the term you're looking for. In a nutshell, only export to Lua the functions you want the users to call. It's that simple, really.

如何限制 lua 的可能性(调用操作系统函数、模块等)

灯角 2024-09-23 09:42:17

tldr:ImagedNamed 很好。它可以很好地处理内存。使用它,不再担心。

2012 年 11 月编辑:请注意,这个问题可以追溯到 iOS 2.0!从那时起,图像要求和处理发生了很大变化。视网膜使图像更大并且加载它们稍微复杂一些。由于内置了对 iPad 和视网膜图像的支持,您当然应该在代码中使用 ImageNamed。现在,为了子孙后代的缘故:

Apple 开发者论坛上的姐妹帖子获得了一些更好的流量。具体来说,Rincewind 添加了一些权限。

iPhone OS 2.x 中存在以下问题:即使在内存警告之后,imageNamed: 缓存也不会被清除。同时 +imageNamed: 得到了很多使用,不是为了缓存,而是为了方便,这可能比应有的情况更严重地放大了问题。

同时警告说

在速度方面,人们对正在发生的事情普遍存在误解。 +imageNamed: 所做的最重要的事情是从源文件中解码图像数据,这几乎总是会显着增大数据大小(例如,屏幕大小的 PNG 文件在压缩时可能会消耗几十 KB,但会消耗超过半 MB解压缩 - 宽度 * 高度 * 4)。相比之下,+imageWithContentsOfFile:将在每次需要图像数据时解压缩该图像。正如您可以想象的那样,如果您只需要图像数据一次,那么您在这里什么也得不到,除了保留图像的缓存版本,并且可能比您需要的时间更长。但是,如果您确实有需要经常重绘的大图像,那么还有其他选择,尽管我主要推荐的方法是避免重绘该大图像:)。

关于缓存的一般行为,它基于文件名进行缓存(因此具有相同名称的 +imageNamed: 的两个实例应该导致对相同缓存数据的引用),并且缓存将根据您的请求动态增长更多图片来自 +imageNamed:。在 iPhone OS 2.x 上,一个错误会阻止缓存在收到内存警告时收缩。

我的理解是 +imageNamed: 缓存应该遵守 iPhone OS 3.0 上的内存警告。当您有机会时进行测试,如果发现情况并非如此,请报告错误。

所以,你就知道了。 imageNamed:不会砸碎您的窗户或谋杀您的孩子。它非常简单,但它是一个优化工具。遗憾的是,它的命名很糟糕,并且没有一个易于使用的等效项 - 因此人们过度使用它,并且当它只是完成其工作时感到不安。

我向 UIImage 添加了一个类别来解决这个问题:

// header omitted
// Before you waste time editing this, please remember that a semi colon at the end of a method definition is valid and a matter of style.
+ (UIImage*)imageFromMainBundleFile:(NSString*)aFileName; {
    NSString* bundlePath = [[NSBundle mainBundle] bundlePath];
    return [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", bundlePath,aFileName]];
}

Rincewind 还包含一些示例代码来构建您自己的优化版本。我不认为它值得维护,但这是为了完整性。

CGImageRef originalImage = uiImage.CGImage;
CFDataRef imageData = CGDataProviderCopyData(
     CGImageGetDataProvider(originalImage));
CGDataProviderRef imageDataProvider = CGDataProviderCreateWithCFData(imageData);
CFRelease(imageData);
CGImageRef image = CGImageCreate(
     CGImageGetWidth(originalImage),
     CGImageGetHeight(originalImage),
     CGImageGetBitsPerComponent(originalImage),
     CGImageGetBitsPerPixel(originalImage),
     CGImageGetBytesPerRow(originalImage),
     CGImageGetColorSpace(originalImage),
     CGImageGetBitmapInfo(originalImage),
     imageDataProvider,
     CGImageGetDecode(originalImage),
     CGImageGetShouldInterpolate(originalImage),
     CGImageGetRenderingIntent(originalImage));
CGDataProviderRelease(imageDataProvider);
UIImage *decompressedImage = [UIImage imageWithCGImage:image];
CGImageRelease(image);

此代码的权衡是解码图像使用更多内存,但渲染速度更快。

tldr: ImagedNamed is fine. It handles memory well. Use it and stop worrying.

Edit Nov 2012: Note that this question dates from iOS 2.0! Image requirements and handling have moved on a lot since then. Retina makes images bigger and loading them slightly more complex. With the built in support for iPad and retina images, you should certainly use ImageNamed in your code. Now, for posterity's sake:

The sister thread on the Apple Dev Forums received some better traffic. Specifically Rincewind added some authority.

There are issues in iPhone OS 2.x where the imageNamed: cache would not be cleared, even after a memory warning. At the same time +imageNamed: has gotten a lot of use not for the cache, but for the convenience, which has probably magnified the problem more than it should have been.

whilst warning that

On the speed front, there is a general misunderstanding of what is going on. The biggest thing that +imageNamed: does is decode the image data from the source file, which almost always significantly inflates the data size (for example, a screen sized PNG file might consume a few dozen KBs when compressed, but consumes over half a MB decompressed - width * height * 4). By contrast +imageWithContentsOfFile: will decompress that image everytime the image data is needed. As you can imagine, if you only need the image data once, you've won nothing here, except to have a cached version of the image hanging around, and likely for longer than you need it. However, if you do have a large image that you need to redraw often, then there are alternatives, although the one I would recommend primarily is to avoid redrawing that large image :).

With respect to the general behavior of the cache, it does cache based on filename (so two instances of +imageNamed: with the same name should result in references to the same cached data) and the cache will grow dynamically as you request more images via +imageNamed:. On iPhone OS 2.x a bug prevents the cache from being shrunk when a memory warning is received.

and

My understanding is that the +imageNamed: cache should respect memory warnings on iPhone OS 3.0. Test it when you get a chance and report bugs if you find that this is not the case.

So, there you have it. imageNamed: will not smash your windows or murder your children. It's pretty simple but it is an optimisation tool. Sadly it is badly named and there is no equivaluent that is as easy to use - hence people overuse it and get upset when it simply does its job

I added a category to UIImage to fix that:

// header omitted
// Before you waste time editing this, please remember that a semi colon at the end of a method definition is valid and a matter of style.
+ (UIImage*)imageFromMainBundleFile:(NSString*)aFileName; {
    NSString* bundlePath = [[NSBundle mainBundle] bundlePath];
    return [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", bundlePath,aFileName]];
}

Rincewind also included some example code to build your own optimised version. I can't see it is worth the maintentace but here it is for completeness.

CGImageRef originalImage = uiImage.CGImage;
CFDataRef imageData = CGDataProviderCopyData(
     CGImageGetDataProvider(originalImage));
CGDataProviderRef imageDataProvider = CGDataProviderCreateWithCFData(imageData);
CFRelease(imageData);
CGImageRef image = CGImageCreate(
     CGImageGetWidth(originalImage),
     CGImageGetHeight(originalImage),
     CGImageGetBitsPerComponent(originalImage),
     CGImageGetBitsPerPixel(originalImage),
     CGImageGetBytesPerRow(originalImage),
     CGImageGetColorSpace(originalImage),
     CGImageGetBitmapInfo(originalImage),
     imageDataProvider,
     CGImageGetDecode(originalImage),
     CGImageGetShouldInterpolate(originalImage),
     CGImageGetRenderingIntent(originalImage));
CGDataProviderRelease(imageDataProvider);
UIImage *decompressedImage = [UIImage imageWithCGImage:image];
CGImageRelease(image);

The trade off with this code is that the decoded image uses more memory but rendering is faster.

消除 UIImage imageNamed: FUD

灯角 2024-09-23 04:29:57

还有另一种使用枚举器同时迭代两个数组的方法:

2.1.2 :003 > enum = [1,2,4].each
 => #<Enumerator: [1, 2, 4]:each> 
2.1.2 :004 > enum2 = [5,6,7].each
 => #<Enumerator: [5, 6, 7]:each> 
2.1.2 :005 > loop do
2.1.2 :006 >     a1,a2=enum.next,enum2.next
2.1.2 :007?>   puts "array 1 #{a1} array 2 #{a2}"
2.1.2 :008?>   end
array 1 1 array 2 5
array 1 2 array 2 6
array 1 4 array 2 7

枚举器比上面使用的示例更强大,因为它们允许无限级数、并行迭代等技术。

There is another way to iterate over two arrays at once using enumerators:

2.1.2 :003 > enum = [1,2,4].each
 => #<Enumerator: [1, 2, 4]:each> 
2.1.2 :004 > enum2 = [5,6,7].each
 => #<Enumerator: [5, 6, 7]:each> 
2.1.2 :005 > loop do
2.1.2 :006 >     a1,a2=enum.next,enum2.next
2.1.2 :007?>   puts "array 1 #{a1} array 2 #{a2}"
2.1.2 :008?>   end
array 1 1 array 2 5
array 1 2 array 2 6
array 1 4 array 2 7

Enumerators are more powerful than the examples used above, because they allow infinite series, parallel iteration, among other techniques.

什么是“Ruby 方式”?一次迭代两个数组

灯角 2024-09-23 03:02:47

您可以通过设置:selectedIndex=0 或设置 selectedItem 属性来选择第一个值。

但您应该确保有一个项目可供您选择。例如,这可以在 dataProvider 的 setter 中完成。

You can select the first value by setting: selectedIndex=0 or set the selectedItemproperty.

But you should make sure that there is an item which you can select. This could be for example done in the setter of the dataProvider.

在 ComboBox 中加载数据时应选择第一个值

灯角 2024-09-22 23:15:42

遗憾的是,没有简单的方法可以做到这一点。您使用的是 WH_KEYBOARD_LLWM_INPUT。不过,可能有一个选择:

您是否测试过 WM_INPUT 是否发生在挂钩之前?如果是这种情况,您可以记住来自 WM_INPUT 的字符,并且在钩子中仅删除来自条形码扫描仪的那些字符。

Sadly there is no easy way to do that. You're with your WH_KEYBOARD_LL and WM_INPUT. There might be a chance of an option though:

Have you tested whether WM_INPUT occurs before the hook? If that was the case, you could remember the characters from WM_INPUT and -- in the hook -- remove only those characters that came from your barcode scanner.

Win32:在 WH_KEYBOARD_LL || 中获取设备信息使用原始输入时阻止 WM_INPUT 上的输入

灯角 2024-09-22 11:09:26

将这些单词包含在分发的文件中,但以某种方式对它们进行加密,以使其无法轻松找到明文列表。然后,使用 py2exe 将脚本编译为 .exe。这将阻止大多数学生对程序进行逆向工程并找到加密算法。

如果学生找到了解密例程,那么它是否是强加密并不重要,因此 rot13base64 应该足够了。

(w.decode('rot13') for w in ['sbeovqqra', 'sbeovqqra gbb', 'rira zber sbeovqqra'])

要制作列表,只需对真实单词使用 encode 即可。

当然,像上面建议的那样,哈希也可以工作。

Include the words in your distributed file, but encrypt them somehow to make it impossible to easily find the plaintext list. Then, compile the script to .exe using py2exe. This will stop most students from reverse-engineering the program and finding the encrypting algorithm.

If a student finds the decryption routine, it doesn't matters if it's a strong encryption or not, so rot13 or base64 should be enough.

(w.decode('rot13') for w in ['sbeovqqra', 'sbeovqqra gbb', 'rira zber sbeovqqra'])

For making the list, just use encode on the real words.

Hashes, like suggested above, will work too, of course.

如何“隐藏” py 文件中的脏话?

灯角 2024-09-22 10:26:18

很难说,因为我无法在窗口中加载 GridView 控件。

我建议在 Grid 中为控件嵌套一个布局管理器 Grid,以在控件和 GridView 之间创建分隔。您还应该考虑将所有控件组合到一个 StackPanel 或其他布局管理器中。

无论如何,无论您选择哪种布局管理器,此布局都可以将控件和 GridView 分开,并且无需指定列跨度。

<Grid> 
  <Grid.RowDefinitions> 
    <RowDefinition Height="Auto"/>  
    <RowDefinition Height="*"/> 
  </Grid.RowDefinitions> 
  <Grid.ColumnDefinitions> 
    <ColumnDefinition />
  </Grid.ColumnDefinitions> 

  <!-- Place a layout Grid inside your Grid to deal with controls -->
  <Grid Grid.Column="0" Grid.Row="0">
    <Grid.RowDefinitions>
       <RowDefinition/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
       <ColumnDefinition />
       <ColumnDefinition Width="Auto"/>
    </Grid.ColumnDefinitions>

    <!-- Removed your nested stack panel -->  
    <StackPanel Grid.Column="0" Grid.Row="0" Orientation="Horizontal"> 
      <Label></Label> 
      <TextBox></TextBox> 
    </StackPanel> 
    <StackPanel Grid.Column="1" Grid.Row="0" Orientation="Horizontal"> 
      <Button /> 
    </StackPanel> 
  </Grid>

  <!-- Add a spilter bar here  -->

  <!-- No need to span 2 columns anymore...  -->
  <TelerikGrid:RadGridView Grid.Column="0" Grid.Row="1" > 
    <TelerikGrid:RadGridView.Columns> 
      <TelerikGrid:GridViewDataColumn Width="*"/>  
    </TelerikGrid:RadGridView.Columns> 
  </TelerikGrid:RadGridView> 

  <!-- Add a status bar here -->

</Grid> 

Hard to tell given I cannot load your GridView control in a Window.

I recommend nesting a layout manager Grid for your controls inside your Grid to create a separation between your controls and the GridView. You also should consider combining all the controls in one StackPanel or other layout manager.

Regardless, this layout gives you separation between the controls and the GridView regardless of your choice of layout manager with no need to specify a column span.

<Grid> 
  <Grid.RowDefinitions> 
    <RowDefinition Height="Auto"/>  
    <RowDefinition Height="*"/> 
  </Grid.RowDefinitions> 
  <Grid.ColumnDefinitions> 
    <ColumnDefinition />
  </Grid.ColumnDefinitions> 

  <!-- Place a layout Grid inside your Grid to deal with controls -->
  <Grid Grid.Column="0" Grid.Row="0">
    <Grid.RowDefinitions>
       <RowDefinition/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
       <ColumnDefinition />
       <ColumnDefinition Width="Auto"/>
    </Grid.ColumnDefinitions>

    <!-- Removed your nested stack panel -->  
    <StackPanel Grid.Column="0" Grid.Row="0" Orientation="Horizontal"> 
      <Label></Label> 
      <TextBox></TextBox> 
    </StackPanel> 
    <StackPanel Grid.Column="1" Grid.Row="0" Orientation="Horizontal"> 
      <Button /> 
    </StackPanel> 
  </Grid>

  <!-- Add a spilter bar here  -->

  <!-- No need to span 2 columns anymore...  -->
  <TelerikGrid:RadGridView Grid.Column="0" Grid.Row="1" > 
    <TelerikGrid:RadGridView.Columns> 
      <TelerikGrid:GridViewDataColumn Width="*"/>  
    </TelerikGrid:RadGridView.Columns> 
  </TelerikGrid:RadGridView> 

  <!-- Add a status bar here -->

</Grid> 

帮助我的 WPF 布局

灯角 2024-09-22 08:33:00
 s3 = new S3(S3KEY, S3SECRET, false);
 res = s3->getObjectInfo(bucketName, filename);

如果文件存在则返回数组

 s3 = new S3(S3KEY, S3SECRET, false);
 res = s3->getObjectInfo(bucketName, filename);

It will return array if file exists

根据通配符确定S3存储桶中是否存在对象

灯角 2024-09-22 07:14:00

我让 CI 服务器将以下内容通过管道传输到名为 CHANGELOG 的文件中对于每个新版本,其日期在版本文件名中设置:

git log --graph --all --date=relative --pretty=format:"%x09 %ad %d %s (%aN)"

I let the CI server pipe the following into a file named CHANGELOG for each new release with the date set in the release-filename:

git log --graph --all --date=relative --pretty=format:"%x09 %ad %d %s (%aN)"

使用 Git 管理变更日志有哪些好方法?

灯角 2024-09-21 22:01:30

对 L2S 不太熟悉,但我想说 Daniel 是正确的:从数据库更新你的模型(通常在某个上下文菜单上)。这应该可以防止它尝试将值插入到自动递增的 ID 列中。

我相信可能有一种方法可以将 IDENTIY_INSERT 设置为 ON,但我强烈建议不要这样做。

如果您的表不应该负责设置 CustomerId(例如,企业有某种方法可以做出该决定(尤其是以非线性方式),请将您的 Customer Id 列保留为 PK,但从表中删除身份规范)柱子。

Not too familiar with L2S, but I'd say Daniel is correct: update your model (usually on a context menu somewhere) from the DB. That should prevent it from attempting to insert a value into your auto-incrementing ID column.

I believe there may be a way to have it set IDENTIY_INSERT ON, but I highly recommend against it.

If your table should not be in charge of setting the CustomerId (say, the business has some method of making that determination (especially in a non-linear way), leave your Customer Id column as the PK, but remove the Identity specificaiton from the column.

违反 PRIMARY KEY 约束 无法在 object 中插入重复的键。在 C#.net...Visual Studio 2010...框架 3.5

灯角 2024-09-21 21:01:43

通常,JNDI 在类路径中的 jndi.properties 文件中查找其配置。

也许有一个流氓 jndi.properties 文件误导了您。

有关更多详细信息,请参阅 https://glassfish.dev.java.net/ javaee5/ejb/EJB_FAQ.html#StandaloneRemoteEJB

Normally JNDI looks for its configuration in a jndi.properties file in the class path.

Meybe there is a rogue jndi.properties file misdirecting you.

For more details see https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#StandaloneRemoteEJB

在执行 jndi 查找时,如何找出应该使用什么 SerialContextProvider?

更多

推荐作者

lanyue

文章 0 评论 0

海螺姑娘

文章 0 评论 0

Demos

文章 0 评论 0

亢龙有悔

文章 0 评论 0

海未深

文章 0 评论 0

浅忆流年

文章 0 评论 0

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