I have a SQL Server 2016 table with an order/position column.  This column is an INT that indicates the preferred order/position of the rows in table for presentation purposes.   How do I INSERT a row in position 1 without using a cursor?  (i.e. new row has position 1, existing rows - assumed to be in correct order before insert - must be "moved down")   The order/position column is NOT NULL and enforced to be UNIQUE. I would also prefer not to use "blunt force" technique like set all rows' order/position value to some "never used" values and then just perform reorder on all rows.
I have a common scenario in app design, where I need to store an ordered list, and make the ordering easily accessible and adjustable via an application UI.    The ordering operations are simple and operate on only one item at a time - move to top, move to bottom, move up one position, or down one position.  These positioning operations may be interspersed in with typical add / edit / delete list operations.  For discussion, this is a single-user app and db store.  Because the objects can be highly complex, I'd like to avoid caching the entire list client-side, and tracking newly created objects in memory until a big save operation occurs.    I am using MS-SQL almost exclusively on these projects, and I'm wondering if there are db features, SQL features, or design patterns I should be using to better support the management of ordered lists.    My current approach is to use a DECIMAL column to store the list positions, which become fractional during the item move process.  Then I sort the list and re-generate integer positions to normalize list.  Following this operation, it's ready for another item move.   In an example implementation, I create a column named Seq for position tracking.  Once decimal place is enough for the .5 storage.   [Seq] [decimal](10, 1) NOT NULL   When an item is re-positioned in the app UI,    I UPDATE that record with new Seq value I retrieve the full table, sorted ascending by Seq and regenerate all Seq values in the table from a 1-based integer series   The new Seq value is easily calculated-    Move to top = 0 Move to bottom = MAX(Seq) + 1 Move up = subtract 1.5 from the current Seq value Move down = add 1.5 to the current Seq value   As lists get longer, updates get slower, since I'm doing N UPDATE statements, where N is the number of rows in the table, so it seems only suitable for small tables.    Is there some kind of in-built capability for managing an ordered list in SQL or MS-SQL? Is there a means to update multiple rows in one call?    A far more performant approach would be to allow more decimal places, and then position at the median of the two adjacent items, with no re-sequencing on the list.     Move to top = Min(Seq) - 1 Move to bottom = MAX(Seq) + 1 Move up = median of the 2 previous item Seq values Move down = median of the 2 following item Seq values   This approach only requires one SELECT (containing 2 rows max) and one UPDATE.    However with enough re-positions I imagine the field would run out of decimal places. For example, if I start with items at positions 10 and 11, and keep moving items down the list from position 9, they'd be given sequences of 10.5, then 10.25, then 10.125.  After 10 moves, the positions get lengthy... 10.0009765625.    UPDATE #1 - IMPROVED RE-SEQUENCING OF THE LIST  Regarding re-sequencing, I'm more caught up on row_number(), OVER, and WITH capabilities in MS-SQL.  It's nice to find that there's a much smoother way to re-sequence the list in a single UPDATE operation;  with OrderedItems as  (     select         ItemID,         Seq,         row_number() over (order by Seq asc) NewSeq     from          Items ) update OrderedItems set Seq = NewSeq
How to limit Docker total resources? I'm trying to limit the total resources accessible from docker (for example only 90% of the RAM and 1500% of the CPU). I cannot use CPU and RAM limit when I'm launching my containers, that's why I need to limit the total resources available for docker containers.  I have around 20 containers which can consume the maximum CPU and memory but not at the same time, so I cannot set the CPU and RAM limit, that's why I need to limit the total resource used by docker  First of all I've created a slice: I tried the instruction above, but impossible to limit both the RAM and the CPU usage  # /etc/systemd/system/docker_limit.slice [Unit] Description=Slice that limits docker resources Before=slices.target  [Slice] CPUAccounting=true CPUQuota=700% #Memory Management MemoryAccounting=true MemoryHigh=20G MemoryMax=25G MemoryMaxSwap=10G   And my daemon.json  {   "insecure-registries" : [ "url1", "url2"],   "cgroup-parent": "docker_limit.slice" }   But when I try from a container:  stress --vm-bytes $(awk '/MemAvailable/{printf "%d\n", $2 * 0.9;}' &lt; /proc/meminfo)k --vm-keep -m 1   I can see from docker stats it's using 111Go of Ram (full capacity of my server)  stress --cpu 16   I can see from docker stats it's using near 1600 % (full capacity of my server)  I think I've missed something but I don't know what What do I need for extreme macro photography? What I would like is a method to convert a double to a string which rounds using the half-up method - i.e. if the decimal to be rounded is 5, it always rounds up to the next number. This is the standard method of rounding most people expect in most situations.  I also would like only significant digits to be displayed - i.e. there should not be any trailing zeroes.  I know one method of doing this is to use the String.format method:  String.format("%.5g%n", 0.912385);   returns:  0.91239   which is great, however it always displays numbers with 5 decimal places even if they are not significant:   String.format("%.5g%n", 0.912300);   returns:  0.91230   Another method is to use the DecimalFormatter:  DecimalFormat df = new DecimalFormat("#.#####"); df.format(0.912385);   returns:  0.91238   However as you can see this uses half-even rounding. That is it will round down if the previous digit is even. What I'd like is this:  0.912385 -&gt; 0.91239 0.912300 -&gt; 0.9123   What is the best way to achieve this in Java? Input impedance of Arduino Uno analog pins? I'm using the  on some small robotic arm motors, and reading in the analog voltage with an Arduino Uno.  I've had reasonably good results, but only after putting in an RC filter on the output.  However, in the application note on the datasheet, it says not to do that:  "the addition of an RC filter to the output of a sensor IC can result in undesirable device output attenuation — even for DC signals."  Then it gives a formula to calculate attenuation, but it depends on knowing the input impedance of whatever is reading the signal, so that's what I'm after here. How does order-preserving encryption work? Order-preserving encryption (OPE) is, apparently, a method of encrypting data so that it's possible to make efficient inequality comparisons on the encrypted items without decrypting them.  I've been coming across this term in various places (including ) lately, but I have no idea how such encryption schemes are supposed to work.  Any obvious methods I can think of to allow such comparisons on encrypted data would result in catastrophic security failure.  Certainly, I assume that OPE must involve some kind of security tradeoff compared to traditional encryption, but given that it seems to be actively  and , it seems that it must be possible to implement in a way that retains at least some level of useful security.  I just don't see how.  Given that  didn't turn up any convenient Wikipedia articles or other popular summaries of OPE, I figured I'd try asking for one here before diving into the academic literature.  (At worst, I may try to answer my own question later, if nobody else beats me to it.)  So, to summarize, my question is: How does order-preserving encryption work, and what security properties does it provide? Apache doesn't log remoteIP when RemoteIPHeader X-Forwarded-For is present Rotate photo in moderncv I'm doing my CV with the template ModernCV Classic. I want to rotate my picture but the command used is \photo I don't know how to do that.  \documentclass[11pt,a4paper,sans]{moderncv}  \moderncvstyle{classic} \moderncvcolor{blue} \nopagenumbers{}  \usepackage[utf8]{inputenc}  \usepackage[latin1]{inputenc} \usepackage[T1]{fontenc} \usepackage[francais]{babel}  \usepackage[scale=0.75]{geometry}  \name{John}{Doe} \title{...} \address{adress}{Town}{Country}  \extrainfo{age, nationality} \phone[mobile]{54466145745} \email{john.doe@mail.com} \photo[80pt][0.4pt]{Photo.jpg} \quote{Objectifs: ...} SQL function as default parameter value? I tried changing a default parameter value with this:  ALTER PROCEDURE [dbo].[my_sp] @currentDate datetime = GETDATE()   and all the SQL pre-compiler gave me was this error:     Msg 102, Level 15, State 1, Procedure my_sp, Line 8 Incorrect syntax near '('.   I have already created the procedure. (I'm not sure if that's relevant.) I was using a null default value and checking for that later, but that doesn't seem proper. Can I do this in one line?   Update: I was going off of :      [ = default ] Is a default value for the parameter. If a default value is defined, the function can be executed without specifying a value for that parameter.            Note:     Default parameter values can be specified for CLR functions except for the varchar(max) and varbinary(max) data types.         When a parameter of the function has a default value, the keyword DEFAULT must be specified when the function is called to retrieve the default value. This behavior is different from using parameters with default values in stored procedures in which omitting the parameter also implies the default value.   Am I reading this wrong?  Many thanks. Limit of $\lim_{(x,y)\rightarrow(0,0)}\frac{x^2y^2}{x^3+y^3}$ I want to know whether $\lim_{(x,y)\to (0,0)}\dfrac{x^2y^2}{x^3+y^3}$ exists or not. I tried to approximate to (0,0) from different "paths" and the result was always 0. For example,  $f(x,mx^2) = \dfrac{m^2x^3}{1+m^3x^3}$  But that doesn't show that the limit is 0. Sum of nth roots of unity Question: If $c\neq 1$ is an $n^{th}$ root of unity then, $1+c+...+c^{n-1} = 0$  Attempt: So I have established that I need to show that $$\sum^{n-1}_{k=0} e^{\frac{i2k\pi}{n}}=\frac{1-e^{\frac{ik2\pi}{n}}}{1-e^{\frac{i2\pi}{n}}} =0$$ by use of the sum of geometric series'. My issue is proceeding further to show that this is indeed true. I'd like to typeset documents using the '' of page layout. Good examples are on pages 40-53 of . The  package is helpful for this, but two additional features would be useful:   Automatic flow of text across (arbitrarily placed) columns / textpos blocks. Vertical line spacing enforced to be an integer multiple of a base line spacing, even when interrupted (for example) by an equation of arbitrary height.   Any ideas as to how either or both of these could be accomplished? image of polynomial map is not an algebraic set I am doing an exercise about algebraic geometry, where the exercise  tell us to provide example of the image of polynomial map $f:\mathbb{C}^{m}\rightarrow \mathbb{C}^{n}$ that is not an algebraic set. But I am thinking that the image of every polynomial is $\mathbb{C}$ thus every polynomial map is surjective. What have I misunderstand? Show (within ZF Set Theory without choice) that for any sets $A,B,C:$   If $|A|^{|B|} = |B|$, then $|A| = 1 = |B|.$   That is, if there is a bijection from $|A|^{|B|}$ to $|B|$, then  $|A| = 1 = |B|.$  Please help me.. How to round a number to n decimal places in Java Quantum entanglement for faster-than-light (FTL) network communication? Quantum entanglement is 2 atoms that are paired together and when you stop one from spinning the other also stops with the same spin. Can you use these pairs to have faster-than-light (FTL) communication between 2 computers? "many a time" means "many times"? What's a word like "disregard" or "bypass" that means "hides"? What's the most efficient way to concatenate strings? hard voting, soft voting in ensemble based methods I'm reading . Then I'm not able to figure out the difference between hard voting and soft voting in context to ensemble based methods.  I quote descriptions of them from the book. The first two images from the top are description for hard voting, and last one is for soft voting.        In my view hard voting is majority decision, but I don't understand soft voting and the reason why soft voting is better than hard voting. Would anyone teach me these? Of Half-elven and mortal life When half-elvens choose mortal life, how would their bodies behave?  Half-elven are always elves by nature. Ever since they're born, their physical body and behaviour would be elvish - they have keen senses, they don't get physically weary, no illness, and so on.  Half-elvens are then offered a choice - Immortal elvish lives or mortal fate of men. When they choose the latter, like Elros and Arwen did, what would happen to their elvish nature? Would they lose it? I don't think they would lose their pointy ears, but what about the other elvish features that I mentioned before?  Are there any canonical references?