灯角

文章 评论 浏览 24

灯角 2024-10-07 05:22:00

无论您使用什么实现,您都需要查阅文档。 C++ 目前没有指定任何有关线程的内容,因此它取决于实现(您还没有告诉我们)。

例如,我的 setlocale Linux 手册页包含以下代码片段:

该字符串可以在静态存储中分配。

这并不绝对表明它是线程不安全的,但我会非常警惕。使用 NULL 调用它(即查询)很可能是线程安全的,但一旦有线程修改它,所有的赌注都会消失。

可能最安全的做法(假设它不是线程安全的)是使用互斥体保护对setlocale的所有调用,并有一个特殊的函数来格式化你的数字沿着以下思路:

claim mutex
curr = setlocale to specific value
format number to string
setlocale to curr
release mutex
return string

You need to consult the documentation for whatever implementation you're using. C++ doesn't currently specify anything about threads so it comes down to the implementation (which you haven't yet told us).

For example, my Linux manpage for setlocale has the snippet:

This string may be allocated in static storage.

which doesn't absolutely indicate that it's thread-unsafe but I'd be very wary. It's likely that calling it with NULL (i.e., querying) would be thread-safe but as soon as you have a thread modifying it, all bets are off.

Probably the safest thing to do (assuming it isn't thread-safe) would be to protect all calls to setlocale with a mutex and have a special function to format your numbers along the lines of:

claim mutex
curr = setlocale to specific value
format number to string
setlocale to curr
release mutex
return string

setlocale 是线程安全函数吗?

灯角 2024-10-07 02:05:43

带有标签并悬停?只是提供一个想法

<html>
<head>
<style>
a div{display:none; height:10px;}
a:hover div{display:inline;}
</style>
</head>
<body>
<ul>
  <li><a>a<div id="hover-display-content">Content</div></a></li>
  <li><a>s<div id="more-hover-display-content">Content1</div></a></li>
  <li><a>d<div id="even-more-hover-display-content">Content2</div></a></li>
</ul>  
</body>
</html>

with a tag and hover? just providing an idea

<html>
<head>
<style>
a div{display:none; height:10px;}
a:hover div{display:inline;}
</style>
</head>
<body>
<ul>
  <li><a>a<div id="hover-display-content">Content</div></a></li>
  <li><a>s<div id="more-hover-display-content">Content1</div></a></li>
  <li><a>d<div id="even-more-hover-display-content">Content2</div></a></li>
</ul>  
</body>
</html>

Javascript 悬停内容显示

灯角 2024-10-07 01:54:32

根据 ,它的意思是“操作会导致进程暂停。”

According to this, it means "Operation would have caused the process to be suspended."

EAGAIN 是什么意思?

灯角 2024-10-07 01:34:47

模拟和存根很棒,但有时您需要将其提升到下一个集成级别。由于生成服务器(即使是假的服务器)可能需要一些时间,因此考虑一个单独的测试套件(称为集成测试)可能是合适的。

“像要使用它一样测试它”是我的指导方针,如果你模拟和存根太多以至于你的测试变得微不足道,那么它就没那么有用(尽管几乎任何测试都比没有好)。如果您担心处理不良 SSL 证书,请务必制作一些不良证书并编写一个可以将其提供给的测试装置。如果这意味着生成一个服务器,那就这样吧。也许如果这让你足够烦恼的话,它会导致重构,使其可以以另一种方式进行测试。

Mocking and stubbing are great, but sometimes you need to take it up to the next level of integration. Since spawning a server, even a fakeish one, can take some time, consider a separate test suite (call them integration tests) might be in order.

"Test it like you are going to use it" is my guideline, and if you mock and stub so much that your test becomes trivial it's not that useful (though almost any test is better than none). If you are concerned about handling bad SSL certs, by all means make some bad ones and write a test fixture you can feed them to. If that means spawning a server, so be it. Maybe if that bugs you enough it will lead to a refactoring that will make it testable another way.

Python:单元测试基于套接字的代码?

灯角 2024-10-07 00:45:56

我会在控制器中创建日历,例如这样:

@Controller
public class CalendarController{

    private static final int START_OF_WEEK = DateTimeConstants.MONDAY;

    @RequestMapping("drawCalendar")
    public ModelAndView drawCalendar(@RequestParam("month") final int month,
        @RequestParam("year") final int year){
        final LocalDate monthStart = new LocalDate(year, month, 1);
        boolean endReached = false;
        LocalDate today = null;
        final List<List<LocalDate>> weeks1 = new ArrayList<List<LocalDate>>();
        while(!endReached){
            final List<LocalDate> thisWeek = new ArrayList<LocalDate>();
            for(int weekOffset = 0; weekOffset < 7; weekOffset++){
                if(today == null){
                    if(!endReached
                        && weekOffset == monthStart.getDayOfWeek()
                            - START_OF_WEEK){
                        today = monthStart;
                    }
                } else{
                    today = today.plusDays(1);
                    if(today.getMonthOfYear() != month){
                        today = null;
                        endReached = true;
                    }
                }
                thisWeek.add(today);
            }
            weeks1.add(thisWeek);
        }
        final List<List<LocalDate>> weeks = weeks1;

        final Map<String, Object> model = new HashMap<String, Object>();
        model.put("calendar", weeks);
        final ModelAndView modelAndView = new ModelAndView("calendar", model);
        return modelAndView;
    }
}

在 JSP 中我会迭代几周:(

<c:forEach items="${calendar}" var="week">
    <tr>
        <td>Mon</td>
        <td>Tue</td>
        <td>Wed</td>
        <td>Thu</td>
        <td>Fri</td>
        <td>Sat</td>
        <td>Sun</td>
    </tr>
    <tr>
        <c:forEach items="${week}" var="date">
            <td><c:out value="${date==null ? '' : date.dayOfWeek}"</td>
        </c:forEach>
    </tr>
</c:forEach>

当然,我大约 3 年没有编写任何 JSP 代码,如果出现问题,很抱歉)

I would create the calendar in the controller, for example like this:

@Controller
public class CalendarController{

    private static final int START_OF_WEEK = DateTimeConstants.MONDAY;

    @RequestMapping("drawCalendar")
    public ModelAndView drawCalendar(@RequestParam("month") final int month,
        @RequestParam("year") final int year){
        final LocalDate monthStart = new LocalDate(year, month, 1);
        boolean endReached = false;
        LocalDate today = null;
        final List<List<LocalDate>> weeks1 = new ArrayList<List<LocalDate>>();
        while(!endReached){
            final List<LocalDate> thisWeek = new ArrayList<LocalDate>();
            for(int weekOffset = 0; weekOffset < 7; weekOffset++){
                if(today == null){
                    if(!endReached
                        && weekOffset == monthStart.getDayOfWeek()
                            - START_OF_WEEK){
                        today = monthStart;
                    }
                } else{
                    today = today.plusDays(1);
                    if(today.getMonthOfYear() != month){
                        today = null;
                        endReached = true;
                    }
                }
                thisWeek.add(today);
            }
            weeks1.add(thisWeek);
        }
        final List<List<LocalDate>> weeks = weeks1;

        final Map<String, Object> model = new HashMap<String, Object>();
        model.put("calendar", weeks);
        final ModelAndView modelAndView = new ModelAndView("calendar", model);
        return modelAndView;
    }
}

and in the JSP I would iterate over the weeks:

<c:forEach items="${calendar}" var="week">
    <tr>
        <td>Mon</td>
        <td>Tue</td>
        <td>Wed</td>
        <td>Thu</td>
        <td>Fri</td>
        <td>Sat</td>
        <td>Sun</td>
    </tr>
    <tr>
        <c:forEach items="${week}" var="date">
            <td><c:out value="${date==null ? '' : date.dayOfWeek}"</td>
        </c:forEach>
    </tr>
</c:forEach>

(of course I haven't written any JSP code in about 3 years, so sorry if something is wrong)

用于显示大型事件类型日历的 JSP 自定义标记

灯角 2024-10-06 20:47:25

您可以使用正则表达式来提取您的元素。

Dim input As String = "10/BSC/01"
Dim matches As MatchCollection = Regex.Matches(input, "(\d+)/(\w+)/(\d+)")

Dim year As Integer = Integer.Parse(matches(0).Groups(1).Value)
Dim course As String = matches(0).Groups(2).Value
Dim rollNumber As Integer = Integer.Parse(matches(0).Groups(3).Value)

Dim result As String = String.Format("{0}/{1}/{2}", year + 1, course, rollNumber)

You can use a regular expression to extract your elements.

Dim input As String = "10/BSC/01"
Dim matches As MatchCollection = Regex.Matches(input, "(\d+)/(\w+)/(\d+)")

Dim year As Integer = Integer.Parse(matches(0).Groups(1).Value)
Dim course As String = matches(0).Groups(2).Value
Dim rollNumber As Integer = Integer.Parse(matches(0).Groups(3).Value)

Dim result As String = String.Format("{0}/{1}/{2}", year + 1, course, rollNumber)

vb.net 文本框控件

灯角 2024-10-06 19:46:30

我强烈推荐 Scratch,特别是对于非当前程序员。很多例子,视觉的而不是语法导向的,游戏是主要目标。还有一个基于 Scratch 的 Android 应用构建器

I'd strongly recommend Scratch, especially for non-current-programmers. Lots of examples, visual and not syntax-oriented, and games are a primary target. There's also an app builder for Android based on Scratch.

对于向初学者教授游戏开发,是否有 Flash 的良好替代方案?

灯角 2024-10-06 06:14:34

函数 printf 返回一个整数

int printf ( const char * format, ... );

因此,只要 my_func 采用整数作为参数,您就可以在 my_func 中使用它。事实似乎并非如此。

The function printf returns an integer.

int printf ( const char * format, ... );

Hence, you can use it in my_func as long as my_func takes an integer as parameter. This does not seem to be the case.

printf 作为函数的参数

灯角 2024-10-06 02:38:17

我的应用程序委托中有这个,无论我以哪种方式转动它,它都会保持横向:

- (void) applicationDidFinishLaunching:(UIApplication*)application
{
    // CC_DIRECTOR_INIT()
    //
    // 1. Initializes an EAGLView with 0-bit depth format, and RGB565 render buffer
    // 2. EAGLView multiple touches: disabled
    // 3. creates a UIWindow, and assign it to the "window" var (it must already be declared)
    // 4. Parents EAGLView to the newly created window
    // 5. Creates Display Link Director
    // 5a. If it fails, it will use an NSTimer director
    // 6. It will try to run at 60 FPS
    // 7. Display FPS: NO
    // 8. Device orientation: Portrait
    // 9. Connects the director to the EAGLView
    //
    CC_DIRECTOR_INIT();

    // Obtain the shared director in order to...
    CCDirector *director = [CCDirector sharedDirector];

    // Sets landscape mode
    [director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];

    // Turn on display FPS
    [director setDisplayFPS:YES];

    // Turn on multiple touches
    EAGLView *view = [director openGLView];
    [view setMultipleTouchEnabled:YES];

    // Default texture format for PNG/BMP/TIFF/JPEG/GIF images
    // It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
    // You can change anytime.
    [CCTexture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA8888];    


    [[CCDirector sharedDirector] runWithScene: [HelloWorld scene]];
}

I have this in my application delegate and it stays in landscape no matter which way I turn it:

- (void) applicationDidFinishLaunching:(UIApplication*)application
{
    // CC_DIRECTOR_INIT()
    //
    // 1. Initializes an EAGLView with 0-bit depth format, and RGB565 render buffer
    // 2. EAGLView multiple touches: disabled
    // 3. creates a UIWindow, and assign it to the "window" var (it must already be declared)
    // 4. Parents EAGLView to the newly created window
    // 5. Creates Display Link Director
    // 5a. If it fails, it will use an NSTimer director
    // 6. It will try to run at 60 FPS
    // 7. Display FPS: NO
    // 8. Device orientation: Portrait
    // 9. Connects the director to the EAGLView
    //
    CC_DIRECTOR_INIT();

    // Obtain the shared director in order to...
    CCDirector *director = [CCDirector sharedDirector];

    // Sets landscape mode
    [director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];

    // Turn on display FPS
    [director setDisplayFPS:YES];

    // Turn on multiple touches
    EAGLView *view = [director openGLView];
    [view setMultipleTouchEnabled:YES];

    // Default texture format for PNG/BMP/TIFF/JPEG/GIF images
    // It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
    // You can change anytime.
    [CCTexture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA8888];    


    [[CCDirector sharedDirector] runWithScene: [HelloWorld scene]];
}

[ios.cocos2d+box2d]如何禁用自动旋转?

灯角 2024-10-05 21:09:28

看一下 MoreLinq Batch:- http ://code.google.com/p/morelinq/source/browse/trunk/MoreLinq/Batch.cs?r=84

其实现为:

public static IEnumerable<IEnumerable<TSource>> Batch<TSource>(
              this IEnumerable<TSource> source, int size)
{
  TSource[] bucket = null;
  var count = 0;

  foreach (var item in source)
  {
      if (bucket == null)
          bucket = new TSource[size];

      bucket[count++] = item;
      if (count != size)
          continue;

      yield return bucket;

      bucket = null;
      count = 0;
  }

  if (bucket != null && count > 0)
      yield return bucket.Take(count);
}

Take a look at MoreLinq Batch :- http://code.google.com/p/morelinq/source/browse/trunk/MoreLinq/Batch.cs?r=84

Which is implemented as:

public static IEnumerable<IEnumerable<TSource>> Batch<TSource>(
              this IEnumerable<TSource> source, int size)
{
  TSource[] bucket = null;
  var count = 0;

  foreach (var item in source)
  {
      if (bucket == null)
          bucket = new TSource[size];

      bucket[count++] = item;
      if (count != size)
          continue;

      yield return bucket;

      bucket = null;
      count = 0;
  }

  if (bucket != null && count > 0)
      yield return bucket.Take(count);
}

我可以改进这些分页扩展方法吗?

灯角 2024-10-05 20:26:31

3D 图表轴渲染器标签布局不如 2D 图表智能,因为 3D 空间中的布局并不那么容易。

您可以尝试使用 AxisRenderer3D 上的 labelRotation 属性来旋转标签,以免它们折叠。或者使用同一对象上的 fontSize 属性来减小它们的大小。

<ilog:ColumnChart3D ...>
   ...
   <ilog:horizontalAxisRenderer>
     <ilog:AxisRenderer3D labelRotation="30" fontSize="8"/>
   </ilog:horizontalAxisRenderer>
</ilog:ColumnChart3D>

您还可以根据需要使用 canDropLabels 属性删除一些标签。

仅供参考 IBM ILOG Elixir 确实有特定的论坛此处,您可以在其中找到有关产品的信息。

The 3D charts axis renderer labels layout is not as smart as the one of the 2D charts due to the layout in a 3D space that is not as easy.

You can try to labelRotation property on the AxisRenderer3D to rotate the labels so that they don't collapse. Or reduce their size using the fontSize property on the same object.

<ilog:ColumnChart3D ...>
   ...
   <ilog:horizontalAxisRenderer>
     <ilog:AxisRenderer3D labelRotation="30" fontSize="8"/>
   </ilog:horizontalAxisRenderer>
</ilog:ColumnChart3D>

You can also remove some labels using the canDropLabels property is needed.

FYI IBM ILOG Elixir does have specific forum here where you can find information on the product.

ILog Elixir ColumnChart3D 标签格式不正确

灯角 2024-10-05 19:56:50

假设您对这个问题的回答是“是”(尽管我建议采用不同的方法,请参见下文),这将满足您的要求:

public String[] get_status(string local_fname) 
{ 
    var dts_doc = new HtmlAgilityPack.HtmlDocument(); 
    dts_doc.Load(local_fname); 

    //Pull the values 
    var ViewState = dts_doc.DocumentNode.SelectSingleNode("/html[1]/body[1]/div[1]/input[4]/@value[1]"); 
    var EventValidation = dts_doc.DocumentNode.SelectSingleNode("/html[1]/body[1]/div[2]/input[1]/@value[1]"); 

    string ViewState2 = ViewState.Attributes[3].Value; 
    string EventValidation2 = EventValidation.Attributes[3].Value; 

    String[] retValues = new String[2];
    retValues[0] = ViewState2;
    retValues[1] = EventValidation2;

    return retValues;

    //Display the values 

    //System.Console.WriteLine(ViewState.Attributes[3].Value); 
    //System.Console.WriteLine(EventValidation.Attributes[3].Value); 
    //System.Console.ReadKey(); 
    return ViewState2; 
} 

也就是说,我会遵循该方法。


我会编写一个包含您想要的数据成员的类:

public class DataClass
{
    public string ViewState { get; set; }
    public string EventValidation { get; set; }
}

然后我会修改该方法以返回数据类的实例。

public DataClass get_status(string local_fname) 
{ 
    var dts_doc = new HtmlAgilityPack.HtmlDocument(); 
    dts_doc.Load(local_fname); 

    //Pull the values 
    var ViewState = dts_doc.DocumentNode.SelectSingleNode("/html[1]/body[1]/div[1]/input[4]/@value[1]"); 
    var EventValidation = dts_doc.DocumentNode.SelectSingleNode("/html[1]/body[1]/div[2]/input[1]/@value[1]"); 

    var dc = new DataClass();

    dc.ViewState = ViewState.Attributes[3].Value;
    dc.EventValidation = EventValidation.Attributes[3].Value;

    return dc;
} 

Assuming you answer yes to this question (although I'd recommend a different approach, see below) this will do what you're asking:

public String[] get_status(string local_fname) 
{ 
    var dts_doc = new HtmlAgilityPack.HtmlDocument(); 
    dts_doc.Load(local_fname); 

    //Pull the values 
    var ViewState = dts_doc.DocumentNode.SelectSingleNode("/html[1]/body[1]/div[1]/input[4]/@value[1]"); 
    var EventValidation = dts_doc.DocumentNode.SelectSingleNode("/html[1]/body[1]/div[2]/input[1]/@value[1]"); 

    string ViewState2 = ViewState.Attributes[3].Value; 
    string EventValidation2 = EventValidation.Attributes[3].Value; 

    String[] retValues = new String[2];
    retValues[0] = ViewState2;
    retValues[1] = EventValidation2;

    return retValues;

    //Display the values 

    //System.Console.WriteLine(ViewState.Attributes[3].Value); 
    //System.Console.WriteLine(EventValidation.Attributes[3].Value); 
    //System.Console.ReadKey(); 
    return ViewState2; 
} 

That said, I would follow the approach afte the line.


I'd write a class that has the data members you want:

public class DataClass
{
    public string ViewState { get; set; }
    public string EventValidation { get; set; }
}

Then I'd modify the method to return an instance of your data class.

public DataClass get_status(string local_fname) 
{ 
    var dts_doc = new HtmlAgilityPack.HtmlDocument(); 
    dts_doc.Load(local_fname); 

    //Pull the values 
    var ViewState = dts_doc.DocumentNode.SelectSingleNode("/html[1]/body[1]/div[1]/input[4]/@value[1]"); 
    var EventValidation = dts_doc.DocumentNode.SelectSingleNode("/html[1]/body[1]/div[2]/input[1]/@value[1]"); 

    var dc = new DataClass();

    dc.ViewState = ViewState.Attributes[3].Value;
    dc.EventValidation = EventValidation.Attributes[3].Value;

    return dc;
} 

C# 数组转换

灯角 2024-10-05 18:57:38

即使使用最新版本的 IE9,我也遇到同样的问题。正如 MeProtozoan 所建议的,向锚点添加透明背景图像可以使行为按预期工作,但是该死的它很脏。

Even with the latest version of IE9 I have this same issue. As MeProtozoan suggested, adding a transparent background image to the anchor(s) gets the behavior working as desired, but damn it's dirty.

IE8:Div悬停仅在设置背景颜色时才起作用,很奇怪,为什么?

灯角 2024-10-05 14:51:15

如果您使用 mappedBy 属性(您无论如何都应该使用)将双向关联的一侧作为关联的拥有一侧,您是否会遇到同样的问题?像这样:

@Entity public class Group {
  ...
  @ManyToMany(fetch = FetchType.EAGER, mappedBy="groups")
  List<User> users;
}

@Entity public class User {
  ...
  @ManyToMany(fetch = FetchType.EAGER)
  List<Group> groups;
}

更新: 我找不到任何证据表明禁止在双向关联的两侧使用 EAGER 获取,据我所知,没有提到这样的限制在 Hibernate 文档和/或 JPA 规范中。

实际上,根据 Emmanuel Bernard 对一个(某种程度上相似)问题的评论

LAZYEAGER 应该与代码库中的无限循环问题正交。 Hibernate 知道如何处理循环图

对我来说,上面的内容非常清楚,Hibernate 应该能够处理您的映射(正如我在评论中提到的),并且我很想将任何矛盾的行为视为错误。

如果您可以提供一个可以重现问题的测试用例,我的建议是提出一个问题。

Do you get the same problem if you make one of the sides of your bidirectional assocation the owning side of the association using the mappedBy attribute (that you should use anyway)? Like this:

@Entity public class Group {
  ...
  @ManyToMany(fetch = FetchType.EAGER, mappedBy="groups")
  List<User> users;
}

@Entity public class User {
  ...
  @ManyToMany(fetch = FetchType.EAGER)
  List<Group> groups;
}

Update: I can't find any evidence that using EAGER fetching on both sides of a bidirectional association is forbidden and AFAIK, there is no mention of such a restriction in the Hibernate documentation and / or the JPA specification.

Actually, according to this comment from Emmanuel Bernard to a (somehow similar) issue:

LAZY or EAGER should be orthogonal to an infinite loop issue in the codebase. Hibernate knows how to handle cyclic graphs

For me, the above is pretty clear, Hibernate should be able to handle your mapping (as I mentioned in a comment) and I would be tempted to consider any contradictory behavior as a bug.

If you can provide a test case allowing to reproduce the problem, my suggestion would be to open an issue.

hibernate @ManyToMany 双向急切获取

灯角 2024-10-05 04:08:06

0xA002 是 Linux 中的非法枚举错误。

你明白了,因为不可能修改缓冲器的增益。没有这样的事。

您可以做的是将 AL_GAIN 属性设置为侦听器(将其应用于当前上下文中的所有源)或特定源。

0xA002 is an ILLEGAL ENUM ERROR in linux.

You got that because it's impossible to modify the gain of a buffer. There's no such thing.

What you can do is set the AL_GAIN attribute either to the listener (applying it to all sources in the current context) or to a particular source.

OpenAL中如何设置通道增益?

更多

推荐作者

搞钱吧!!!

文章 0 评论 0

zhangMack

文章 0 评论 0

qq_je1Wlq

文章 0 评论 0

fsdcds

文章 0 评论 0

unknown

文章 0 评论 0

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