qid int64 1 74.7M | question stringlengths 0 58.3k | date stringlengths 10 10 | metadata list | response_j stringlengths 2 48.3k | response_k stringlengths 2 40.5k |
|---|---|---|---|---|---|
47,950,710 | See the two different implementations that return `Enumeration<?>`
```
Vector<String> v = new Vector<>(map.keySet());
return v.elements();
```
---
```
List<String> v = new ArrayList<>(map.keySet());
return Collections.enumeration(v);
```
**Please note that the return type here `Enumeration<?>`, cannot be changed.... | 2017/12/23 | [
"https://Stackoverflow.com/questions/47950710",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3647002/"
] | Neither. You don't need either of these. `Collections.enumeration()` takes a `Collection` argument, and `Set` is a `Collection`, and `Map.keySet()` returns a `Set`.
You just need:
```
return Collections.enumeration(map.keySet());
``` | I think that if you want to just get Enumeration there is no difference.
Vector constoructor is as below.
```
public Vector(Collection<? extends E> c) {
elementData = c.toArray();
elementCount = elementData.length;
// c.toArray might (incorrectly) not return Object[] (see 6260652)
if (elementData.getC... |
17,670 | We have a situation in our product where for a long time some data has been stored in the application's database as SQL string (choice of MS SQL server or sybase SQL anywhere) which was encrypted via the Windows API function [CryptEncrypt.](http://msdn.microsoft.com/en-us/library/aa379924.aspx) (direct and de-cryptable... | 2008/08/20 | [
"https://Stackoverflow.com/questions/17670",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/379/"
] | Any semi-decent algorithm will end up with a strong chance of generating a NULL value somewhere in the resulting ciphertext.
Why not do something like [base-64 encode](http://en.wikipedia.org/wiki/Base64) your resulting binary blob before persisting to the DB? ([sample implementation in C++](http://synesis.com.au/soft... | That's an interesting route OJ.
We're looking at the feasability of a non-reversable method (still making sure we don't explicitly retrieve the data to decrypt) e.g. just store a Hash to compare on a submission |
17,670 | We have a situation in our product where for a long time some data has been stored in the application's database as SQL string (choice of MS SQL server or sybase SQL anywhere) which was encrypted via the Windows API function [CryptEncrypt.](http://msdn.microsoft.com/en-us/library/aa379924.aspx) (direct and de-cryptable... | 2008/08/20 | [
"https://Stackoverflow.com/questions/17670",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/379/"
] | Any semi-decent algorithm will end up with a strong chance of generating a NULL value somewhere in the resulting ciphertext.
Why not do something like [base-64 encode](http://en.wikipedia.org/wiki/Base64) your resulting binary blob before persisting to the DB? ([sample implementation in C++](http://synesis.com.au/soft... | Storing a hash is a good idea. However, please definitely read Jeff's [You're Probably Storing Passwords Incorrectly](http://www.codinghorror.com/blog/archives/000953.html). |
17,670 | We have a situation in our product where for a long time some data has been stored in the application's database as SQL string (choice of MS SQL server or sybase SQL anywhere) which was encrypted via the Windows API function [CryptEncrypt.](http://msdn.microsoft.com/en-us/library/aa379924.aspx) (direct and de-cryptable... | 2008/08/20 | [
"https://Stackoverflow.com/questions/17670",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/379/"
] | Any semi-decent algorithm will end up with a strong chance of generating a NULL value somewhere in the resulting ciphertext.
Why not do something like [base-64 encode](http://en.wikipedia.org/wiki/Base64) your resulting binary blob before persisting to the DB? ([sample implementation in C++](http://synesis.com.au/soft... | It seems that the developer handling this is going to wrap the existing encryption with [yEnc](http://www.yenc.org) to preserve the table integrity as the data needs to be retrievable, and this save all that messy mucking about with infinite-improbab.... uhhh changing column types on entrenched installations.
Cheers Gu... |
17,670 | We have a situation in our product where for a long time some data has been stored in the application's database as SQL string (choice of MS SQL server or sybase SQL anywhere) which was encrypted via the Windows API function [CryptEncrypt.](http://msdn.microsoft.com/en-us/library/aa379924.aspx) (direct and de-cryptable... | 2008/08/20 | [
"https://Stackoverflow.com/questions/17670",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/379/"
] | Storing a hash is a good idea. However, please definitely read Jeff's [You're Probably Storing Passwords Incorrectly](http://www.codinghorror.com/blog/archives/000953.html). | That's an interesting route OJ.
We're looking at the feasability of a non-reversable method (still making sure we don't explicitly retrieve the data to decrypt) e.g. just store a Hash to compare on a submission |
17,670 | We have a situation in our product where for a long time some data has been stored in the application's database as SQL string (choice of MS SQL server or sybase SQL anywhere) which was encrypted via the Windows API function [CryptEncrypt.](http://msdn.microsoft.com/en-us/library/aa379924.aspx) (direct and de-cryptable... | 2008/08/20 | [
"https://Stackoverflow.com/questions/17670",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/379/"
] | Storing a hash is a good idea. However, please definitely read Jeff's [You're Probably Storing Passwords Incorrectly](http://www.codinghorror.com/blog/archives/000953.html). | It seems that the developer handling this is going to wrap the existing encryption with [yEnc](http://www.yenc.org) to preserve the table integrity as the data needs to be retrievable, and this save all that messy mucking about with infinite-improbab.... uhhh changing column types on entrenched installations.
Cheers Gu... |
57,071,669 | I have 2 models, 2 views, and 1 viewmodel.
Basically I want to load the data from a GTSLocation object into a ListItem, but also add two more values from a GTSWorkingSite object that has the same Working Site Guid as the GTSLocation object have.
The item fooA from ObservableCollection<GTSLocation>:
```
WorkingSiteId ... | 2019/07/17 | [
"https://Stackoverflow.com/questions/57071669",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3939608/"
] | I think this is what i need:
```
$request->user()->token()->client
``` | If you have used `passport` you can get the user id from the `Auth` facade using `api guard` like this:
```
$user_id = Auth::guard('api')->id();
```
or get the user:
```
$user = Auth::guard('api')->user();
``` |
57,071,669 | I have 2 models, 2 views, and 1 viewmodel.
Basically I want to load the data from a GTSLocation object into a ListItem, but also add two more values from a GTSWorkingSite object that has the same Working Site Guid as the GTSLocation object have.
The item fooA from ObservableCollection<GTSLocation>:
```
WorkingSiteId ... | 2019/07/17 | [
"https://Stackoverflow.com/questions/57071669",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3939608/"
] | If you deal with the [**grant type client\_credentials**](https://laravel.com/docs/6.x/passport#client-credentials-grant-tokens) you might consider the following solution:
```
Route::get('/get-client-cred', function (Request $request) {
$bearerToken = $request->bearerToken();
$tokenId = (new \Lcobucci\JWT\Par... | If you have used `passport` you can get the user id from the `Auth` facade using `api guard` like this:
```
$user_id = Auth::guard('api')->id();
```
or get the user:
```
$user = Auth::guard('api')->user();
``` |
57,071,669 | I have 2 models, 2 views, and 1 viewmodel.
Basically I want to load the data from a GTSLocation object into a ListItem, but also add two more values from a GTSWorkingSite object that has the same Working Site Guid as the GTSLocation object have.
The item fooA from ObservableCollection<GTSLocation>:
```
WorkingSiteId ... | 2019/07/17 | [
"https://Stackoverflow.com/questions/57071669",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3939608/"
] | I think this is what i need:
```
$request->user()->token()->client
``` | If you deal with the [**grant type client\_credentials**](https://laravel.com/docs/6.x/passport#client-credentials-grant-tokens) you might consider the following solution:
```
Route::get('/get-client-cred', function (Request $request) {
$bearerToken = $request->bearerToken();
$tokenId = (new \Lcobucci\JWT\Par... |
57,071,669 | I have 2 models, 2 views, and 1 viewmodel.
Basically I want to load the data from a GTSLocation object into a ListItem, but also add two more values from a GTSWorkingSite object that has the same Working Site Guid as the GTSLocation object have.
The item fooA from ObservableCollection<GTSLocation>:
```
WorkingSiteId ... | 2019/07/17 | [
"https://Stackoverflow.com/questions/57071669",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3939608/"
] | I think this is what i need:
```
$request->user()->token()->client
``` | This is what finally worked for me with Laravel 8.
Note that I plagerised the solution from @judge2020's [answer on GitHub](https://github.com/laravel/passport/issues/124).
```
use Laravel\Passport\Token;
use Lcobucci\JWT\Configuration; /* composer require lcobucci/jwt */
Route::get('/v1/test', function(Request $req... |
57,071,669 | I have 2 models, 2 views, and 1 viewmodel.
Basically I want to load the data from a GTSLocation object into a ListItem, but also add two more values from a GTSWorkingSite object that has the same Working Site Guid as the GTSLocation object have.
The item fooA from ObservableCollection<GTSLocation>:
```
WorkingSiteId ... | 2019/07/17 | [
"https://Stackoverflow.com/questions/57071669",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3939608/"
] | If you deal with the [**grant type client\_credentials**](https://laravel.com/docs/6.x/passport#client-credentials-grant-tokens) you might consider the following solution:
```
Route::get('/get-client-cred', function (Request $request) {
$bearerToken = $request->bearerToken();
$tokenId = (new \Lcobucci\JWT\Par... | This is what finally worked for me with Laravel 8.
Note that I plagerised the solution from @judge2020's [answer on GitHub](https://github.com/laravel/passport/issues/124).
```
use Laravel\Passport\Token;
use Lcobucci\JWT\Configuration; /* composer require lcobucci/jwt */
Route::get('/v1/test', function(Request $req... |
44,054 | I've written a query to compare the clients in our database with the people in a list that I've received. It needs to check if anyone from the list is one of our clients. I've created a temporary table which has been filled with the names and the query below makes a cross-join with the two tables. That query works very... | 2014/03/11 | [
"https://codereview.stackexchange.com/questions/44054",
"https://codereview.stackexchange.com",
"https://codereview.stackexchange.com/users/37623/"
] | First off, you should clean up the indention. Currently the wrong indention makes the code hard to read.
The next problem is that your variables `width`, `prev` and `data` are lacking the `var` keyword making them global und thus making the surrounding [IIFE](http://en.wikipedia.org/wiki/Immediately-invoked_function_e... | From a once over:
* This:
```
var $this = $(this);
prev = $this.text();
data = $this.attr('data-portfolio');
```
should have been this:
```
var $this = $(this), //<- Comma, not semicolon
prev = $this.text(), //<- Comma, not semicolon
data = $this.attr('data-portfolio');
```
* Be consistent w... |
69,081,312 | How do I put the `v-model="item.checked"` as the condition of the `if` in below `validations()`?
```
<table>
<tr v-for="(item, i) of $v.timesheet.items.$each.$iter" >
<div>
<td>
<input
type="checkbox"
v-model="item.checked"
... | 2021/09/07 | [
"https://Stackoverflow.com/questions/69081312",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16780927/"
] | So as I understand, you want `total_hour` to be a required field only if `checked` is true. Vuelidate provides a nice built-in validator for this purpose called `requiredIf`. It is a [contextified validator](https://vuelidate.js.org/#sub-contextified-validators) so you can reference a sibling property.
```js
import { ... | So, there are a few things to improve your code.
**Replace watcher with a method**
Watchers are pretty hard to debug and can cause side effects. They should be only used when really necessary.
Instead, create a method, which adds a row:
```
addRow() {
this.timesheet.items.push({
total_hour: "",
checked: fa... |
32,983,243 | I have come across the following problem statement:
>
> You have a sentence written entirely in a single row. You would like to split it into several rows by replacing some of the spaces
> with "new row" indicators. Your goal is to minimize the width of the
> longest row in the resulting text ("new row" indicators ... | 2015/10/07 | [
"https://Stackoverflow.com/questions/32983243",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1852230/"
] | Easy if you use the Gauss formula to calculate the sum of the first N consecutive numbers:
```
function solution(A) {
var np1, perfectSum, sum;
if (!A || A.length == 0) {
return 1;
}
np1 = A.length + 1;
// Gauss formula
perfectSum = np1 * (1 + np1) / ... | My 100% JavaScript solution:
```
function solution(A) {
const N = A.length;
// use the Gauss formula
const sumNatural = (N + 1) * (N + 2) / 2;
// actual sum with the missing number (smaller than sumNatural above)
const actualSum = A.reduce((sum, num) => sum += num, 0);
// the difference bet... |
32,983,243 | I have come across the following problem statement:
>
> You have a sentence written entirely in a single row. You would like to split it into several rows by replacing some of the spaces
> with "new row" indicators. Your goal is to minimize the width of the
> longest row in the resulting text ("new row" indicators ... | 2015/10/07 | [
"https://Stackoverflow.com/questions/32983243",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1852230/"
] | Here is 100% javascript solution:
```
function solution(A) {
if (!A.length) return 1;
let n = A.length + 1;
return (n + (n * n - n) / 2) - A.reduce((a, b) => a + b);
}
```
We return 1 if the given array is empty, which is the missing element in an empty array.
Next we calculate the 'ordinary' series sum... | Get 100 in correctness and performance using this function
```
function solution(A) {
// write your code in JavaScript (Node.js 4.0.0)
var size = A.length;
var sum = (size + 1) * (size + 2) / 2;
for (i = 0; i < size; i++) {
sum -= A[i];
}
return sum;
}
``` |
32,983,243 | I have come across the following problem statement:
>
> You have a sentence written entirely in a single row. You would like to split it into several rows by replacing some of the spaces
> with "new row" indicators. Your goal is to minimize the width of the
> longest row in the resulting text ("new row" indicators ... | 2015/10/07 | [
"https://Stackoverflow.com/questions/32983243",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1852230/"
] | No Gauss formula, only simple and plain separate for loops that give an O(N) or O(N \* log(N)) and 100% score:
```
function solution(A) {
if(!A.length){
return 1; //Just because if empty this is the only one missing.
}
let fullSum = 0;
let sum = 0;
for(let i = 0; i <= A.length; i++){
... | My 100% JavaScript solution:
```
function solution(A) {
const N = A.length;
// use the Gauss formula
const sumNatural = (N + 1) * (N + 2) / 2;
// actual sum with the missing number (smaller than sumNatural above)
const actualSum = A.reduce((sum, num) => sum += num, 0);
// the difference bet... |
32,983,243 | I have come across the following problem statement:
>
> You have a sentence written entirely in a single row. You would like to split it into several rows by replacing some of the spaces
> with "new row" indicators. Your goal is to minimize the width of the
> longest row in the resulting text ("new row" indicators ... | 2015/10/07 | [
"https://Stackoverflow.com/questions/32983243",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1852230/"
] | No Gauss formula, only simple and plain separate for loops that give an O(N) or O(N \* log(N)) and 100% score:
```
function solution(A) {
if(!A.length){
return 1; //Just because if empty this is the only one missing.
}
let fullSum = 0;
let sum = 0;
for(let i = 0; i <= A.length; i++){
... | ```js
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
if (!A.length) return 1;
A = A.sort((a, b) => a - b);
for (let i = 0; i < A.length + 1; i++) {
if (A[i] !== i + 1) {
return i + 1;
}
}
}
``` |
32,983,243 | I have come across the following problem statement:
>
> You have a sentence written entirely in a single row. You would like to split it into several rows by replacing some of the spaces
> with "new row" indicators. Your goal is to minimize the width of the
> longest row in the resulting text ("new row" indicators ... | 2015/10/07 | [
"https://Stackoverflow.com/questions/32983243",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1852230/"
] | Get 100 in correctness and performance using this function
```
function solution(A) {
// write your code in JavaScript (Node.js 4.0.0)
var size = A.length;
var sum = (size + 1) * (size + 2) / 2;
for (i = 0; i < size; i++) {
sum -= A[i];
}
return sum;
}
``` | No Gauss formula, only simple and plain separate for loops that give an O(N) or O(N \* log(N)) and 100% score:
```
function solution(A) {
if(!A.length){
return 1; //Just because if empty this is the only one missing.
}
let fullSum = 0;
let sum = 0;
for(let i = 0; i <= A.length; i++){
... |
32,983,243 | I have come across the following problem statement:
>
> You have a sentence written entirely in a single row. You would like to split it into several rows by replacing some of the spaces
> with "new row" indicators. Your goal is to minimize the width of the
> longest row in the resulting text ("new row" indicators ... | 2015/10/07 | [
"https://Stackoverflow.com/questions/32983243",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1852230/"
] | This got me 100%
```
function solution(A) {
if (A.length === 0 || !A) {
return 1;
}
A.sort((a, b) => a - b);
let count = A[0];
if (count !== 1) { return 1 }
for (let i = 0; i <= A.length; i++) {
if (A[i + 1] === count + 1) {
count ++;
continue
}
return count + 1;
}
```
} | I had the same problem with my code:
```
function solution(A) {
var i, next;
A.sort();
next = 1;
for (i=0; i<A.length; i++){
if (A[i] != next) return next;
next++;
}
return next;
}
```
Altough it scored 100% in correctness, it returned wrong answer in all the performance te... |
32,983,243 | I have come across the following problem statement:
>
> You have a sentence written entirely in a single row. You would like to split it into several rows by replacing some of the spaces
> with "new row" indicators. Your goal is to minimize the width of the
> longest row in the resulting text ("new row" indicators ... | 2015/10/07 | [
"https://Stackoverflow.com/questions/32983243",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1852230/"
] | Here is 100% javascript solution:
```
function solution(A) {
if (!A.length) return 1;
let n = A.length + 1;
return (n + (n * n - n) / 2) - A.reduce((a, b) => a + b);
}
```
We return 1 if the given array is empty, which is the missing element in an empty array.
Next we calculate the 'ordinary' series sum... | This should be work good:
```
function solution(A) {
// Size of the A array
const size = A.length;
// sum of the current values
const arrSum = A.reduce((a, b) => a + b, 0);
// sum of all values including the missing number
const sum = (size + 1) * (size + 2) / 2;
// return... |
32,983,243 | I have come across the following problem statement:
>
> You have a sentence written entirely in a single row. You would like to split it into several rows by replacing some of the spaces
> with "new row" indicators. Your goal is to minimize the width of the
> longest row in the resulting text ("new row" indicators ... | 2015/10/07 | [
"https://Stackoverflow.com/questions/32983243",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1852230/"
] | Easy if you use the Gauss formula to calculate the sum of the first N consecutive numbers:
```
function solution(A) {
var np1, perfectSum, sum;
if (!A || A.length == 0) {
return 1;
}
np1 = A.length + 1;
// Gauss formula
perfectSum = np1 * (1 + np1) / ... | I got an alternative 100% correctness/performance solution without the Gauss formula, sorting the array first instead:
```
function solution(A) {
A.sort((a, b) => a-b);
for(let i=0; i<A.length; i++){
if(A[i] != i+1) {
return 0;
}
}
return 1;
}
``` |
32,983,243 | I have come across the following problem statement:
>
> You have a sentence written entirely in a single row. You would like to split it into several rows by replacing some of the spaces
> with "new row" indicators. Your goal is to minimize the width of the
> longest row in the resulting text ("new row" indicators ... | 2015/10/07 | [
"https://Stackoverflow.com/questions/32983243",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1852230/"
] | From the sum of first natural numbers formula we have
[](https://i.stack.imgur.com/qYmeo.gif)
now since the N item for us in the task is (N+1) we substitue n with n+1 and we get
[]... | I had the same problem with my code:
```
function solution(A) {
var i, next;
A.sort();
next = 1;
for (i=0; i<A.length; i++){
if (A[i] != next) return next;
next++;
}
return next;
}
```
Altough it scored 100% in correctness, it returned wrong answer in all the performance te... |
32,983,243 | I have come across the following problem statement:
>
> You have a sentence written entirely in a single row. You would like to split it into several rows by replacing some of the spaces
> with "new row" indicators. Your goal is to minimize the width of the
> longest row in the resulting text ("new row" indicators ... | 2015/10/07 | [
"https://Stackoverflow.com/questions/32983243",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1852230/"
] | Easy if you use the Gauss formula to calculate the sum of the first N consecutive numbers:
```
function solution(A) {
var np1, perfectSum, sum;
if (!A || A.length == 0) {
return 1;
}
np1 = A.length + 1;
// Gauss formula
perfectSum = np1 * (1 + np1) / ... | This should be work good:
```
function solution(A) {
// Size of the A array
const size = A.length;
// sum of the current values
const arrSum = A.reduce((a, b) => a + b, 0);
// sum of all values including the missing number
const sum = (size + 1) * (size + 2) / 2;
// return... |
397,708 | I am trying to write a MySQL query that retrieves one record from table "projects" that has a one-to-many relationship with table "tags". My application uses 4 tables to do this:
```
Projects - the projects table
Entities - entity table; references several application resources
Tags - tags table
Tag_entity - links tag... | 2008/12/29 | [
"https://Stackoverflow.com/questions/397708",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11568/"
] | see [GROUP\_CONCAT](http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat)
example:
```
mysql> SELECT * FROM blah;
+----+-----+-----------+
| K | grp | name |
+----+-----+-----------+
| 1 | 1 | foo |
| 2 | 1 | bar |
| 3 | 2 | hydrogen |
| 4 | 4 | dasher ... | I don't know if it works in MySQL, but in SQL Server you can use a trick for this:
```
DECLARE @csv varchar(max)
SET @csv = ''
SELECT @csv = @csv + ',' + foo.SomeColumn
FROM [FOO] foo
WHERE foo.SomeId = @SomeId
```
Then in the main select
```
SELECT ..., @csv AS [Tags]
FROM ...
```
The result of `SELECT @csv =... |
63,315,758 | I want to fill `null` values over my window with last value of every window. But in some cases I think `last` functions doesn't work.
Here is my data:
```
l = [
('100', '2012-01-02', None),
('110', '2012-01-02', None),
('100', '2012-01-03', 26),
('110', '2012-01-03', 251),
('100', '2012-01-04'... | 2020/08/08 | [
"https://Stackoverflow.com/questions/63315758",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10835053/"
] | Change your window to this.
```
my_window = Window.partitionBy('number').orderBy(df['date']).rowsBetween(Window.currentRow, Window.unboundedFollowing)
```
Your window imposes the rows between the first row to the current and in this case, the last is the same as the current. | I know this is long overdue, but for people trying to understand why this happens
(I'm no expert but I'll just relay what I've been told)
I did have the same problem and I asked around at work and after digging it up a little bit I've been told that when we use "orderBy" in the window Spark will create a partition to ... |
256,965 | We are looking to do new flooring in our downstairs bathroom. My wife likes a flooring material by a company called COREtec; specifically their ["Calypso Oak"](https://coretecfloors.com/en-us/products/coretec-enhanced/calypso-oak-vv012-00761) LVP/LVT product:
[:
1. LVP to my understanding has a grout-like central layer and thus needs to be well-supported to prevent crac... | Personally, I would take out the tile, but doesn't sound like you have too. Some of the vinyl plank flooring is not strong enough to bridge the gaps between tiles where the grout is lower. Eventually, those lines will show through. |
256,965 | We are looking to do new flooring in our downstairs bathroom. My wife likes a flooring material by a company called COREtec; specifically their ["Calypso Oak"](https://coretecfloors.com/en-us/products/coretec-enhanced/calypso-oak-vv012-00761) LVP/LVT product:
[).
Which means that when you do
```
Person first = new Person("John");
Person second = first;
```
you have two different ... | The reason is given in a comment by @khelwood:
>
> Variables are assigned by value in Java. g = x\_map.get(42) just
> assigns the value from the map into the variable g. If you reassign g,
> then you're repointing g to a different value.
>
>
>
If instead of `String` I put something that actually is modifiable ... |
50,587,087 | I'm trying to configure Prometheus outside Kubernetes Cluster.
Below is my Prometheus config.
```
- job_name: 'kubernetes-apiservers'
kubernetes_sd_configs:
- role: endpoints
api_server: https://10.0.4.155:6443
scheme: https
tls_config:
insecure_skip_verify: true
basic_auth:
username: kube
... | 2018/05/29 | [
"https://Stackoverflow.com/questions/50587087",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8625281/"
] | Pass-by-value
-------------
Java is **pass-by-value** (see [Is Java “pass-by-reference” or “pass-by-value”?](https://stackoverflow.com/questions/40480/is-java-pass-by-reference-or-pass-by-value)).
Which means that when you do
```
Person first = new Person("John");
Person second = first;
```
you have two different ... | Because you didn't update the value of the 42 key in the x\_map.
for that you should do this
X\_map.put(42, g) |
2,597,593 | Function socialbookmarksTableData(data) is called by another function to generate the content of a table -- data is a JSON object. Inside the function i call 2 other functions that use getJSON and POST (with json as a return object) to get some data. The problem is: though the functions execute correctly i get undefine... | 2010/04/08 | [
"https://Stackoverflow.com/questions/2597593",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/253530/"
] | The `android.graphics.Path` class doesn't have such a method. The Canvas class does have a clipping region that can be set to a path, there is no way to test it against a point. You might try Canvas.quickReject, testing against a single point rectangle (or a 1x1 `Rect`). I don't know if that would really check against ... | WebKit's [SkiaUtils](http://www.opensource.apple.com/source/WebCore/WebCore-658.28/platform/graphics/skia/SkiaUtils.cpp) has a C++ work-around for Randy Findley's bug:
```
bool SkPathContainsPoint(SkPath* originalPath, const FloatPoint& point, SkPath::FillType ft)
{
SkRegion rgn;
SkRegion clip;
SkPath::FillType... |
2,597,593 | Function socialbookmarksTableData(data) is called by another function to generate the content of a table -- data is a JSON object. Inside the function i call 2 other functions that use getJSON and POST (with json as a return object) to get some data. The problem is: though the functions execute correctly i get undefine... | 2010/04/08 | [
"https://Stackoverflow.com/questions/2597593",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/253530/"
] | The `android.graphics.Path` class doesn't have such a method. The Canvas class does have a clipping region that can be set to a path, there is no way to test it against a point. You might try Canvas.quickReject, testing against a single point rectangle (or a 1x1 `Rect`). I don't know if that would really check against ... | I know I'm a bit late to the party, but I would solve this problem by thinking about it like determining whether or not a point is in a polygon.
<http://en.wikipedia.org/wiki/Point_in_polygon>
The math computes more slowly when you're looking at Bezier splines instead of line segments, but drawing a ray from the poin... |
2,597,593 | Function socialbookmarksTableData(data) is called by another function to generate the content of a table -- data is a JSON object. Inside the function i call 2 other functions that use getJSON and POST (with json as a return object) to get some data. The problem is: though the functions execute correctly i get undefine... | 2010/04/08 | [
"https://Stackoverflow.com/questions/2597593",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/253530/"
] | The `android.graphics.Path` class doesn't have such a method. The Canvas class does have a clipping region that can be set to a path, there is no way to test it against a point. You might try Canvas.quickReject, testing against a single point rectangle (or a 1x1 `Rect`). I don't know if that would really check against ... | For completeness, I want to make a couple notes here:
As of API 19, there is an [intersection operation](http://developer.android.com/reference/android/graphics/Path.html#op(android.graphics.Path,%20android.graphics.Path,%20android.graphics.Path.Op)) for Paths. You could create a very small square path around your tes... |
2,597,593 | Function socialbookmarksTableData(data) is called by another function to generate the content of a table -- data is a JSON object. Inside the function i call 2 other functions that use getJSON and POST (with json as a return object) to get some data. The problem is: though the functions execute correctly i get undefine... | 2010/04/08 | [
"https://Stackoverflow.com/questions/2597593",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/253530/"
] | Here is what I did and it seems to work:
```
RectF rectF = new RectF();
path.computeBounds(rectF, true);
region = new Region();
region.setPath(path, new Region((int) rectF.left, (int) rectF.top, (int) rectF.right, (int) rectF.bottom));
```
Now you can use the `region.contains(x,y)` method.
```
Point point = new Poi... | WebKit's [SkiaUtils](http://www.opensource.apple.com/source/WebCore/WebCore-658.28/platform/graphics/skia/SkiaUtils.cpp) has a C++ work-around for Randy Findley's bug:
```
bool SkPathContainsPoint(SkPath* originalPath, const FloatPoint& point, SkPath::FillType ft)
{
SkRegion rgn;
SkRegion clip;
SkPath::FillType... |
2,597,593 | Function socialbookmarksTableData(data) is called by another function to generate the content of a table -- data is a JSON object. Inside the function i call 2 other functions that use getJSON and POST (with json as a return object) to get some data. The problem is: though the functions execute correctly i get undefine... | 2010/04/08 | [
"https://Stackoverflow.com/questions/2597593",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/253530/"
] | Here is what I did and it seems to work:
```
RectF rectF = new RectF();
path.computeBounds(rectF, true);
region = new Region();
region.setPath(path, new Region((int) rectF.left, (int) rectF.top, (int) rectF.right, (int) rectF.bottom));
```
Now you can use the `region.contains(x,y)` method.
```
Point point = new Poi... | I know I'm a bit late to the party, but I would solve this problem by thinking about it like determining whether or not a point is in a polygon.
<http://en.wikipedia.org/wiki/Point_in_polygon>
The math computes more slowly when you're looking at Bezier splines instead of line segments, but drawing a ray from the poin... |
2,597,593 | Function socialbookmarksTableData(data) is called by another function to generate the content of a table -- data is a JSON object. Inside the function i call 2 other functions that use getJSON and POST (with json as a return object) to get some data. The problem is: though the functions execute correctly i get undefine... | 2010/04/08 | [
"https://Stackoverflow.com/questions/2597593",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/253530/"
] | Here is what I did and it seems to work:
```
RectF rectF = new RectF();
path.computeBounds(rectF, true);
region = new Region();
region.setPath(path, new Region((int) rectF.left, (int) rectF.top, (int) rectF.right, (int) rectF.bottom));
```
Now you can use the `region.contains(x,y)` method.
```
Point point = new Poi... | For completeness, I want to make a couple notes here:
As of API 19, there is an [intersection operation](http://developer.android.com/reference/android/graphics/Path.html#op(android.graphics.Path,%20android.graphics.Path,%20android.graphics.Path.Op)) for Paths. You could create a very small square path around your tes... |
2,597,593 | Function socialbookmarksTableData(data) is called by another function to generate the content of a table -- data is a JSON object. Inside the function i call 2 other functions that use getJSON and POST (with json as a return object) to get some data. The problem is: though the functions execute correctly i get undefine... | 2010/04/08 | [
"https://Stackoverflow.com/questions/2597593",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/253530/"
] | WebKit's [SkiaUtils](http://www.opensource.apple.com/source/WebCore/WebCore-658.28/platform/graphics/skia/SkiaUtils.cpp) has a C++ work-around for Randy Findley's bug:
```
bool SkPathContainsPoint(SkPath* originalPath, const FloatPoint& point, SkPath::FillType ft)
{
SkRegion rgn;
SkRegion clip;
SkPath::FillType... | I know I'm a bit late to the party, but I would solve this problem by thinking about it like determining whether or not a point is in a polygon.
<http://en.wikipedia.org/wiki/Point_in_polygon>
The math computes more slowly when you're looking at Bezier splines instead of line segments, but drawing a ray from the poin... |
2,597,593 | Function socialbookmarksTableData(data) is called by another function to generate the content of a table -- data is a JSON object. Inside the function i call 2 other functions that use getJSON and POST (with json as a return object) to get some data. The problem is: though the functions execute correctly i get undefine... | 2010/04/08 | [
"https://Stackoverflow.com/questions/2597593",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/253530/"
] | WebKit's [SkiaUtils](http://www.opensource.apple.com/source/WebCore/WebCore-658.28/platform/graphics/skia/SkiaUtils.cpp) has a C++ work-around for Randy Findley's bug:
```
bool SkPathContainsPoint(SkPath* originalPath, const FloatPoint& point, SkPath::FillType ft)
{
SkRegion rgn;
SkRegion clip;
SkPath::FillType... | For completeness, I want to make a couple notes here:
As of API 19, there is an [intersection operation](http://developer.android.com/reference/android/graphics/Path.html#op(android.graphics.Path,%20android.graphics.Path,%20android.graphics.Path.Op)) for Paths. You could create a very small square path around your tes... |
934,147 | This question is inspired by the Dichotomy Paradox but with a twist: Let's say that Telemachus is running between two light posts, distance **L** length units apart. He starts at the first light post with an initial velocity of **V0**. When he reaches L/2, half the distance between the light posts, he doubles the speed... | 2014/09/16 | [
"https://math.stackexchange.com/questions/934147",
"https://math.stackexchange.com",
"https://math.stackexchange.com/users/176545/"
] | Let $t\_0=\frac{L}{2V\_0}$ the time need to reach the distance $\frac{L}{2}$. The next step the distance is divided by $2$ and the velocity multiplied by $2$, so the time is divided by $4$, and the same for each subsequent step.
So the time needed to reach $L$ is $$\sum\_{i=0}^{\infty}\frac{t\_0}{4^i}=\frac{4t\_0}{3}=... | This is a weaker form of the paradox, because the original paradox holds when the speed is held constant. To resolve such a paradox, regardless of speed, one has to consider the infinite series (sum) of times to reach destinations, instead of focusing on one destination at a time on and on forever. Then you realize tha... |
42,256,675 | When I try to extend the SubDagOperator provided in airflow API, airflow webserver GUI does not recognize it as SubDagOperator thereby disabling me to zoom in to the subdag.
How can I extend the SubDagOperator while preserving the ability to zoom in to it as a subdag? Am I missing something? | 2017/02/15 | [
"https://Stackoverflow.com/questions/42256675",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3285394/"
] | Please see the example below on how to extend the SubDagOperator. The key in your case was to override the task\_type function
```
from airflow import DAG
from airflow.operators.subdag_operator import SubDagOperator
from airflow.operators.dummy_operator import DummyOperator
from airflow.utils.decorators import apply_d... | If you define the subdag as a dag itself this should work.
There is a good example from airflow. You also have to pay attention to the naming convention, the subdag name has to be of parent\_name.child\_name format.
the main dag
<https://github.com/apache/incubator-airflow/blob/master/airflow/example_dags/example_su... |
23,010,257 | I want to set my checkbox to be automatically unchecked when my webpage loads. I am using the function form\_checkbox() which has these parameters if you use an array to give the checkbox your desired properties.
```
$data = array(
'name' => 'newsletter',
'id' => 'newsletter',
'value' => 'accept'... | 2014/04/11 | [
"https://Stackoverflow.com/questions/23010257",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3494437/"
] | As per the [table on MSDN here](http://technet.microsoft.com/en-us/library/ms175003.aspx) Sql Server's `ROUND()` will return a decimal output for a decimal input.
The overloads of [`Math.Round`](http://msdn.microsoft.com/en-us/library/system.math.round.aspx) return either decimal or double, depending on the input type... | SQL is giving you the same datatype you put in - there is a precision setting for a decimal datatype in SQL and since you are specifying an number with 2dp, SQL returns a value with 2dp.
.NET doesn't share the same data types as SQL and is therefore returning a `double` (since you didn't specify the input as decimal) |
45,486,612 | I have updated a web page that I didn't create. I worked locally perfecting the new layout which was fine.
However when I moved it to the server, a lot of styles didn't apply.
In troubleshooting, I found that the styles that weren't working on the server were listed as "Author Stylesheet" styles locally (in Safari D... | 2017/08/03 | [
"https://Stackoverflow.com/questions/45486612",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6328161/"
] | I'm not sure if this is 100% accurate, but I believe that Safari will not show the name of the css file if it is named default.css. In my case, Chrome tools displayed the file name (not just "Author Stylesheet"). | Wayne, I don't think you might declare the author of CSS file on it. You must passing the wrong name or locale from CSS server, is there all your CSS found? Aren't u using css on your local or .min.css in your app? User google chrome in the console tab to look wgat is the problems with your stylesheet. |
5,711,975 | I have a basic understanding of the [MERGE](http://technet.microsoft.com/en-us/library/bb510625.aspx) syntax for SQL Sever 2008 but have a question about an advanced use of the concept.
Imagine I have a sports team that has 30 players in it. Each player is a record in a table. Now, half way through the season, some pl... | 2011/04/19 | [
"https://Stackoverflow.com/questions/5711975",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30674/"
] | You can use merge like that but then I guess that your source table for the new team must hold the entire new team including those that has not been modified.
Here is a simplified sample.
The season starts out with this team
```
PlayerName Position
-------------------- --------
Brett Favre QB
Joe M... | Yes, `WHEN NOT MATCHED BY SOURCE THEN <merge_matched>` is the section where you can take care about the players that have left.
According to the [doc](http://technet.microsoft.com/en-us/library/bb510625.aspx), you can use an UPDATE (for example, set the `Active` atribute to `0`) or a DELETE instruction there.
You ca... |
49,214,684 | In Swift you can ignore the loop constant by using `_` like so:
```
for _ in 0...10 {
//loop logic here
}
```
Is there an equivalent in Kotlin? | 2018/03/10 | [
"https://Stackoverflow.com/questions/49214684",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1839500/"
] | You can also use [repeat()](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/repeat.html) function:
```
repeat(10){
//loop logic here
}
``` | You can just use a forEach loop, and don't use `it` inside the closure:
```
(1..10).forEach {
println("hello")
}
``` |
49,214,684 | In Swift you can ignore the loop constant by using `_` like so:
```
for _ in 0...10 {
//loop logic here
}
```
Is there an equivalent in Kotlin? | 2018/03/10 | [
"https://Stackoverflow.com/questions/49214684",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1839500/"
] | You can just use a forEach loop, and don't use `it` inside the closure:
```
(1..10).forEach {
println("hello")
}
``` | Kotlin also knows the [convention](https://kotlinlang.org/docs/reference/lambdas.html#underscore-for-unused-variables-since-11) of naming lambda parameters `"_"` in order to indicate they are unused. The following looks very similar to your example:
```
(1..10).forEach { _ ->
//loop logic here
}
``` |
49,214,684 | In Swift you can ignore the loop constant by using `_` like so:
```
for _ in 0...10 {
//loop logic here
}
```
Is there an equivalent in Kotlin? | 2018/03/10 | [
"https://Stackoverflow.com/questions/49214684",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1839500/"
] | You can also use [repeat()](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/repeat.html) function:
```
repeat(10){
//loop logic here
}
``` | Kotlin also knows the [convention](https://kotlinlang.org/docs/reference/lambdas.html#underscore-for-unused-variables-since-11) of naming lambda parameters `"_"` in order to indicate they are unused. The following looks very similar to your example:
```
(1..10).forEach { _ ->
//loop logic here
}
``` |
58,711,646 | I have create this toggle menu for mobile device using javascript but this is not working
```js
const selectElement = (s) => document.querySelector(s);
selectElement(s: '.open').addEventListener('click', () => {
selectElement(s:'nav-list').classList.add('active');
});
selectElement(s:'.close').addEventListener('cl... | 2019/11/05 | [
"https://Stackoverflow.com/questions/58711646",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11540655/"
] | I followed the same tutorial, here's what I did to make it work:
Here's the ModifiedTensorBoard Class:
```
class ModifiedTensorBoard(TensorBoard):
# Overriding init to set initial step and writer (we want one log file for all .fit() calls)
def __init__(self, **kwargs):
super().__init__(**kwargs)
... | The following code will work on TensorFlow 2.4.1 :
```
class ModifiedTensorBoard(TensorBoard):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.step = 1
self.writer = tf.summary.create_file_writer(self.log_dir)
self._log_write_dir = self.log_dir
def set_model(self, model):
self.... |
73,005,970 | I want to filter a list that has episodes of series. The list looks a bit like this:
```
[
{
"media": {
"episode_number": "7"
},
"collection": {
"collection_id": "26464"
}
},
{
"media": {
"episode_number": "6"
},
"collection": {
"collection_id": "26464"
}
... | 2022/07/16 | [
"https://Stackoverflow.com/questions/73005970",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19559117/"
] | What you need here is to **group items by** `collection.collectionId` and then for each group look for an item with **maximum** value of `media.episode_number`. In Kotlin it can be done almost as it was said above:
```kotlin
items
.groupBy { it.collection.collectionId }
.values
.map { group -> group.maxByO... | I found the solution:
```
list = list.sortedBy { it.collection.collectionId }.filter { item ->
item == list.first { it.collection.collectionId == item.collection.collectionId }
}
```
(turns out they are already sorted by episode in the correct order)
I think this is one o... |
49,775,716 | I need to get the same result I got, just by using react
I can't seem to find a way to reach the unorderd list if I creat it in the return of the render function, I'm new to react and just found out that getElementById just returns null in this case
(create an unordered list, Clicking on one of the items toggle the co... | 2018/04/11 | [
"https://Stackoverflow.com/questions/49775716",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9630519/"
] | If the TreeViewItem is not expanded then its children will not have any UI so you can't get their children. Maybe that's the problem you're seeing.
This is some code to think about, I don't have all your code to easily work out what's happening but this works on a sample I have. It is quick and dirty rather than super... | The TV has a nodes collection. Each node also has a nodes collection.
You need to start at the root, examine each node, and if that node contains a nodes collection with a length > 0, you need to descend into it.
This is typically done with a recursive tree walk. |
21,683,798 | I'm using Sinatra.
I have a deck: in main.rb
```
session[:deck] = []
suit = ['Clubs', 'Spades', 'Hearts', 'Diamonds']
values = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen','King', 'Ace']
session[:deck] = suit.product(values).shuffle!
```
In my game.erb I want to display the images associated with ... | 2014/02/10 | [
"https://Stackoverflow.com/questions/21683798",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3138341/"
] | The definition of which card image applies to a particular card needs to be done in the controller, not in the view. I'd structure things differently:
```
SUITS = %w[Clubs Spades Hearts Diamonds]
VALUES = %w[2 3 4 5 6 7 8 9 10 Jack Queen King Ace]
CARDS = SUITS.product(VALUES)
IMAGES = Hash[ CARDS.map{ |suit, value|... | ```
<img src='/images/cards/<%= "#{session[:deck].first}_#{session[:deck].last} %>.jpg' height="120" width="120>
```
But probably it's better to do:
```
<%= image_tag "cards/#{session[:deck].first}_#{session[:deck].last}.jpg", size: '120' %>
``` |
21,683,798 | I'm using Sinatra.
I have a deck: in main.rb
```
session[:deck] = []
suit = ['Clubs', 'Spades', 'Hearts', 'Diamonds']
values = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen','King', 'Ace']
session[:deck] = suit.product(values).shuffle!
```
In my game.erb I want to display the images associated with ... | 2014/02/10 | [
"https://Stackoverflow.com/questions/21683798",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3138341/"
] | You can create a method in your helpers:
```
def display_image(card)
"<img src='/images/cards/#{card[0]}_#{card[1]}.jpg' height='100' width='100'>"
end
```
Then you would call your method like so:
```
<%= display_image(card) %>
``` | ```
<img src='/images/cards/<%= "#{session[:deck].first}_#{session[:deck].last} %>.jpg' height="120" width="120>
```
But probably it's better to do:
```
<%= image_tag "cards/#{session[:deck].first}_#{session[:deck].last}.jpg", size: '120' %>
``` |
25,650,533 | I am getting a syntax error on this statement below that combines an If, IsError and VLOOKUP statement - I been trying everything..... anyone know why?
```
If Application.Worksheetfunction.IsError(VLOOKUP(cell.Value,'[Codes.xlsx]Processing Codes'!ProcessingCodesTable,5,FALSE)) = FALSE then
```
Thanks any help would ... | 2014/09/03 | [
"https://Stackoverflow.com/questions/25650533",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3242388/"
] | A SQL table represents an *unordered* set. There is no concept of "in-between" (or first or last or previous or next). The rows simply are; they are in the table.
Queries return *result sets* that have an order. And, you can control the order when you write the query. That is why you use the `order by` clause. When yo... | Hmmmm.
It doesn't seem you are using rows and columns as they are intended in a database.
However, a solution for your problem would be doing this:
For every Math, start on a new row:
```
ID Stuff
100 Maths Science Biology
200 Maths Science Biology Geography
300 Maths Science
```
To read this data structure you... |
25,650,533 | I am getting a syntax error on this statement below that combines an If, IsError and VLOOKUP statement - I been trying everything..... anyone know why?
```
If Application.Worksheetfunction.IsError(VLOOKUP(cell.Value,'[Codes.xlsx]Processing Codes'!ProcessingCodesTable,5,FALSE)) = FALSE then
```
Thanks any help would ... | 2014/09/03 | [
"https://Stackoverflow.com/questions/25650533",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3242388/"
] | A SQL table represents an *unordered* set. There is no concept of "in-between" (or first or last or previous or next). The rows simply are; they are in the table.
Queries return *result sets* that have an order. And, you can control the order when you write the query. That is why you use the `order by` clause. When yo... | As others have noted relational databases are not really meant to work with ordered lists.
You could work out some convoluted solution like select the "math" rows followed by "science" rows and then use that to insert "Physics" row.
Something like:
```
CREATE TABLE temp_table AS
(
(SELECT
t1.id+1 AS id,
'Physics' AS... |
25,650,533 | I am getting a syntax error on this statement below that combines an If, IsError and VLOOKUP statement - I been trying everything..... anyone know why?
```
If Application.Worksheetfunction.IsError(VLOOKUP(cell.Value,'[Codes.xlsx]Processing Codes'!ProcessingCodesTable,5,FALSE)) = FALSE then
```
Thanks any help would ... | 2014/09/03 | [
"https://Stackoverflow.com/questions/25650533",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3242388/"
] | Hmmmm.
It doesn't seem you are using rows and columns as they are intended in a database.
However, a solution for your problem would be doing this:
For every Math, start on a new row:
```
ID Stuff
100 Maths Science Biology
200 Maths Science Biology Geography
300 Maths Science
```
To read this data structure you... | As others have noted relational databases are not really meant to work with ordered lists.
You could work out some convoluted solution like select the "math" rows followed by "science" rows and then use that to insert "Physics" row.
Something like:
```
CREATE TABLE temp_table AS
(
(SELECT
t1.id+1 AS id,
'Physics' AS... |
69,721,679 | How do we get a date before the current date using DayJs.
I know how to get the current date but can we like remove 15 days from the current date?
```
cy.get('input[name="day"]').should('have.value', (Cypress.dayjs().format('DD')))
cy.get('input[name="month"]').should('have.value', (Cypress.dayjs().format('MM')))
cy... | 2021/10/26 | [
"https://Stackoverflow.com/questions/69721679",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15647985/"
] | From the [documentation](https://day.js.org/docs/en/manipulate/subtract):
```js
dayjs().subtract(15, 'day');
```
Available units are mentioned [here](https://day.js.org/docs/en/manipulate/add#list-of-all-available-units), `day` is one of them. | As @pavelsaman mentioned `.subtract` will work. Yo just have to format it to extract day, month, year.
```js
const dayjs = require('dayjs')
cy.get('input[name="day"]').should(
'have.value',
dayjs().subtract(15, 'day').format('DD')
) //11
cy.get('input[name="month"]').should(
'have.value',
dayjs().subtract(15,... |
69,721,679 | How do we get a date before the current date using DayJs.
I know how to get the current date but can we like remove 15 days from the current date?
```
cy.get('input[name="day"]').should('have.value', (Cypress.dayjs().format('DD')))
cy.get('input[name="month"]').should('have.value', (Cypress.dayjs().format('MM')))
cy... | 2021/10/26 | [
"https://Stackoverflow.com/questions/69721679",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15647985/"
] | From the [documentation](https://day.js.org/docs/en/manipulate/subtract):
```js
dayjs().subtract(15, 'day');
```
Available units are mentioned [here](https://day.js.org/docs/en/manipulate/add#list-of-all-available-units), `day` is one of them. | For readable test, calculate target once.
```js
const target = dayjs().subtract(15, 'day')
cy.get('input[name="day"]').should('have.value', target.format('DD'))
cy.get('input[name="month"]').should('have.value', target.format('MM'))
cy.get('input[name="year"]').should('have.value', target .format('YY'))
``` |
69,721,679 | How do we get a date before the current date using DayJs.
I know how to get the current date but can we like remove 15 days from the current date?
```
cy.get('input[name="day"]').should('have.value', (Cypress.dayjs().format('DD')))
cy.get('input[name="month"]').should('have.value', (Cypress.dayjs().format('MM')))
cy... | 2021/10/26 | [
"https://Stackoverflow.com/questions/69721679",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15647985/"
] | For readable test, calculate target once.
```js
const target = dayjs().subtract(15, 'day')
cy.get('input[name="day"]').should('have.value', target.format('DD'))
cy.get('input[name="month"]').should('have.value', target.format('MM'))
cy.get('input[name="year"]').should('have.value', target .format('YY'))
``` | As @pavelsaman mentioned `.subtract` will work. Yo just have to format it to extract day, month, year.
```js
const dayjs = require('dayjs')
cy.get('input[name="day"]').should(
'have.value',
dayjs().subtract(15, 'day').format('DD')
) //11
cy.get('input[name="month"]').should(
'have.value',
dayjs().subtract(15,... |
1,042,110 | I don't know if this is true, but when I was reading FAQ on one of the problem providing sites, I found something, that poke my attention:
>
> Check your input/output methods. In C++, using cin and cout is too slow. Use these, and you will guarantee not being able to solve any problem with a decent amount of input or... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1042110",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/126781/"
] | <http://www.quora.com/Is-cin-cout-slower-than-scanf-printf/answer/Aditya-Vishwakarma>
Performance of `cin`/`cout` can be slow because they need to keep themselves in sync with the underlying C library. This is essential if both C IO and C++ IO is going to be used.
However, if you only going to use C++ IO, then simply... | Probably scanf is somewhat faster than using streams. Although streams provide a lot of type safety, and do not have to parse format strings at runtime, it usually has an advantage of not requiring excessive memory allocations (this depends on your compiler and runtime). That said, unless performance is your only end g... |
1,042,110 | I don't know if this is true, but when I was reading FAQ on one of the problem providing sites, I found something, that poke my attention:
>
> Check your input/output methods. In C++, using cin and cout is too slow. Use these, and you will guarantee not being able to solve any problem with a decent amount of input or... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1042110",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/126781/"
] | The statements `cin` and `cout` in general use seem to be slower than `scanf` and `printf` in C++, but actually they are FASTER!
The thing is: In C++, whenever you use `cin` and `cout`, a synchronization process takes place by default that makes sure that if you use both `scanf` and `cin` in your program, then they bo... | Of course it's ridiculous to use cstdio over iostream. At least when you develop software (if you are already using c++ over c, then go all the way and use it's benefits instead of only suffering from it's disadvantages).
But in the online judge you are not developing software, you are creating a program that should b... |
1,042,110 | I don't know if this is true, but when I was reading FAQ on one of the problem providing sites, I found something, that poke my attention:
>
> Check your input/output methods. In C++, using cin and cout is too slow. Use these, and you will guarantee not being able to solve any problem with a decent amount of input or... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1042110",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/126781/"
] | Here's a quick test of a simple case: a program to read a list of numbers from standard input and XOR all of the numbers.
**iostream version:**
```
#include <iostream>
int main(int argc, char **argv) {
int parity = 0;
int x;
while (std::cin >> x)
parity ^= x;
std::cout << parity << std::endl;
return... | Of course it's ridiculous to use cstdio over iostream. At least when you develop software (if you are already using c++ over c, then go all the way and use it's benefits instead of only suffering from it's disadvantages).
But in the online judge you are not developing software, you are creating a program that should b... |
1,042,110 | I don't know if this is true, but when I was reading FAQ on one of the problem providing sites, I found something, that poke my attention:
>
> Check your input/output methods. In C++, using cin and cout is too slow. Use these, and you will guarantee not being able to solve any problem with a decent amount of input or... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1042110",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/126781/"
] | The statements `cin` and `cout` in general use seem to be slower than `scanf` and `printf` in C++, but actually they are FASTER!
The thing is: In C++, whenever you use `cin` and `cout`, a synchronization process takes place by default that makes sure that if you use both `scanf` and `cin` in your program, then they bo... | The problem is that `cin` has a lot of overhead involved because it gives you an abstraction layer above `scanf()` calls. You shouldn't use `scanf()` over `cin` if you are writing C++ software because that is want `cin` is for. If you want performance, you probably wouldn't be writing I/O in C++ anyway. |
1,042,110 | I don't know if this is true, but when I was reading FAQ on one of the problem providing sites, I found something, that poke my attention:
>
> Check your input/output methods. In C++, using cin and cout is too slow. Use these, and you will guarantee not being able to solve any problem with a decent amount of input or... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1042110",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/126781/"
] | <http://www.quora.com/Is-cin-cout-slower-than-scanf-printf/answer/Aditya-Vishwakarma>
Performance of `cin`/`cout` can be slow because they need to keep themselves in sync with the underlying C library. This is essential if both C IO and C++ IO is going to be used.
However, if you only going to use C++ IO, then simply... | The problem is that `cin` has a lot of overhead involved because it gives you an abstraction layer above `scanf()` calls. You shouldn't use `scanf()` over `cin` if you are writing C++ software because that is want `cin` is for. If you want performance, you probably wouldn't be writing I/O in C++ anyway. |
1,042,110 | I don't know if this is true, but when I was reading FAQ on one of the problem providing sites, I found something, that poke my attention:
>
> Check your input/output methods. In C++, using cin and cout is too slow. Use these, and you will guarantee not being able to solve any problem with a decent amount of input or... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1042110",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/126781/"
] | Yes iostream is slower than cstdio.
Yes you probably shouldn't use cstdio if you're developing in C++.
Having said that, there are even faster ways to get I/O than scanf if you don't care about formatting, type safety, blah, blah, blah...
For instance this is a custom routine to get a number from STDIN:
```
inl... | ```
#include <stdio.h>
#include <unistd.h>
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
static int scanuint(unsigned int* x)
{
char c;
*x = 0;
do
{
c = getchar_unlocked();
if (unlikely(c==EOF)) return 1;
} while(c<'0' || c>'9');
do
{... |
1,042,110 | I don't know if this is true, but when I was reading FAQ on one of the problem providing sites, I found something, that poke my attention:
>
> Check your input/output methods. In C++, using cin and cout is too slow. Use these, and you will guarantee not being able to solve any problem with a decent amount of input or... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1042110",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/126781/"
] | The statements `cin` and `cout` in general use seem to be slower than `scanf` and `printf` in C++, but actually they are FASTER!
The thing is: In C++, whenever you use `cin` and `cout`, a synchronization process takes place by default that makes sure that if you use both `scanf` and `cin` in your program, then they bo... | Yes iostream is slower than cstdio.
Yes you probably shouldn't use cstdio if you're developing in C++.
Having said that, there are even faster ways to get I/O than scanf if you don't care about formatting, type safety, blah, blah, blah...
For instance this is a custom routine to get a number from STDIN:
```
inl... |
1,042,110 | I don't know if this is true, but when I was reading FAQ on one of the problem providing sites, I found something, that poke my attention:
>
> Check your input/output methods. In C++, using cin and cout is too slow. Use these, and you will guarantee not being able to solve any problem with a decent amount of input or... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1042110",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/126781/"
] | Yes iostream is slower than cstdio.
Yes you probably shouldn't use cstdio if you're developing in C++.
Having said that, there are even faster ways to get I/O than scanf if you don't care about formatting, type safety, blah, blah, blah...
For instance this is a custom routine to get a number from STDIN:
```
inl... | The problem is that `cin` has a lot of overhead involved because it gives you an abstraction layer above `scanf()` calls. You shouldn't use `scanf()` over `cin` if you are writing C++ software because that is want `cin` is for. If you want performance, you probably wouldn't be writing I/O in C++ anyway. |
1,042,110 | I don't know if this is true, but when I was reading FAQ on one of the problem providing sites, I found something, that poke my attention:
>
> Check your input/output methods. In C++, using cin and cout is too slow. Use these, and you will guarantee not being able to solve any problem with a decent amount of input or... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1042110",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/126781/"
] | Here's a quick test of a simple case: a program to read a list of numbers from standard input and XOR all of the numbers.
**iostream version:**
```
#include <iostream>
int main(int argc, char **argv) {
int parity = 0;
int x;
while (std::cin >> x)
parity ^= x;
std::cout << parity << std::endl;
return... | The statements `cin` and `cout` in general use seem to be slower than `scanf` and `printf` in C++, but actually they are FASTER!
The thing is: In C++, whenever you use `cin` and `cout`, a synchronization process takes place by default that makes sure that if you use both `scanf` and `cin` in your program, then they bo... |
1,042,110 | I don't know if this is true, but when I was reading FAQ on one of the problem providing sites, I found something, that poke my attention:
>
> Check your input/output methods. In C++, using cin and cout is too slow. Use these, and you will guarantee not being able to solve any problem with a decent amount of input or... | 2009/06/25 | [
"https://Stackoverflow.com/questions/1042110",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/126781/"
] | If you care about both performance and string formatting, do take a look at [Matthew Wilson's FastFormat](http://fastformat.sourceforge.net/) library.
edit -- link to accu publication on that library: <http://accu.org/index.php/journals/1539> | Of course it's ridiculous to use cstdio over iostream. At least when you develop software (if you are already using c++ over c, then go all the way and use it's benefits instead of only suffering from it's disadvantages).
But in the online judge you are not developing software, you are creating a program that should b... |
13,971,674 | >
> **Possible Duplicate:**
>
> [100% width bg images not extending on horizontal scroll](https://stackoverflow.com/questions/3042979/100-width-bg-images-not-extending-on-horizontal-scroll)
>
>
>
I have been struggling with this issue for quite a while. I am building a very basic web application for travel age... | 2012/12/20 | [
"https://Stackoverflow.com/questions/13971674",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1451537/"
] | without regard to other errors or inconsistencies. also let me note that you should use mysqli or pdo. but php uses `time()`
```
$sql_insert = mysql_query("
INSERT INTO newsletter
(name, email, dateTime)
VALUES
... | 1. make sure you are connected to the database ! see what `echo mysql_error();` says
2. if a form was submitted, catch the values, and then sanitize
3. insert query
ps: see what the following do:
```
if(isset($_POST['name']) ...
echo mysql_insert_id();
time() not now()
```
see the `id` of the new data inserted
... |
13,971,674 | >
> **Possible Duplicate:**
>
> [100% width bg images not extending on horizontal scroll](https://stackoverflow.com/questions/3042979/100-width-bg-images-not-extending-on-horizontal-scroll)
>
>
>
I have been struggling with this issue for quite a while. I am building a very basic web application for travel age... | 2012/12/20 | [
"https://Stackoverflow.com/questions/13971674",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1451537/"
] | You have to change `now()` from your code. And Use Following code.
```
$time = time() ;
$sql_insert = mysql_query("INSERT INTO newsletter (name, email, dateTime) VALUES ('".$name."', '".$email."', '".$time."' )") or die (mysql_error());
``` | 1. make sure you are connected to the database ! see what `echo mysql_error();` says
2. if a form was submitted, catch the values, and then sanitize
3. insert query
ps: see what the following do:
```
if(isset($_POST['name']) ...
echo mysql_insert_id();
time() not now()
```
see the `id` of the new data inserted
... |
30,289,633 | I'm currently trying to get along with Layouts, considering that I never really understood them and only did nullLayout instead, absolutely positioning all elements then.
However, I currently have a suitable small project, where I am trying to learn it, which is some small chat service.
Here is a picture right now: !... | 2015/05/17 | [
"https://Stackoverflow.com/questions/30289633",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4787510/"
] | Initially, you've got one simple problem:
```
// should be new JPanel(new BorderLayout())
JPanel messagePanel = new JPanel();
```
Then, after that, generally BorderLayout likes to stretch the component in `BorderLayout.CENTER`. So you want to put your `textfield` and `chatMessage` in the center.
```
public... | Try `BoxLayout` insted `BorderLayout` in `messagePanel`:
```
messagePanel.setLayout(new BoxLayout(messagePanel,BoxLayout.LINE_AXIS));
messagePanel.add(chatMessage);
messagePanel.add(send);
```
And for `textField`:
```
frame.add(textfield, BorderLayout.CENTER);
``` |
30,289,633 | I'm currently trying to get along with Layouts, considering that I never really understood them and only did nullLayout instead, absolutely positioning all elements then.
However, I currently have a suitable small project, where I am trying to learn it, which is some small chat service.
Here is a picture right now: !... | 2015/05/17 | [
"https://Stackoverflow.com/questions/30289633",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4787510/"
] | Initially, you've got one simple problem:
```
// should be new JPanel(new BorderLayout())
JPanel messagePanel = new JPanel();
```
Then, after that, generally BorderLayout likes to stretch the component in `BorderLayout.CENTER`. So you want to put your `textfield` and `chatMessage` in the center.
```
public... | Try setting preferred size dimensions of the elements.
```
textfield.setText("Textfield");
textfield.setPreferredSize(new Dimension(600, 300));
//some other code
JTextField chatMessage = new JTextField();
chatMessage.setPreferredSize(new Dimension(500, 25));
//some other code
``` |
30,289,633 | I'm currently trying to get along with Layouts, considering that I never really understood them and only did nullLayout instead, absolutely positioning all elements then.
However, I currently have a suitable small project, where I am trying to learn it, which is some small chat service.
Here is a picture right now: !... | 2015/05/17 | [
"https://Stackoverflow.com/questions/30289633",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4787510/"
] | Initially, you've got one simple problem:
```
// should be new JPanel(new BorderLayout())
JPanel messagePanel = new JPanel();
```
Then, after that, generally BorderLayout likes to stretch the component in `BorderLayout.CENTER`. So you want to put your `textfield` and `chatMessage` in the center.
```
public... | As pointed out by [Sridhar](https://stackoverflow.com/users/1806481/sridhar), `BorderLayout` does not always respect the dimensions of sub-panels. To fix this, you should initialize your sub-panels (in this case `textfield` and `messagePanel`) using `setPreferedSize()` instead of `setSize()`. |
30,289,633 | I'm currently trying to get along with Layouts, considering that I never really understood them and only did nullLayout instead, absolutely positioning all elements then.
However, I currently have a suitable small project, where I am trying to learn it, which is some small chat service.
Here is a picture right now: !... | 2015/05/17 | [
"https://Stackoverflow.com/questions/30289633",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4787510/"
] | Initially, you've got one simple problem:
```
// should be new JPanel(new BorderLayout())
JPanel messagePanel = new JPanel();
```
Then, after that, generally BorderLayout likes to stretch the component in `BorderLayout.CENTER`. So you want to put your `textfield` and `chatMessage` in the center.
```
public... | change your constructor to
```
public Gui() {
frame = new JFrame();
frame.setSize(600, 400);
textfield = new JTextArea();
textfield.setText("Textfield");
textfield.setSize(400, 300);
// set border layout to JPanel
JPanel messagePanel = new JPanel(new BorderLayout());
JTextField chatM... |
332,441 | I was at an interview for a C position in which they presented me with an idiom that I haven't previously encountered. This is a trick that simplifies implementation of various algorithms involving linked lists and I'm wondering if anybody else has encountered this.
Say we have a linked list record defined so:
```
ty... | 2008/12/01 | [
"https://Stackoverflow.com/questions/332441",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15109/"
] | What would be the idiom here? Surely not the implementation of a linked list.
The usage of a pointer to pointer construct?
The compact loop?
Personally I'd use a pointer return value instead of operating on an input value.
Because seeing this input data type would ring a bell, which makes me copy my value before handi... | To answer the original question, this is known as a pointer centric approach instead of the naive node centric approach. Chapter 3 of "Advanced Programming Techniques" by Rex Barzee available at [amazon.com](https://rads.stackoverflow.com/amzn/click/com/B006R2CSXM) includes a much better example implementation of the p... |
332,441 | I was at an interview for a C position in which they presented me with an idiom that I haven't previously encountered. This is a trick that simplifies implementation of various algorithms involving linked lists and I'm wondering if anybody else has encountered this.
Say we have a linked list record defined so:
```
ty... | 2008/12/01 | [
"https://Stackoverflow.com/questions/332441",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15109/"
] | What would be the idiom here? Surely not the implementation of a linked list.
The usage of a pointer to pointer construct?
The compact loop?
Personally I'd use a pointer return value instead of operating on an input value.
Because seeing this input data type would ring a bell, which makes me copy my value before handi... | This idiom is given in the Chapter 12 of "Pointers on C".This is used to insert a node into a linked list without list head. |
332,441 | I was at an interview for a C position in which they presented me with an idiom that I haven't previously encountered. This is a trick that simplifies implementation of various algorithms involving linked lists and I'm wondering if anybody else has encountered this.
Say we have a linked list record defined so:
```
ty... | 2008/12/01 | [
"https://Stackoverflow.com/questions/332441",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15109/"
] | I don't know if this has a name or even if it's some special idiom but, since memory is relatively plentiful nowadays, my linked lists (where the language libraries don't make them available) are a special variant which simplifies the code greatly.
For a start, they're always doubly-linked since this makes traversal i... | I have also come up with this use of a double pointer, I have used it, but I don't really like it. The code that I came up with has this kernel to search for certain objects and remove them from the list:
```
Element** previous = &firstElement, *current;
while((current = *previous)) {
if(shouldRemove(current)) {
... |
332,441 | I was at an interview for a C position in which they presented me with an idiom that I haven't previously encountered. This is a trick that simplifies implementation of various algorithms involving linked lists and I'm wondering if anybody else has encountered this.
Say we have a linked list record defined so:
```
ty... | 2008/12/01 | [
"https://Stackoverflow.com/questions/332441",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15109/"
] | I don't know if this has a name or even if it's some special idiom but, since memory is relatively plentiful nowadays, my linked lists (where the language libraries don't make them available) are a special variant which simplifies the code greatly.
For a start, they're always doubly-linked since this makes traversal i... | Instead of returning the value of the new node as an in/out parameter, you are better off having that be the return value of the function. This simplifies both the calling code, and the code inside the function (you can get rid of all those ugly double indirections).
```
record* insert_sorted(const record* head, const... |
332,441 | I was at an interview for a C position in which they presented me with an idiom that I haven't previously encountered. This is a trick that simplifies implementation of various algorithms involving linked lists and I'm wondering if anybody else has encountered this.
Say we have a linked list record defined so:
```
ty... | 2008/12/01 | [
"https://Stackoverflow.com/questions/332441",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15109/"
] | I don't see anything I'd call an idiom per se. It looks like standard coding for when you deal with datastructures in C.
My only complaint would be that the callers pointer (\*r) is modified. Depending on the use of the function, I'd expect thats an unexpected side effect. Besides removing the unexpected side effect, ... | To answer the original question, this is known as a pointer centric approach instead of the naive node centric approach. Chapter 3 of "Advanced Programming Techniques" by Rex Barzee available at [amazon.com](https://rads.stackoverflow.com/amzn/click/com/B006R2CSXM) includes a much better example implementation of the p... |
332,441 | I was at an interview for a C position in which they presented me with an idiom that I haven't previously encountered. This is a trick that simplifies implementation of various algorithms involving linked lists and I'm wondering if anybody else has encountered this.
Say we have a linked list record defined so:
```
ty... | 2008/12/01 | [
"https://Stackoverflow.com/questions/332441",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15109/"
] | This idiom is given in the Chapter 12 of "Pointers on C".This is used to insert a node into a linked list without list head. | I have also come up with this use of a double pointer, I have used it, but I don't really like it. The code that I came up with has this kernel to search for certain objects and remove them from the list:
```
Element** previous = &firstElement, *current;
while((current = *previous)) {
if(shouldRemove(current)) {
... |
332,441 | I was at an interview for a C position in which they presented me with an idiom that I haven't previously encountered. This is a trick that simplifies implementation of various algorithms involving linked lists and I'm wondering if anybody else has encountered this.
Say we have a linked list record defined so:
```
ty... | 2008/12/01 | [
"https://Stackoverflow.com/questions/332441",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15109/"
] | I'd say the idiom is "the kind of code which gave 'c' a bad name"
* Unwarrantedly clever
* Unwarrantedly compact
* Surprising side effects on caller
* No error handling on malloc
* Only works for US English strings | This idiom is given in the Chapter 12 of "Pointers on C".This is used to insert a node into a linked list without list head. |
332,441 | I was at an interview for a C position in which they presented me with an idiom that I haven't previously encountered. This is a trick that simplifies implementation of various algorithms involving linked lists and I'm wondering if anybody else has encountered this.
Say we have a linked list record defined so:
```
ty... | 2008/12/01 | [
"https://Stackoverflow.com/questions/332441",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15109/"
] | This is a well known thing - double pointer iteration (that's my name for it, I don't know the official name). The goal is to be able to locate a position in single linked list, and then insert *before* that position (inserting after it is trivial). Implemented naively, this requires two pointers (current and prev) and... | I have also come up with this use of a double pointer, I have used it, but I don't really like it. The code that I came up with has this kernel to search for certain objects and remove them from the list:
```
Element** previous = &firstElement, *current;
while((current = *previous)) {
if(shouldRemove(current)) {
... |
332,441 | I was at an interview for a C position in which they presented me with an idiom that I haven't previously encountered. This is a trick that simplifies implementation of various algorithms involving linked lists and I'm wondering if anybody else has encountered this.
Say we have a linked list record defined so:
```
ty... | 2008/12/01 | [
"https://Stackoverflow.com/questions/332441",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15109/"
] | What would be the idiom here? Surely not the implementation of a linked list.
The usage of a pointer to pointer construct?
The compact loop?
Personally I'd use a pointer return value instead of operating on an input value.
Because seeing this input data type would ring a bell, which makes me copy my value before handi... | I have also come up with this use of a double pointer, I have used it, but I don't really like it. The code that I came up with has this kernel to search for certain objects and remove them from the list:
```
Element** previous = &firstElement, *current;
while((current = *previous)) {
if(shouldRemove(current)) {
... |
332,441 | I was at an interview for a C position in which they presented me with an idiom that I haven't previously encountered. This is a trick that simplifies implementation of various algorithms involving linked lists and I'm wondering if anybody else has encountered this.
Say we have a linked list record defined so:
```
ty... | 2008/12/01 | [
"https://Stackoverflow.com/questions/332441",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15109/"
] | I'd say the idiom is "the kind of code which gave 'c' a bad name"
* Unwarrantedly clever
* Unwarrantedly compact
* Surprising side effects on caller
* No error handling on malloc
* Only works for US English strings | To answer the original question, this is known as a pointer centric approach instead of the naive node centric approach. Chapter 3 of "Advanced Programming Techniques" by Rex Barzee available at [amazon.com](https://rads.stackoverflow.com/amzn/click/com/B006R2CSXM) includes a much better example implementation of the p... |
2,183,519 | I'm new to Java and really need your help.
I am presently using a queue, a receiver thread puts data into this queue and the parser reads out of this.
But the problem is the receiver may receive at incredible peak speed, ~~eg. 3000/sec, while the parser only parses at 100/sec.~~
>
> EDIT:I have checked, the queue f... | 2010/02/02 | [
"https://Stackoverflow.com/questions/2183519",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/262296/"
] | Since data comes in 30 times faster than it is processed you may extend HeapSize using
`java -Xms<initial heap size> -Xmx<maximum heap size>` if the transmission is finished before your memory is exhausted.
* Or as youself suggested dump the data to disc and process delayed.
* Otherwise you would have to optimze you... | I have a theory, the implementation of `ArrayDeque` (at least in Oracle JDK, I'm not sure about Android's) **seems** to never actually deallocate popped elements.
In other words, slots for popped elements are simply nulled. While elements added to the tail will make the "inner array" grow bigger for eternity, which wi... |
2,183,519 | I'm new to Java and really need your help.
I am presently using a queue, a receiver thread puts data into this queue and the parser reads out of this.
But the problem is the receiver may receive at incredible peak speed, ~~eg. 3000/sec, while the parser only parses at 100/sec.~~
>
> EDIT:I have checked, the queue f... | 2010/02/02 | [
"https://Stackoverflow.com/questions/2183519",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/262296/"
] | If the producer produces more data then the consumer can handle, then the data will start to accumulate and eventually you run into OutOfMemory problems. This will depend on (1) the rate difference between the producer and consumer, (2) the quantity of data you have to process.
I suggest you limit the number of items ... | When you run `java`, you can use the `-Xmx` parameter to make more memory available to the virtual machine. For example, `java -Xmx512m` will allow the VM to allocate up to 512Mb of memory. (The default is fairly small).
But if you're allocating memory and filling up a list with data and never removing it, eventually ... |
2,183,519 | I'm new to Java and really need your help.
I am presently using a queue, a receiver thread puts data into this queue and the parser reads out of this.
But the problem is the receiver may receive at incredible peak speed, ~~eg. 3000/sec, while the parser only parses at 100/sec.~~
>
> EDIT:I have checked, the queue f... | 2010/02/02 | [
"https://Stackoverflow.com/questions/2183519",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/262296/"
] | If the producer produces more data then the consumer can handle, then the data will start to accumulate and eventually you run into OutOfMemory problems. This will depend on (1) the rate difference between the producer and consumer, (2) the quantity of data you have to process.
I suggest you limit the number of items ... | Another way to do this would be to sample the data when queue gets too big, and save the sampling rate so we could simulate the original data. |
2,183,519 | I'm new to Java and really need your help.
I am presently using a queue, a receiver thread puts data into this queue and the parser reads out of this.
But the problem is the receiver may receive at incredible peak speed, ~~eg. 3000/sec, while the parser only parses at 100/sec.~~
>
> EDIT:I have checked, the queue f... | 2010/02/02 | [
"https://Stackoverflow.com/questions/2183519",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/262296/"
] | If you receive 3000/sec but only process 100/sec sooner or later you will run out of memory.
May I suggest you use more threads to do the parsing?
Concerning the queue, have a look at [LinkedBlockingDeque](http://java.sun.com/javase/6/docs/api/java/util/concurrent/LinkedBlockingDeque.html) and [LinkedBlockingQueue](ht... | When you run `java`, you can use the `-Xmx` parameter to make more memory available to the virtual machine. For example, `java -Xmx512m` will allow the VM to allocate up to 512Mb of memory. (The default is fairly small).
But if you're allocating memory and filling up a list with data and never removing it, eventually ... |
2,183,519 | I'm new to Java and really need your help.
I am presently using a queue, a receiver thread puts data into this queue and the parser reads out of this.
But the problem is the receiver may receive at incredible peak speed, ~~eg. 3000/sec, while the parser only parses at 100/sec.~~
>
> EDIT:I have checked, the queue f... | 2010/02/02 | [
"https://Stackoverflow.com/questions/2183519",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/262296/"
] | If you receive 3000/sec but only process 100/sec sooner or later you will run out of memory.
May I suggest you use more threads to do the parsing?
Concerning the queue, have a look at [LinkedBlockingDeque](http://java.sun.com/javase/6/docs/api/java/util/concurrent/LinkedBlockingDeque.html) and [LinkedBlockingQueue](ht... | I have a theory, the implementation of `ArrayDeque` (at least in Oracle JDK, I'm not sure about Android's) **seems** to never actually deallocate popped elements.
In other words, slots for popped elements are simply nulled. While elements added to the tail will make the "inner array" grow bigger for eternity, which wi... |
2,183,519 | I'm new to Java and really need your help.
I am presently using a queue, a receiver thread puts data into this queue and the parser reads out of this.
But the problem is the receiver may receive at incredible peak speed, ~~eg. 3000/sec, while the parser only parses at 100/sec.~~
>
> EDIT:I have checked, the queue f... | 2010/02/02 | [
"https://Stackoverflow.com/questions/2183519",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/262296/"
] | If the producer produces more data then the consumer can handle, then the data will start to accumulate and eventually you run into OutOfMemory problems. This will depend on (1) the rate difference between the producer and consumer, (2) the quantity of data you have to process.
I suggest you limit the number of items ... | I have a theory, the implementation of `ArrayDeque` (at least in Oracle JDK, I'm not sure about Android's) **seems** to never actually deallocate popped elements.
In other words, slots for popped elements are simply nulled. While elements added to the tail will make the "inner array" grow bigger for eternity, which wi... |
2,183,519 | I'm new to Java and really need your help.
I am presently using a queue, a receiver thread puts data into this queue and the parser reads out of this.
But the problem is the receiver may receive at incredible peak speed, ~~eg. 3000/sec, while the parser only parses at 100/sec.~~
>
> EDIT:I have checked, the queue f... | 2010/02/02 | [
"https://Stackoverflow.com/questions/2183519",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/262296/"
] | Since data comes in 30 times faster than it is processed you may extend HeapSize using
`java -Xms<initial heap size> -Xmx<maximum heap size>` if the transmission is finished before your memory is exhausted.
* Or as youself suggested dump the data to disc and process delayed.
* Otherwise you would have to optimze you... | When you run `java`, you can use the `-Xmx` parameter to make more memory available to the virtual machine. For example, `java -Xmx512m` will allow the VM to allocate up to 512Mb of memory. (The default is fairly small).
But if you're allocating memory and filling up a list with data and never removing it, eventually ... |
2,183,519 | I'm new to Java and really need your help.
I am presently using a queue, a receiver thread puts data into this queue and the parser reads out of this.
But the problem is the receiver may receive at incredible peak speed, ~~eg. 3000/sec, while the parser only parses at 100/sec.~~
>
> EDIT:I have checked, the queue f... | 2010/02/02 | [
"https://Stackoverflow.com/questions/2183519",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/262296/"
] | If you receive 3000/sec but only process 100/sec sooner or later you will run out of memory.
May I suggest you use more threads to do the parsing?
Concerning the queue, have a look at [LinkedBlockingDeque](http://java.sun.com/javase/6/docs/api/java/util/concurrent/LinkedBlockingDeque.html) and [LinkedBlockingQueue](ht... | If the producer produces more data then the consumer can handle, then the data will start to accumulate and eventually you run into OutOfMemory problems. This will depend on (1) the rate difference between the producer and consumer, (2) the quantity of data you have to process.
I suggest you limit the number of items ... |
2,183,519 | I'm new to Java and really need your help.
I am presently using a queue, a receiver thread puts data into this queue and the parser reads out of this.
But the problem is the receiver may receive at incredible peak speed, ~~eg. 3000/sec, while the parser only parses at 100/sec.~~
>
> EDIT:I have checked, the queue f... | 2010/02/02 | [
"https://Stackoverflow.com/questions/2183519",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/262296/"
] | >
> I guess the problem is that queue is made using a linked-list, and all the pointers must be saved in the heap.
>
>
>
I don't think so. I think that the *real* problem is the mismatch between the rate at which your system gets input and the rate that it can process it. Unless you can process at at least the ave... | I have a theory, the implementation of `ArrayDeque` (at least in Oracle JDK, I'm not sure about Android's) **seems** to never actually deallocate popped elements.
In other words, slots for popped elements are simply nulled. While elements added to the tail will make the "inner array" grow bigger for eternity, which wi... |
2,183,519 | I'm new to Java and really need your help.
I am presently using a queue, a receiver thread puts data into this queue and the parser reads out of this.
But the problem is the receiver may receive at incredible peak speed, ~~eg. 3000/sec, while the parser only parses at 100/sec.~~
>
> EDIT:I have checked, the queue f... | 2010/02/02 | [
"https://Stackoverflow.com/questions/2183519",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/262296/"
] | If you receive 3000/sec but only process 100/sec sooner or later you will run out of memory.
May I suggest you use more threads to do the parsing?
Concerning the queue, have a look at [LinkedBlockingDeque](http://java.sun.com/javase/6/docs/api/java/util/concurrent/LinkedBlockingDeque.html) and [LinkedBlockingQueue](ht... | Since data comes in 30 times faster than it is processed you may extend HeapSize using
`java -Xms<initial heap size> -Xmx<maximum heap size>` if the transmission is finished before your memory is exhausted.
* Or as youself suggested dump the data to disc and process delayed.
* Otherwise you would have to optimze you... |
17,846,444 | I'm developing a xtext-based language which should refer to objects defined in a vendor-specific file format.
E.g. this file format defines messages, my language shall define Rules that work with these messages. Of course i want to use xtext features e.g. to autocomplete/validate message names, attributes etc.
Not su... | 2013/07/24 | [
"https://Stackoverflow.com/questions/17846444",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2616578/"
] | I have two ideas what to check.
1. Xtext has a specific global scope provider called [ImportedNameSpaceAwareScopeProvider](http://download.eclipse.org/modeling/tmf/xtext/javadoc/2.3/org/eclipse/xtext/scoping/impl/ImportedNamespaceAwareLocalScopeProvider.html). By using an overridden version of this, you could specify ... | Finally, I ended up using the SimpleNamesFragment, ImportURIScopingFragment and a custom ScopeProvider derived from AbstractDeclarativeScopeProvider.
That way, I had to implement ScopeProvider methods for quiet a few rules but was much more flexible in using my "namespace prefix".
E.g. it is simple to implement syntax... |
27,129,681 | Since forward slashes can only occur in strings inside a JSON serialized object and are not escaped (in the default settings), using
```
json.dump(some_dict).replace('/', r'\/')
```
reliably works, but it looks hacky.
I know that forward slashes **don't have to be** escaped, but you **may** escape them, and for my... | 2014/11/25 | [
"https://Stackoverflow.com/questions/27129681",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/416224/"
] | **Only escape forward slashes when encode\_html\_chars=True**
Check out this-
<https://github.com/esnme/ultrajson/pull/114>
The JSON spec says forward slashes shall be escaped implicitly.
Here is a solution to do it in JSONEncoder itself. Its just that you create an ESCAPE DICTIONARY and do computation before hand a... | Use `escape_forward_slashes` as per ujson doc,
**escape\_forward\_slashes**
Controls whether forward slashes (/) are escaped. Default is True:
```
>>> ujson.dumps("http://esn.me")
'"http:\/\/esn.me"'
>>> ujson.dumps("http://esn.me", escape_forward_slashes=False)
'"http://esn.me"'
```
See [here](https://github.com/u... |
73,946,525 | I have a sample df
```
id name
1 John Walter walter
2 Adam Smith Smith
3 Steve Rogers rogers
```
How can I find whether it is duplicated in every row and pop it out?
```
id name is_duplicated poped_out_string corrected_name
1 John Walter walter... | 2022/10/04 | [
"https://Stackoverflow.com/questions/73946525",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7288928/"
] | First, query `ids` where `category` is completed:
```sql
select
category,
array_agg(id) as ids
from tbl
group by category
having bool_and(nullif(data_1, '') || nullif(data_2, '') is not null)
order by category;
category | ids
----------+---------
1 | {1,2}
5 | {13,14}
6 | {15}
(3 r... | ```
select distinct category from tbl
where category not in (
select category from tbl
where data_1 is null or data_1 = ''
or data_2 is null or data_2 = '')
```
Fixed using your fiddle! |
16,501,549 | I can setup this listener:
```
$('input[type="text"]').on('keyup paste input change', function() {
console.log('Hello!');
});
```
If I open **DevTools** and do:
```
$('input[type="text"]').val('a new value');
```
None of the events above are called. Which event should I listen for this cases? | 2013/05/11 | [
"https://Stackoverflow.com/questions/16501549",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1641422/"
] | Changing an elements value programatically doesn't trigger an event, you'll have to do that yourself. You could use trigger to trigger event handlers in jQuery :
```
$('input[type="text"]').val('a new value').trigger('change');
``` | The `.val()` function is designed not to trigger events when executed. What I mean by that is even though it could technically have that functionality due to how jQuery works. If you use the `.val()` function you can manually execute the event you would like using `$(element).val("something").click()/change()/input()/k... |
8,017,384 | I'm building a web page form with jquery append() , html() etc and I'm at the point where I have to write the script shown below to the page ( which gets called by some other external include script by ID I think)
What's the best way to write this script to the page or include it so the external calling script can fin... | 2011/11/05 | [
"https://Stackoverflow.com/questions/8017384",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/659196/"
] | Triggers can definitely be a huge problem, especially if there are multiple layers of them. It makes debugging, performance tuning, and understanding the data logic almost impossible.
But if you keep your design to a single layer (a trigger for the table), and it is used soley for auditing (i.e. putting the updated ti... | You can always use a TimeStamp column (in MySql). If it's MSSQL, just note that the timestamp column is a serial number, not a DateTime data type.
Generally, I avoid triggers like the plague (close to on par with cursors) and so always just update the column manually. To me, it helps reinforce the business logic. But ... |
8,017,384 | I'm building a web page form with jquery append() , html() etc and I'm at the point where I have to write the script shown below to the page ( which gets called by some other external include script by ID I think)
What's the best way to write this script to the page or include it so the external calling script can fin... | 2011/11/05 | [
"https://Stackoverflow.com/questions/8017384",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/659196/"
] | You can always use a TimeStamp column (in MySql). If it's MSSQL, just note that the timestamp column is a serial number, not a DateTime data type.
Generally, I avoid triggers like the plague (close to on par with cursors) and so always just update the column manually. To me, it helps reinforce the business logic. But ... | Generally, triggers are most useful as a bottleneck if you have a table that needs certain business logic applied for every update, and you have updates coming from different sources.
For example suppose you have php and python apps that both use the database. You could try and remember to update the python code every... |
8,017,384 | I'm building a web page form with jquery append() , html() etc and I'm at the point where I have to write the script shown below to the page ( which gets called by some other external include script by ID I think)
What's the best way to write this script to the page or include it so the external calling script can fin... | 2011/11/05 | [
"https://Stackoverflow.com/questions/8017384",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/659196/"
] | You can always use a TimeStamp column (in MySql). If it's MSSQL, just note that the timestamp column is a serial number, not a DateTime data type.
Generally, I avoid triggers like the plague (close to on par with cursors) and so always just update the column manually. To me, it helps reinforce the business logic. But ... | Its true that some triggers can often be a source of confusion and frustration when debugging, especially when there are cascading foreign key updates.
But they do have their use.
In this case, you have a choice of updating 400 stored procedures, and updating the date manually. If you miss one of those stored procs,... |
8,017,384 | I'm building a web page form with jquery append() , html() etc and I'm at the point where I have to write the script shown below to the page ( which gets called by some other external include script by ID I think)
What's the best way to write this script to the page or include it so the external calling script can fin... | 2011/11/05 | [
"https://Stackoverflow.com/questions/8017384",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/659196/"
] | Triggers can definitely be a huge problem, especially if there are multiple layers of them. It makes debugging, performance tuning, and understanding the data logic almost impossible.
But if you keep your design to a single layer (a trigger for the table), and it is used soley for auditing (i.e. putting the updated ti... | Generally, triggers are most useful as a bottleneck if you have a table that needs certain business logic applied for every update, and you have updates coming from different sources.
For example suppose you have php and python apps that both use the database. You could try and remember to update the python code every... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.