range

How can I pattern match on a range in Scala?

谁都会走 提交于 2019-12-17 16:00:31
问题 In Ruby I can write this: case n when 0...5 then "less than five" when 5...10 then "less than ten" else "a lot" end How do I do this in Scala? Edit: preferably I'd like to do it more elegantly than using if . 回答1: Inside pattern match it can be expressed with guards: n match { case it if 0 until 5 contains it => "less than five" case it if 5 until 10 contains it => "less than ten" case _ => "a lot" } 回答2: class Contains(r: Range) { def unapply(i: Int): Boolean = r contains i } val C1 = new

Set textarea selection in Internet Explorer

时光总嘲笑我的痴心妄想 提交于 2019-12-17 15:56:22
问题 I'm looking for a way to set a selection in a textarea in Internet Explorer. In other browsers, this works just fine: textarea.selectionStart = start; textarea.selectionEnd = end; In IE, I assume I have to use createRange and adjust the selection somehow, but I cannot figure out how. Extra bonus points for a link to a proper documentation about createRange and associated methods, MSDN isn't helping out much. 回答1: This works for me: <textarea id="lol">

How to check if an integer is within a range of numbers in PHP?

只谈情不闲聊 提交于 2019-12-17 15:34:15
问题 How can I check if a given number is within a range of numbers? 回答1: The expression: ($min <= $value) && ($value <= $max) will be true if $value is between $min and $max , inclusively See the PHP docs for more on comparison operators 回答2: You can use filter_var filter_var( $yourInteger, FILTER_VALIDATE_INT, array( 'options' => array( 'min_range' => $min, 'max_range' => $max ) ) ); This will also allow you to specify whether you want to allow octal and hex notation of integers. Note that the

MySQL display all date in between range [duplicate]

落花浮王杯 提交于 2019-12-17 14:55:48
问题 This question already has answers here : generate days from date range (29 answers) Closed 6 years ago . I want to display all dates between a from and to dates from MySQL. For example the data from schedule table that has from and to fields are: from date is 2013-3-13 , and to date is 2013-3-20 , my desired result is: 2013-3-13 2013-3-14 2013-3-15 2013-3-16 2013-3-17 2013-3-18 2013-3-19 2013-3-20 How can I achieve this using MySQL query only (without having to use stored procedure 'cause I'm

Winform文件下载之断点续传

半腔热情 提交于 2019-12-17 14:25:03
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 在本系列的前两篇文章中,分别向大家介绍了用于完成下载任务的 WebClinet 和 WinINet 的基本用法和一些实用技巧。 今天来为大家讲述下载过程中最常遇到的断点续传问题。 首先明确一点,本文所说的断点续传特指 HTTP 协议中的断点续传,文章中讲述了实现断点续传的方法思路和关键代码,想了解更多细节的同学,请下载并查看本文附带的 demo。 工作原理 http 协议中定义了一些请求/响应头,通过组合使用这些头信息,即可实现分批下载同一文件的目的。例如,在一次 http 请求中只请求文件中的一部分数据,然后将请求到的数据保存起来,下次只需请求剩余部分的数据,当全部数据都下载到本地后再完成数据的合并工作。 http 协议指出,可以通过 http 请求中的 Range 头来指定请求数据的范围。 Range 头的使用很简单,按照如下的格式使用即可: Range: bytes=500-999 上述意思为:只请求目标文件的第500至第999,这500个字节。 举例说明,有一个1000 字节大小的文件需要下载,第一次请求时不指定 Range 头,表示下载整个文件;但在下载完第499个字节后,下载被中断了,那么在下一次请求剩余文件时,只需要下载第500个至第999个字节的数据即可。 原理看上去很简单

Merge overlapping ranges into unique groups, in dataframe

懵懂的女人 提交于 2019-12-17 12:02:31
问题 I have a dataframe of n rows and 3 df <- data.frame(start=c(178,400,983,1932,33653), end=c(5025,5025, 5535, 6918, 38197), group=c(1,1,2,2,3)) df start end group 1 178 5025 1 2 400 5025 1 3 983 5535 2 4 1932 6918 2 5 33653 38197 3 I would like to make a new column df$group2 that re-classifies groups that overlap to be the same. For example, df$group[df$group==1] starts at 178 and ends at 5025. This overlaps with df$group[df$group==2] , which starts at 983 and ends at 6918. I would like to make

Generate N random numbers within a range with a constant sum

南楼画角 提交于 2019-12-17 11:52:35
问题 I want to generate N random numbers drawn from a specif distribution (e.g uniform random) between [a,b] which sum to a constant C. I have tried a couple of solutions I could think of myself, and some proposed on similar threads but most of them either work for a limited form of problem or I can't prove the outcome still follows the desired distribution. What I have tried: Generage N random numbers, divide all of them by the sum of them and multiply by the desired constant. This seems to work

Generate N random numbers within a range with a constant sum

无人久伴 提交于 2019-12-17 11:52:01
问题 I want to generate N random numbers drawn from a specif distribution (e.g uniform random) between [a,b] which sum to a constant C. I have tried a couple of solutions I could think of myself, and some proposed on similar threads but most of them either work for a limited form of problem or I can't prove the outcome still follows the desired distribution. What I have tried: Generage N random numbers, divide all of them by the sum of them and multiply by the desired constant. This seems to work

Create Chart from Array data and not range

房东的猫 提交于 2019-12-17 10:48:44
问题 is it possible to create a Chart (e.g. Double Y-Axis Line Chart) not from Ranges, but from Array data? If so, how? 回答1: Yes. You can assign arrays to the XValues and Values properties of a Series object on a chart. Example: Dim c As Chart Dim s As Series Dim myData As Variant Set c = ActiveChart ' Assumes a chart is currently active in Excel... Set s = c.SeriesCollection(1) myData = Array(9, 6, 7, 1) ' or whatever s.Values = myData 回答2: You can assign arrays to chart series in Excel 2007

Parsing HTTP_RANGE header in PHP

孤者浪人 提交于 2019-12-17 10:46:59
问题 Is there an existing way to parse the HTTP_RANGE header correctly in PHP? Thought I'd ask here before re-inventing the wheel. I am currently using preg_match('/bytes=(\d+)-(\d+)/', $_SERVER['HTTP_RANGE'], $matches); to parse the header but that does not cover all possible values of the header so I am wondering if there is a function or library that can do this already? Thanks in advance. 回答1: Rather use regex to test it before sending a 416. Then just parse it by exploding on the comma , and