intervals

Terminate a thread after an interval if not returned

。_饼干妹妹 提交于 2019-12-05 00:03:04
I have a thread which grabs some data from network or serial port. The thread must terminate (or return false) if no data is received within 5 seconds. In other words, if running the thread is taking more than 5 seconds it must stop. I am writing in C#, but any .NET language is OK. There are two approaches: 1. Encapsulated timeout The thread reading the data from network or serial port can measure time elapsed from its time of start and wait for the data for no more than the remaining time. Network communication APIs usually provide means to specify a timeout for the operation. Hence by doing

Finding All Intervals That Overlap a Point

空扰寡人 提交于 2019-12-04 22:07:57
Consider a large set of floating-point intervals in 1-dimension, e.g. [1.0, 2.5], 1.0 |---------------|2.5 [1.5, 3.6], 1.5|---------------------|3.6 ..... It is desired to find all intervals that contain a given point. For example given point = 1.2, algorithm should return the first interval, and if given point = 2.0, it should return the first two interval in the above example. In the problem I am dealing, this operation needs to be repeated for a large number of times for a large number of intervals. Therefore a brute-force search is not desired and performance is an important factor. After

Two timers with two different intervals C# Form

若如初见. 提交于 2019-12-04 22:04:19
I'm trying to create a chat in c# form and i have created two timers; one of them is checking every 1 second if someone wrote something, the other one is sending every 1 second the message "I'm Online" or "I'm offline" depends on what i have set; the problem is that i'm spamming too much even if i did an if which doesn't show anymore the spam messages; but the problem is even if i don't see the messages, the chat is lagging, i mean more time i let it open more lag it does.. for example if i write a message from another console, i see it after 30 seconds, and the time increases if let it open.

Append div with interval in Jquery

廉价感情. 提交于 2019-12-04 21:39:59
Hi I need help regarding appending div while using 2 types of speed interval via 2 loops Here is my sample code <script type="text/javascript"> $(document).ready(function() { for (var i = 0; i <= 300; i++) { $(".wrapper").append("<div class='item' id='" + i + "'>" + i + "</div>"); if (i==300) { //I need this for loop to slow down my //interval so div will display slower compared to the first 300 for (var i = 300; i <= 500; i++) { $(".wrapper").append("<div class='item' id='" + i + "'>" + i + "</div>"); }; } }; }); var step = 0; function hideItemFunc() { var interval = setInterval(function() {

StopWatch vs Timer - When to Use

 ̄綄美尐妖づ 提交于 2019-12-04 17:39:32
问题 Forgive me for this question, but I can't seem to find a good source of when to use which. Would be happy if you can explain it in simple terms. Furthermore, I am facing this dilemma: See, I am coding a simple application. I want it to show the elapsed time (hh:mm:ss format or something). But also, to be able to "speed up" or "slow down" its time intervals (i.e. speed up so that a minute in real time equals an hour in the app). For example, in Youtube videos ( * let's not consider the fact

Plotting a 95% confidence interval for a lm object

。_饼干妹妹 提交于 2019-12-04 16:29:44
How can I calculate and plot a confidence interval for my regression in r? So far I have two numerical vectors of equal length (x,y) and a regression object(lm.out). I have made a scatterplot of y given x and added the regression line to this plot. I am looking for a way to add a 95% prediction confidence band for lm.out to the plot. I've tried using the predict function, but I don't even know where to start with that :/. Here is my code at the moment: x=c(1,2,3,4,5,6,7,8,9,0) y=c(13,28,43,35,96,84,101,110,108,13) lm.out <- lm(y ~ x) plot(x,y) regression.data = summary(lm.out) #save regression

Maximum sum of the range non-overlapping intervals in a list of Intervals

半世苍凉 提交于 2019-12-04 13:35:11
问题 Someone asked me this question: You are given a list of intervals. You have to design an algorithm to find the sequence of non-overlapping intervals so that the sum of the range of intervals is maximum. For Example: If given intervals are: ["06:00","08:30"], ["09:00","11:00"], ["08:00","09:00"], ["09:00","11:30"], ["10:30","14:00"], ["12:00","14:00"] Range is maximized when three intervals [“06:00”, “08:30”], [“09:00”, “11:30”], [“12:00”, “14:00”], are chosen. Therefore, the answer is 420

parse string of integer sets with intervals to list

♀尐吖头ヾ 提交于 2019-12-04 13:15:31
问题 I have "2,5,7-9,12" string. I want to get [2, 5, 7, 8, 9, 12] list from it. Is there any built-in function for it in python? Thanks. UPD. I suppose, the straight answer is No . Anyway, thanks for your "snippets". Using one, suggested by Sven Marnach . 回答1: This version handles arbitrary whitespace, overlapping ranges, out-of-order ranges, and negative integers: from itertools import chain def group_to_range(group): group = ''.join(group.split()) sign, g = ('-', group[1:]) if group.startswith(

How do you get a dynamic 12 business day view in Postgresql?

寵の児 提交于 2019-12-04 12:46:24
Here is the code I currently have that gives me the last 12 days SELECT * FROM table WHERE analysis_date >= current_date - interval '12' day; analysis_date is the date column in the table. I understand why this isn't working because it's not accounting for business days. How can I rewrite this so that I get an interval of the last 12 business days? I tried search online and found extract(dow from (date)) But I couldn't find an example where I need a weekday interval. Any help would be appreciated. This can be solved with a CTE: WITH business_days_back AS ( WITH RECURSIVE bd(back_day, go_back)

using intervals to assign categorical values

时光毁灭记忆、已成空白 提交于 2019-12-04 09:53:26
Take the following generic data A <- c(5,7,11,10,23,30,24,6) B <- c(1,2,3,1,2,3,1,2) C <- data.frame(A,B) and the following intervals library(intervals) interval1 <- Intervals( matrix( c( 5, 15, 15, 25, 25, 35, 35, 100 ), ncol = 2, byrow = TRUE ), closed = c( TRUE, FALSE ), type = "Z" ) rownames(interval1) <- c("A","B","C", "D") interval2 <- Intervals( matrix( c( 0, 10, 12, 20, 22, 30, 30, 100 ), ncol = 2, byrow = TRUE ), closed = c( TRUE, FALSE ), type = "Z" ) rownames(interval2) <- c("P","Q","R", "S") Now I want to create the following output table So where the A value overlap the two