Handling of generate_series() in queries with date or timestamp with / without time zone

Question: I have a query to generate a report based on a date series that is grouped by date and employee_id. The date should be based on a particular time zone, in this case 'Asia/Kuala_Lumpur'. But this can change depending on where the user's time zone is.

SELECT
     d::date AT TIME ZONE 'Asia/Kuala_Lumpur' AS created_date,
     e.id,
     e.name,
     e.division_id,
     ARRAY_AGG(
       a.id
     ) as rows,
     MIN(a.created_at) FILTER (WHERE a.activity_type = 1) as min_time_in,
     MAX(a.created_at) FILTER (WHERE a.activity_type = 2) as max_time_out,
     ARRAY_AGG(
       CASE
           WHEN a.activity_type = 1
           THEN a.created_at
           ELSE NULL
       END
     ) as check_ins,
     ARRAY_AGG(
       CASE
           WHEN a.activity_type = 2
           THEN a.created_at
           ELSE NULL
       END
     ) as check_outs
FROM    (SELECT MIN(created_at), MAX(created_at) FROM attendance) AS r(startdate,enddate)
  , generate_series(
        startdate::timestamp,
        enddate::timestamp,
        interval '1 day') g(d)
    CROSS JOIN  employee e
    LEFT JOIN   attendance a ON a.created_at::date = d::date AND e.id = a.employee_id
    where d::date = date '2020-11-20' and division_id = 1
GROUP BY
    created_date
  , e.id
  , e.name
  , e.division_id
ORDER BY
    created_date
  , e.id;

Definition and sample data for table attendance:
CREATE TABLE attendance (
    id int,
    employee_id int,
    activity_type int,
    created_at timestamp with time zone NOT NULL
);

INSERT INTO attendance VALUES
( 1, 1, 1,'2020-11-18 07:10:25 +00:00'),
( 2, 2, 1,'2020-11-18 07:30:25 +00:00'),
( 3, 3, 1,'2020-11-18 07:50:25 +00:00'),
( 4, 2, 2,'2020-11-18 19:10:25 +00:00'),
( 5, 3, 2,'2020-11-18 19:22:38 +00:00'),
( 6, 1, 2,'2020-11-18 20:01:05 +00:00'),
( 7, 1, 1,'2020-11-19 07:11:23 +00:00'),
( 8, 1, 2,'2020-11-19 16:21:53 +00:00'), <-- Asia/Kuala_Lumpur +8 should be in 20.11 (refer to the check_outs field in the results output)
( 9, 1, 1,'2020-11-19 19:11:23 +00:00'), <-- Asia/Kuala_Lumpur +8 should be in 20.11 (refer to the check_ins field in the results output)
(10, 1, 2,'2020-11-19 20:21:53 +00:00'), <-- Asia/Kuala_Lumpur +8 should be in 20.11 (refer to the check_outs field in the results output)
(11, 1, 1,'2020-11-20 07:41:38 +00:00'),
(12, 1, 2,'2020-11-20 08:52:01 +00:00');

Here is a fiddle to test.
The query does not include rows 8-10 in the output for the time zone Asia/Kuala_Lumpur +8, though it should. Result shows "rows" field 11,12.
How can I fix the query so that it generates the report based on dates of a given time zone? (Meaning I can change Asia/Kuala_Lumpur to America/New_York etc.)
I was told to do something like this:
where created_at >= timestamp '2020-11-20' AT TIME ZONE 'Asia/Kuala_Lumpur'
and   created_at <  timestamp '2020-11-20' AT TIME ZONE 'Asia/Kuala_Lumpur' + interval '1 day'

But I am not sure how to apply it. Does not seem to work properly in this fiddle. It should include rows 8,9,10,11,12 but only rows 8,9,10 show up.
Comment: What are the column types for the `startdate` and `endate` values; timestamp, timestamptz, something else? What is the server `TimeZone set to? So timestamps are being entered at 'UTC`, correct? Have you tried something like; `startdate::timestamp AT TIME ZONE ' Asia/Kuala_Lumpur' , enddate::timestamp AT TIME ZONE ' Asia/Kuala_Lumpur'`?
Comment: I'ved updated to try in startdate and enddate https://dbfiddle.uk/?rdbms=postgres_13&fiddle=716c719de4c98cfb0598f83d85e37137. created_at timestamp with time zone <-- thats how its defined. the server timezone is "GB", my own server is different timezone. I'd like the query to output according to the desired timezone.
Answer: DB design
Consider some modifications to your setup:
CREATE TABLE employee (
  id           int PRIMARY KEY  -- !
, name         text             -- do NOT use char(n) !
, division_id  int
);

CREATE  TABLE attendance (
  id             int PRIMARY KEY  --!
, employee_id    int NOT NULL REFERENCES employee -- FK!
, activity_type  int
, created_at     timestamptz NOT NULL
);

Defining a PK makes it easier to aggregate rows, because the PK covers the whole row in the GROUP BY clause. See:

Why can't I exclude dependent columns from `GROUP BY` when I aggregate by a key?

I wouldn't use "name" as column name. It's not descriptive. Every other column could be named "name". Consider:

Any downsides of using data type "text" for storing strings?
How to implement a many-to-many relationship in PostgreSQL?

Query
SELECT *
FROM  (        -- complete employee/date grid for division in range
   SELECT g.d::date AS the_date, id AS employee_id, name, division_id
   FROM  (
      SELECT generate_series(MIN(created_at) AT TIME ZONE 'Asia/Kuala_Lumpur'
                           , MAX(created_at) AT TIME ZONE 'Asia/Kuala_Lumpur'
                           , interval '1 day')
      FROM   attendance
      ) g(d)
   CROSS  JOIN employee e
   WHERE  e.division_id = 1
   ) de
LEFT   JOIN (  -- checkins & checkouts per employee/date for division in range
   SELECT employee_id, ts::date AS the_date
        , array_agg(id) as rows
        , min(ts)             FILTER (WHERE activity_type = 1) AS min_check_in
        , max(ts)             FILTER (WHERE activity_type = 2) AS max_check_out
        , array_agg(ts::time) FILTER (WHERE activity_type = 1) AS check_ins
        , array_agg(ts::time) FILTER (WHERE activity_type = 2) AS check_outs
   FROM  (
      SELECT a.id, a.employee_id, a.activity_type, a.created_at AT TIME ZONE 'Asia/Kuala_Lumpur' AS ts  -- convert to timestamp
      FROM   employee   e
      JOIN   attendance a ON a.employee_id = e.id
   -- WHERE  a.created_at >= timestamp '2020-11-20' AT TIME ZONE 'Asia/Kuala_Lumpur' -- "sargable" expressions
   -- AND    a.created_at <  timestamp '2020-11-21' AT TIME ZONE 'Asia/Kuala_Lumpur' -- exclusive upper bound (includes all of 2020-11-20);
      AND    e.division_id = 1
      ORDER  BY a.employee_id, a.created_at, a.activity_type  -- optional to guarantee sorted arrays
   ) sub
   GROUP  BY 1, 2
   ) a USING (the_date, employee_id)
ORDER  BY 1, 2;

db<>fiddle here
Note that my query outputs local date and time for Asia/Kuala_Lumpur:
test=> SELECT timestamptz '2020-11-20 08:52:01 +0' AT TIME ZONE 'Asia/Kuala_Lumpur' AS local_ts;
      local_ts
---------------------
 2020-11-20 16:52:01

Where to start? You need to understand the concepts of time zones and the Postgres data types timestamp with time zone (timestamptz) vs. timestamp without time zone (timestamp). Else, it will be confusion without end. Start here:

Ignoring time zones altogether in Rails and PostgreSQL

Most notably, timestamptz does not store a time zone:

Time zone storage in data type "timestamp with time zone"

When simply casting timestamptz to date or timestamp, the current time zone setting of the session is assumed. Not what you want. Provide a time zone explicitly with the AT TIME ZONE construct to avoid this pifall. In your fiddle you have both:
  ...
  , generate_series(
        startdate::timestamp AT TIME ZONE 'Asia/Kuala_Lumpur',
        enddate::timestamp AT TIME ZONE 'Asia/Kuala_Lumpur',
        interval '1 day') g(d)
   ...

Also not doing what you want. After the (faulty!) cast to timestamp, the AT TIME ZONE construct translates the values back to timestamptz.
Also, your query generates the complete Cartesian Product of all users and and the maximum range of days in the the table attendance, only to reduce it back to a single day with:
    where created_at >= timestamp '2020-11-20' AT TIME ZONE 'Asia/Kuala_Lumpur'
    and   created_at <  timestamp '2020-11-20' AT TIME ZONE 'Asia/Kuala_Lumpur' + interval '1 day'

The WHERE clause finally does what it's supposed to do. But it makes no sense to first generate the full range of days, only to throw away most of it. (Seems you copied that from my other fiddle in the meantime?)
I commented out the WHERE clause and kept an optimized version of your generate_series() in my query as proof of concept. Further reading:

Generating time series between two dates in PostgreSQL
Comment: https://dbfiddle.uk/?rdbms=postgres_13&fiddle=c199f944fd7cc5f51c7fac3d32996ef8 <-- i belive this your db<>fiddle (created_at timestamptz NOT NULL). I cant make that modification as it is live. Can you use the existing db design instead ?
Comment: thanks for the quite elaborate explanation. I cant fundamentally change the DB design (to timestamptz), so I would have to stick to the original definitions. Back to the query, I can get my intended output for 19-20.11.2020 https://dbfiddle.uk/?rdbms=postgres_13&fiddle=96719b3bccfbd4a1b63ab9e38e9821c5. but I still find it weird on the generate_series using dates outside the range 2020-11-20 and 2020-11-21. is this correct ? something looks not right.
Comment: https://dbfiddle.uk/?rdbms=postgres_13&fiddle=60166a27d821b7f58d2cdc02addfa33c this is another I tried -10 UTC with Pacific/Honolulu. 19.11.2020 does not appear
Comment: What do you mean  "change to `timestamptz`"? `changed_at` *is* `timestamptz`, I didn't change that. Also, my `generate_series()` does not use `date` but `timestamp`. Your `generate_series()` in both new fiddles, however, uses `timestamptz`, which makes no sense. The subquery `a` which we join to outputs `timestamp`, not `timestamptz`. Neither does `MIN` or `MAX` make any sense in there.
Comment: Are you aware that `AT TIME ZONE` converts `timestamp` to `timestamptz` and vice versa? Did you read up on the topic like I suggested? You'll have to, or confusion will never end.
Comment: `timestamptz` is a synonym of `timestamp with time zone`. Please read: https://stackoverflow.com/a/9576170/939860
Comment: Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/226018/discussion-between-axil-and-erwin-brandstetter).


MAAS credentials for open stack

Question: I was installing Open-stack on my Ubuntu machine. I have successfully installed MAAS and am able to access the GUI. Everything went well but I am stuck at the point where i have to start installing Autopilot for Openstack. Here I have two issues

sudo openstack-install  does not work but these commands found on Ask Ubuntu got me through:
sudo apt install conjure-up
conjure-up openstack

I could not login into MAAS when I chose to install Autopilot for Openstack. I need help here. I have used the credentials i use to login to MAAS GUI but it gives me this error:

I gave my mass server as http://127.0.0.1/MAAS
and oauth as the MAAS login password.
How to deal with this? is the server name I provided correct? What does "3 items separated by colons" mean? Should I change any text files for login?
Answer: You need to give conjure-up the MAAS API credentials, not your login credentials.
Go to the MAAS GUI (as admin or a regular user), click on your name on the top right, select "account". There you will see "MAAS Keys". If it's empty, just generate one.
That's the text you need to give conjure-up, and is what it means by "3 items separated by colons": it's because the MAAS API key is like text:text:text.

MAAS credentials for open stack


How to make a dependent dropdown list in excel, of a list of variable size

Question: I have 5 separate sheets in excel
number 1 list foods like this:

Food type
Food

Nuts

Hazelnut

Cashew

Walnut

Fruit

Banana

Apple

It allows the user to input foods and divide them by type.
The second sheet is the same but with unhealthy foods.
The third sheet is generated using functions and should not be touched by the user. It looks like this:

Nuts
Hazelnut
Cashew
Walnut

Fruit
Banana
Apple

It lists all food types in the first sheet and then places the foods in that category behind it.
The fourth sheet is the same but for the unhealthy foods.
Sheets 3 and 4 were made using the solutions to this problem
And now to the final sheet. I want to make it a sort of logbook of when I bought which foods. Like this:

Date
Amount
Category
Food type
Food

2023/09/08
5
Healthy
Nuts
Cashew

2023/10/09
2
Healthy
Fruit
Apple

The hard part here is that I want the entries in the last three columns to be options from lists. The category is easy, I have that figured out. But how do I make a list of all food types in the healthy sheet when healthy is selected in the category column, or all unhealthy food types when unhealthy is selected? And then once a food type is selected make a list of all foods that belong to it?
It is important to note that sheets 1 and 2 can be edited over time, sheets 3 and 4 are updated automatically and the dropdown menus of sheet 5 should automatically adapt.
Comment: You might want to look at the choose() function - did something similar with it... Or check this: https://stackoverflow.com/a/64714109/4961700
Answer: STEP 1: Create a named range for the "Healthy" dynamic array on Sheet3. To do this, select the top-left cell of the spilled array, which contains the formula (I'm going to assume it's cell A1), then go to the Formulas Tab on the ribbon and click Define Name. In the Name: field, type Healthy, then in the Refers to: field, add the hashtag symbol (#) to the end of the cell reference =Sheet3!$A$1# and click OK.
STEP 2: Repeat step 1 to create a named range for the "Unhealthy" dynamic array on Sheet4 (Name: Unhealthy, Refers to: =Sheet4!$A$1#).
STEP 3: Create a custom LAMBDA function called "GET.LIST". Again, on the Formulas Tab, click Define Name. In the Name: field, type GET.LIST, but this time in the Refers to: field, copy and paste the following formula, then click OK:
=LAMBDA(category,[food_type],
   LET(
   _list, INDIRECT(category),
   _types, INDEX(_list,,1),
   _items, DROP(_list,,1),
   IF(ISOMITTED(food_type),_types,
      XLOOKUP(food_type,_types,_items))))

STEP 4: Add data validation to the "Food Type" column (D) on Sheet5. To do this, select the range D2:D10 (or however many rows you need), then go the Data Tab on the ribbon and click the Data Validation icon. Under Allow: select List, then for the Source: use the custom function =GET.LIST(C2).
STEP 5: Repeat step 4 to add data validation to the "Food" column (E2:E10) on Sheet5, but this time for the Source: use the custom function =GET.LIST(C2,D2).
NOTE: When you click OK to create the data validation rules, you may be prompted with the following message:

The Source currently evaluates to an error. Do you want to continue?

Click Yes to proceed, and the dependent data validation lists should work as expected (select a category of either "Healthy" or "Unhealthy" in C2 to generate the dependent list in D2, then select an item in D2 to generate the dependent list in E2).


cUrl getting contents of url containing "ü" U+00FC %c3%bc

Question: I am trying to get information about groceries, title, image, price etc.
All other URLs work fine and the cUrl response is exactly as expected.
The problem I am having is when URLs contain accented latin/non-standard url/non-english characters like ü or è.
I've tried everything I can think of, but there is probably a simply solution I am missing:
stringtest.php?url=http://www.sainsburys.co.uk/shop/gb/groceries/desserts/g%C3%BC-lemon-pots-3x45g
stringtest.php?url=http://www.sainsburys.co.uk/shop/gb/groceries/desserts/gü-lemon-pots-3x45g
stringtest.php?url=http%3A%2F%2Fwww.sainsburys.co.uk%2Fshop%2Fgb%2Fgroceries%2Fdesserts%2Fg%C3%BC-lemon-pots-3x45g

This my code for testing cUrl:
<!DOCTYPE html>

    <meta charset="utf-8">

<?php
  $url = $_GET['url'];

  echo curlUrl($url);

  function curlUrl($url){
    $ch = curl_init();
    $timeout = 5;
    $cookie_file = "/tmp/cookie/cookie1.txt";
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    $html = curl_exec($ch);
    curl_close($ch);

    return $html;
  }

?>
  <form action="stringtest.php" method="get" id="process">
    <input type="text" name="url" placeholder="Url" autofocus>
    <input type="submit">
  </form>

The result I get from cUrl is Sainsburys' 404 page claiming the page isn't found.
Copying http://www.sainsburys.co.uk/shop/gb/groceries/desserts/gü-lemon-pots-3x45g from the url bar results in the URL encoded version of ü (%C3%BC) being copied, as expected. When entering the URL in the browser, ü and %C3%BC can both be used to reach the actual product page so why does Sainsburys return a 404 when cUrl'd?
I've tried various things such as urldecode(), using the exact headers the browser uses, but to no avail.
Answer: Seems like an issue with the Sainsbury website itself.
The server returns a 404 when you don't send a valid cookie.
Did you try reloading?
I tried
stringtest.php?url=http://www.sainsburys.co.uk/shop/gb/groceries/desserts/gü-chocolate-ganache-pots-3x45g

and it worked with a valid cookie.
Comment: Thanks for the reply, it responded as expected when I included the cookie information from a browser request. It seems odd that [link](http://www.sainsburys.co.uk/shop/gb/groceries/lamb/sainsburys-lamb-half-leg-%28approx-1kg%29) doesn't require a cookie but URLs like the one in question does!
Answer: If you try:
wget http://www.sainsburys.co.uk/shop/gb/groceries/desserts/g%C3%BC-lemon-pots-3x45g

The response is:
http://www.sainsburys.co.uk/shop/gb/groceries/bakery
Resolving www.sainsburys.co.uk (www.sainsburys.co.uk)... 126.96.36.199
Connecting to www.sainsburys.co.uk (www.sainsburys.co.uk)|188.8.131.52|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://www.sainsburys.co.uk/webapp/wcs/stores/servlet/gb/groceries/bakery?langId=44&storeId=10151&krypto=xbYM3SJja%2F1mDOxJIVlKl9vZN6zjdlTL4MSiHOKiUMQoum9OkLwoTv6wj27CjUXwqM4%2BsteXag0O%0AQOWiHuS8onFdmoVLWlJyZ7hXaMhcMW9MIMMAsnPdWTPEzSEnOP5a&ddkey=http:AjaxAutoCompleteDisplayView [following]
--2014-10-07 11:56:11-- http://www.sainsburys.co.uk/webapp/wcs/stores/servlet/gb/groceries/bakery?langId=44&storeId=10151&krypto=xbYM3SJja%2F1mDOxJIVlKl9vZN6zjdlTL4MSiHOKiUMQoum9OkLwoTv6wj27CjUXwqM4%2BsteXag0O%0AQOWiHuS8onFdmoVLWlJyZ7hXaMhcMW9MIMMAsnPdWTPEzSEnOP5a&ddkey=http:AjaxAutoCompleteDisplayView
Reusing existing connection to www.sainsburys.co.uk:80.
HTTP request sent, awaiting response... 200 OK

To follow the redirect in curl, use the -L flag:
curl -L http://www.sainsburys.co.uk/shop/gb/groceries/desserts/g%C3%BC-lemon-pots-3x45g


Do I need to define huge VPC subnets in order to run many Lambda functions in parallel?

Question: I read that each AWS Lambda invocation gets it's own private IP (when running in VPC).
Does this mean that if I want 50,000 Lambdas running in parallel I need it to run in a VPC subnet with 50,000 available private IPs?
Comment: If you're at the scale of wanting to run 500k Lambda functions simultaneously, I'd expect you to have at least a business-level support relationship with AWS. That would give you access to support engineers who can help you engage the Lambda team. Even if you only subscribe to business-level support for a month in order to work through this challenge, it might be worthwhile.
Comment: Also note that the largest VPC size is /16 which is 65,536 total IPv4 addresses (and you need to subtract 5 reserved addresses).
Comment: Why are you running your Lambda inside VPC?
Comment: To use private resources such as RDS (without the overhead of SSL and firewall)
Answer: Short (updated) answer: No. You do not need a large VPC.
The accepted answer was correct for some time. However back in 2019 AWS changed how Lambdas work within VPCs: https://aws.amazon.com/blogs/compute/announcing-improved-vpc-networking-for-aws-lambda-functions/
Since then each distinct 'subnet + security group' combination now only needs one IP / one ENI within your VPC and that ENI is shared across all execution environments / lambda invocations across all different lambda functions. So even if you have 100 lambda functions within your VPC and 10k concurrent invocations you only need one IP as long as the lambdas are configured similarly.
Answer: Short answer: Yes.
If you want to run 50000 concurrent lambdas inside VPC, you will need more than 50000 IP Addresses as some IP Addresses may not get released right after the end of lambda execution.
There is a soft limit of running 1000 lambdas per account running concurrently. It is a soft limit so you can always submit a ticket and ask AWS to raise it but I doubt they will raise it to 50000.
Update
This is no longer true. Please refer to the answer by @luk2302.
Comment: Can I overcome this limit by not running the lambdas in a VPC?
Comment: 1000 concurrent lambda limitation applies regardless where your lambda is running (Inside or outside VPC). You will need to raise a ticket and ask AWS to raise it.
Comment: The correct answer should be the one below.
Comment: @Asdfg thanks for the update, I am actually quite surprised this was the case once, seems to defeat the purpose and advantages of lambdas in large parts. Nice trip down AWS history lane.


How to add right click format option to a disk icon in the launcher?

Question: How can I add the format option when right clicking in the icon of a disk in the Launcher? Ubuntu 12.04 has this option. How can I make this in Ubuntu 12.10?
Answer: Run sudo apt-get install nautilus-actions
Search nautlilus-actions in the dash
Open it
Enter the information as follows:
Action Tab
Nautilus Item - mark Display Item in selection context menu
Context Label - Format Disk
ToolTip - Format Removable USB & SD Media
Icon - browse to /usr/share/icons/gnome/48x48/apps/file-manager.png and select (this is
just what i used, you may choose something different(
Action Properties - Enabled
Command Tab
Profile - Default Profile
Command - gksudo gnome-format
Parmeters - Blank
Folders Tab
Should already have / listed

Restart your computer
Finally open nautilus and right click any empty space in the directory that you want to format
Select nautilus actions
Select Format Disk
I hope this helps!
Answer: It seems doesn't work easily under Trusty (and new one?) because it uses gnome-format that is no more in default repository, as we can saw at page : https://apps.ubuntu.com/cat/applications/quantal/gnome-format/
I am looking for an other tools in http://packages.ubuntu.com/trusty/utils/ but nothing seems replace it.
nautilusgnome-format


error Unnecessary use of boolean literals in conditional expression no-unneeded-ternary

Question: I am trying this code in atom with ESLint
Code snippet:
$scope.IsVisible = false;
$scope.ShowHide = function () {
  $scope.IsVisible = $scope.IsVisible ? false : true; // error
};

Got this ESLint error:
error Unnecessary use of boolean literals in conditional expression  no-unneeded-ternary
Tried with these solutions solution 1 and solution 2, but error is not fixed. Furthermore, code works fine in editor without ESLint.
Comment: `$scope.IsVisible = !$scope.IsVisible;`
Answer: Try the good way =). No need to use statements in this case.
$scope.IsVisible = !$scope.IsVisible;

Comment: If, like me, you need to check for a `true` value, use the double bang: `!!$scope.IsVisible`
Answer: In my case, I wanted to assign a value to my boolean, according to a variable that was either an object or null.
As kylesimmonds stated, the double bang !! operator can be used.
const myObject: SomeObjectType | null;
...

const isObjectExistent: boolean = !!myObject;
/*
  instead of:
  const isObjectExistent: boolean = myObject? true : false;
*/

Check: What is the !! (not not) operator in JavaScript?


MediaRecorder Chrome Codec/Container not playable on Mobile or Safari

Question: Goal: use MediaRecorder (or else) api to produce video files that are viewable cross platforms.
Fail: current api falls back to container/codec on google chrome which is only viewable on chrome and advanced desktop media players but not on Safari or mobile devices.
! Same code when running on safari generates a working video file on all platforms.
    const mimeType = 'video/webm;codecs=H264'
    rec = new MediaRecorder(stream.current, { mimeType })
    rec.ondataavailable = e => blobs.push(e.data)
    rec.onstop = async () => {
      saveToFile(new Blob(blobs, { type: mimeType }))
    }

Tried all different combinations of containers and codecs.
also tried to override the mimeType of the Blob with MP4 file container.
No success what so ever.
also tried:
https://github.com/streamproc/MediaStreamRecorder
https://github.com/muaz-khan/RecordRTC
Same issues. iI seems like chrome's container/codec combinations always fall back to a format that is only viewable out of the box on chrome or a powerful desktop video player like vlc.

The only cross platform working example for me is the one taken from safari browser and is the 5th from left in the picture above.
The Question:
Edit -
(We don't allow questions seeking recommendations for books, tools, software libraries, and more. Edit the question so it can be answered with facts and citations)
What is the correct container/codac to be used in MediaCapture api to make the output file playable cross platform.
Answer: We have the same issue. We have tried many different combinations but always it fallbacks to matroska
Comment: Did you find an answer to this?  I have the same issue making videos with mediarecorder have cross browser support.  I did notice firefox have fixed the metadata issue and works fine.  However, chromium browsers are still an issue.  We've tried ts-ebml.js which injects the metadata and makes video seekable in the browsers, however as soon as you download it and play with a the windows native player it plays fine until you touch the seek handle. Then you get error: 0xc00d3e8c which suggests the video is still malformed.


Assigning variable of Class<> Type implementing an interface in Java

Question: I want to create a variable of type Class, which implements some interface.
Like:
Class<List<String>> b = ArrayList.class;

But when i try something like this, it complains about incompatible types, since the generics is filled with the concrete class.
Is there a way to do this?
I want to do this to be type safe further down the road. I know that it will work when i don't care about type safety, but if i could, I would rather do it in a type safe manner.
Comment: The best I can do is `Class b = ArrayList.class;`
Comment: The moment you start using reflection to construct generic instances, there is no more type safety.
Comment: Can you elaborate a bit on in what circumstances you might need the Class variable? I cannot imagine a type safety case that requires that.
Comment: I think you can't get the variable of type class which implements your interface.
Comment: @aviad I will use this class for calling a Builder that is based on reflection. It is a generic builder that accepts any implementation of an interface. In the start method it gets the class, fills some data and then calls the constructor via reflection on the class.
Comment: @Xtroce try to use Visitor pattern. https://sourcemaking.com/design_patterns/visitor
Answer: You can actually use Class<List<String>> b = (Class)ArrayList.class;. It compiles, doesn't throw an exception and gives type safety.
The reason you can't just use Class<List<String>> b = ArrayList.class; is because ArrayList.class isn't a Class<List<String>> type, but rather a primitive class type. Casting it to Class removes the primitive and wildcard.
Answer: You get a type error here Class<List<String>> b = ArrayList.class; 'couse ArrayList.class is not Class>. Why? Let's see, Think about lists, in their implementatios they look like
public interface List<T> ...

So, when you create a List, you MUST tell her wich is his type inside, for example:
List<String> list1;
List<Integer> list2;

the original error is similar to:
List<String> list1 = new String("Hi");
List<Integer> list2 = new Integer(5);

The correct way, is telling both types, that creates a new concrete type:
List<String> list1 = new ArrayList<String>();
List<Integer> list2 = new ArrayList<Integer>();

list1 and list2, don't have the same type, although they both are List.
Finally, for your class "Class", the correct way is to do something like this:
import java.util.ArrayList;
import java.util.List;

public class Class<T> {

    private T v;

    public Class(T t){
        this.v = t;
    }

    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        Class<List<String>> a = new Class<List<String>>(list);
    }

}


Why does the CPU load dropped in the last days?

Question:
Anybody has a hint? I didn't change anything in the machine (except for the security updates), and the sites hosted there didn't suffer a significant change in connections.
May be Google changed something in their infrastructure? Coincidentally, it was an issue with the Cloud DNS ManagedZone these days: they charged me with $ 920 for half month usage, and it was an error (they counted thousands of weeks of usage too) so they recently changed back to $ 0,28. May be there was some process that indeed used the Cloud DNS by error and thus consumed CPU power, and they corrected now?
I wish to know what is happening from someone that knows what going on in GC. Thank you.
Comment: Did the security updates coincide with the start of lower CPU usage? Suspect the DNS charges are a simple billing error, not an indication of more DNS activity.
Comment: Well, actually, not. There was no security updates before the lowering. Nobody else has seen something like that in their Compute Engine?
Comment: Mine is a g1-small instance with 1 shared CPU (Intel Haswell) and 1.7 GB of RAM
Answer: CPU utilization reporting is now more accurate from a VM guest perspective as it doesn't include virtualization layer overhead anymore. It has nothing to do with Cloud DNS.
See this issue for some extra context:
https://code.google.com/p/google-compute-engine/issues/detail?id=281
Comment: Thank you. That's the explanation I was looking for. I think that Google should have explained that to everyone. I had no clue about what's going on. I don't understand why someone has downvoted ny question.


PDF scraping using R

Question: I have been using the XML package successfully for extracting HTML tables but want to extend to PDF's. From previous questions it does not appear that there is a simple R solution but wondered if there had been any recent developments
Failing that, is there some way in Python (in which I am a complete Novice) to  obtain
and manipulate pdfs so that I could finish the job off with the R XML package
Answer: Extracting text from PDFs is hard, and nearly always requires lots of care.
I'd start with the command line tools such as pdftotext and see what they spit out. The problem is that PDFs can store the text in any order, can use awkward font encodings, and can do things like use ligature characters (the joined up 'ff' and 'ij' that you see in proper typesetting) to throw you.
pdftotext is installable on any Linux system...
Comment: Running pdftotext isn't brilliant on that page, but converting to ps first or just running ps2txt on the PDF produces an almost perfect table with some page heads/foots to remove.
Comment: Seconded.  Doing it in R isn't worth the effort of anyone to develop and maintain, when there are options that are far better maintained outside of R.  If you need to do a lot of files, try using the `find` utility in Unix (or in the GNU collection for Windows), or one can have R send commands to the shell, looping over filenames...  Even Adobe had a terrible text extractor for a long time (not sure if it's better now), while Xerox had a good one.
Comment: Well pdftotext works fine in producing a clean text page but its not in any sort of form to easily create what i want. Thanks anyways
Answer: Your might want to check out the text mining package tm. I recall that they implemented so called readers, and there also was one for PDFs.
Answer: AFAIK there isn't an easy way of turning PDF tables into something useful for data analysis.  You can use the Data Science Toolkit's File to Text utility (R interface via the RDSTK package), then parse the resulting text.  Be warned: the parsing is often non-trivial.

EDIT: There's a useful discussion of converting PDFs to XML on discerning.com.  The short answer is that you will probably need to buy a commercial tool.
Comment: +1 Thanks for that. i checked the discussion and tried downloading the ABBYY product on trial but it would not set-up proprrly. Guess I'm doomed
Answer: The heart of the tabula application that can extract tables from PDF documents is available as a simple command line Java application, tabula-extractor.
This Java app has been wrapped in R by the tabulizer package. Pass it the path to a PDF file and it will try to extract data tables for you and return them as data.
For an example, see When Documents Become Databases – Tabulizer R Wrapper for Tabula PDF Table Extractor.

PDF scraping using R


cpp declaration of string with a char

Question: I am referring to this post on how to create a string from a char in cpp.
Convert a single character to a string?
c is a charactor and inputstr is a vector of strings.
As stated, if I do this
string str2(1,c);
inputstr.push_back(str2);

it works and inputstr gets a str append to the end but not when I do
inputstr.push_back(string str2(1,c));

It throws an error: expected primary-expression before 'strx'
     inputstr.push_back(string strx(1,c));
What does the error mean? is it because cpp does not support in line declaration, I would expect a different error in that case.
Comment: You want `inputstr.push_back(string(1,c));`.
Comment: The error means that this is not valid C++.
Answer: But,
inputstr.push_back(string(1, c));

should work.
In your example, you are attempting to declare a variable in an invalid place and that is not valid code, so the compilation fails. In this example, you are simply instantiating a string object and passing the instance to push_back(). You don't need the variable in this case.

cpp declaration of string with a char


Javascript : issues with Promise.all and json() being logged as "not a function"

Question: I'm having some issues with the "Promise.all" method.
Bascially, I have an array of URL (here is a simple one if you guys want to test :
const urlArray = [
  "https://coverartarchive.org/release/985adeec-a1fd-4e79-899d-10c54b6af299",
  "https://coverartarchive.org/release/4c54ee58-86df-3ba5-aaad-6b284293141b",
  "https://coverartarchive.org/release/cd8e5736-ec8c-3c4d-a231-ac097877d87a",
  "https://coverartarchive.org/release/b9b7641f-9389-342e-8be9-e463bd52fdb9",
  "https://coverartarchive.org/release/b6206cad-15eb-3a95-b67e-1f49849e5fbd",
  "https://coverartarchive.org/release/db425753-965f-4881-955b-8cd3ef65d1e6",
  "https://coverartarchive.org/release/fa4f230a-e78c-32a8-bec8-3a7425aba9d2",
  "https://coverartarchive.org/release/fa023617-1585-4ae6-81b6-1a07c47ecb2a",
  "https://coverartarchive.org/release/61782e1c-67a2-487c-8324-6431c628cad8",
  "https://coverartarchive.org/release/b16e94f3-ad3b-4e3b-9fad-0ef3d2a0958e",
  "https://coverartarchive.org/release/37e7091f-9ebc-4ac8-875b-5c88f7e5fba8",
  "https://coverartarchive.org/release/a63b6cc9-899c-447d-b0e6-d1e439379eb2",
  "https://coverartarchive.org/release/d2d3df43-65c4-499e-90d2-22a157cc7dea",
  "https://coverartarchive.org/release/9cb95cac-4a0d-4fbb-9237-544a99f29b57",
  "https://coverartarchive.org/release/7cf87b52-47e3-4d12-8890-53a910792b70"
]

Normally, when a promise is resolved, it should return a JSON object, has seen when you enter one of those URLs above in your browser with infos about cover arts for an album release.
So I have tried using Promise.all using this array and see what goes, but I simply can't get something to work : the json() method. I have tried several ways to handle this, found on stackoverflow or elsewhere on the internet, I just always get the "Uncaught (in promise) TypeError: response.json is not a function"
Here are several things I tried :
  Promise.all(urlArray)
    .then(toJSON)
    .then((jsonObjects) => console.log(jsonObjects));

  function toJSON(responses) {
    if (!Array.isArray(responses)) {
      // also handle the non array case
      responses = [responses];
    }

    return Promise.all(responses.map((response) => response.json()));
  }

Same thing I guess but without helper
    Promise.all(urlArray)
      .then((res) => {
        const responses = res.map((response) => response.json());
        return Promise.all(responses);
      })
      .then((data) => console.log(data));

The worst thing is, I did manage to do it a few days ago, then changed my mind about how to go with this, and I just can't find how I solved this the first time around. If you guys have any idea what I'm doing wrong, don't hesitate to point it out and scold me about it !
Cheers
Comment: You are passing an array carrying URLs to the static method Promise.all. instead you should have passed array of promise objects. I think you missed the part of making ajax call. You should do something like Promis.all(urlArray.map((url)=>makeAjaxAndReturnPromise(url))) and implement your makeAjaxAndReturnPromise
Answer: Your urlArray is an array of plain strings, not an array of requests. You never actually make any network requests in your code - you don't have any Promises.
Map the array of request URLs to an array of Promises first.

const urlArray = [
  "https://coverartarchive.org/release/985adeec-a1fd-4e79-899d-10c54b6af299",
  "https://coverartarchive.org/release/4c54ee58-86df-3ba5-aaad-6b284293141b",
  "https://coverartarchive.org/release/cd8e5736-ec8c-3c4d-a231-ac097877d87a",
  "https://coverartarchive.org/release/b9b7641f-9389-342e-8be9-e463bd52fdb9",
  "https://coverartarchive.org/release/b6206cad-15eb-3a95-b67e-1f49849e5fbd",
  "https://coverartarchive.org/release/db425753-965f-4881-955b-8cd3ef65d1e6",
  "https://coverartarchive.org/release/fa4f230a-e78c-32a8-bec8-3a7425aba9d2",
  "https://coverartarchive.org/release/fa023617-1585-4ae6-81b6-1a07c47ecb2a",
  "https://coverartarchive.org/release/61782e1c-67a2-487c-8324-6431c628cad8",
  "https://coverartarchive.org/release/b16e94f3-ad3b-4e3b-9fad-0ef3d2a0958e",
  "https://coverartarchive.org/release/37e7091f-9ebc-4ac8-875b-5c88f7e5fba8",
  "https://coverartarchive.org/release/a63b6cc9-899c-447d-b0e6-d1e439379eb2",
  "https://coverartarchive.org/release/d2d3df43-65c4-499e-90d2-22a157cc7dea",
  "https://coverartarchive.org/release/9cb95cac-4a0d-4fbb-9237-544a99f29b57",
  "https://coverartarchive.org/release/7cf87b52-47e3-4d12-8890-53a910792b70"
]

Promise.all(
  urlArray.map(
    url => fetch(url).then(res => res.json())
  )
)
  .then((results) => {
    console.log('got all results');
    // use results here
  });


R302.7 Under-Stair Protection - does drywall need to be below stringers or just treads and risers?

Question: I am finishing a room in my basement, and a wall will butt up against where the stairs are. I'm planning on making a small door to access the volume below the stairs for a small storage area.
The building inspector said I needed to put drywall below the stairs for fire protection.
The stairs have a middle string. If I place the drywall over the stringer, that will significantly reduce the available volume.
Can I fulfill this requirement by putting two tightly fitting drywall panels in the spaces between the stringers, leaving the middle stringer exposed?
Text of relevant ICC code:

R302.7 Under-Stair Protection
Enclosed accessible space under stairs shall have walls, under-stair
  surface and any soffits protected on the enclosed side with 1/2-inch
  (12.7 mm) gypsum board.

Otherwise, simply "coating" the middle stringer would be a compliant alternative to maximize accessible volume, would it not?
Here are some pictures from under the stairs. The difference between the plane of the bottom of the stringers vs the bottoms of the treads and risers is a significant amount of space to store stuff.
Answer: No, you can't leave the center stringer exposed. That would leave a path for fire through the drywall. You must create a continuous break, with all seams taped.
I can't see an inspector flagging either of your other ideas, but you should probably just ask first. You don't want to do the job twice.
Comment: Key terms are "surface" and "protected" - he would be in compliance if he cut several pieces and properly attached/beaded/taped/finished every single one. Silly, but I've seen stranger - kind of a waste of effort for such an insignificant space IMHO. I had a basement from 1994-2009; you put stuff under the stairs that you plan to never see again, maybe get out once a year, and want to increase the chances that it get invaded by critters, mold, and mother nature. 3 pieces minimum and done. This is a hoarders quest...
Answer: One possible solution--not ideal-- may be to put the drywall on the bottom of the treads and backs of the risers. Would this be approved by the inspector? (The spec is not clear). However, it is not a good solution because the flex in the stairs will cause any drywall mud to crack over time--but perhaps you could just use corner-mold to cover the drywall seams. You'd still lose some space, but not as much as covering the entire bottom of the stairs...and you wouldn't have to spackle anything.
Answer: If you noticed, Section 302.7 is a sub-section (and only applies to) Section 302: Fire Resistant Construction.
Therefore, you first need to determine if the stair needs to be "fire resistant". It only needs to be "fire resistant " and have the 1/2" gypsum board, if 1) the stair is exterior AND falls within the fire separation distance between buildings, or 2) required egress located in garages next to the residence, or 3) required egress from townhouse unit.
I doubt if your stair meets these requirements and needs to be "fire resistant" with 1/2" gypsum board.
There is also an exception for all three conditions if the house has fire sprinklers.
Also, if the Building Official determines that you meet one of the requirements, you do not need to cover the stringers if they are solid sawn and a minimum size of 4x6's. (This is called "Heavy Timber construction". See Table 602.1)
In summary:
You may enclose the underside of the stair without 1/2" gypsum board, unless it needs to be fire resistant construction.
Comment: Perhaps there is a different relevant section than R302.7 than I cited, but the building inspector specifically mentioned I have to do the fire protection. I've tried to ask him what to do but he's on vacation now.  The exceptions you mentioned don't apply unfortunately.
Comment: @whatsisname There is only one required fire resistive construction system required in a "single family residence", on the INTERIOR of the house: and that is the wall between the garage and interior living spaces. First, remember the Building Official wants to get everything correct too. Second, there is a clause in the code that allows the Building Official to require anything. He can require you spread peanut butter on the walls. There is an appeal process, and he'd loose that argument...and Building Officials don't like to be appealed. Third, perhaps he sees that there is only...
Comment: there is only one way in-and-out of the basement (the stairs) because you do not have an exit door (a sliding glass door is not considered an exit door) AND there are no bedroom egress windows. So, in his mind he thinks someone could store matches and firecrackers under the stair leading to a hazardous and dangerous situation. (Don't scoff...I've heard worse.) If however, you have another emergency exit, I'd gently ask him to cite a reference for the 1/2" gypsum board. Now, the reason you're asking for the reference is so you can get it right. (Don't be a wise guy.) The reason you need to...
Comment: The reason you need to know is so you can get the nailing correct. Ask what the size AND spacing of nail is required into the bottom of the treads and risers. (There is none specified in the Code...or anywhere.) Act dumb and let him know you want to nail it correctly into the treads and risers. (Oops...Edit: a slider can be used as an emergency exit out of a basement.) Finally, the Code allows "Alternative Design". If he still wants the gypsum board, suggest you provide a smoke detector at the top of the stair instead. This is considered "early warning" which is better than "fire protection".
Comment: Getting into an argument with the inspector and having to go through an approval process is not even remotely worth the hassle, even if I was guaranteed to prevail. The area will have flammable materials in it, I don't think it's unreasonable to meet the requirement, I just want to try to optimize available space.
Comment: @whatsisname "Arguing with the inspector...approval process...worth the hassle..."???  Where did that come from? I'm talking about asking a pointed question so they drop the unsubstantiated requirement. If you think the requirement is so "reasonable", why ask Stack Exchange for assistance?


Does a conduit running through a ceiling need to be supported?

Question: I will be running wire through a basement ceiling (not a drop ceiling) and I would like to avoid cutting holes in the drywall. I know that the wire on its own would need to be supported and secured to the joists. However, if the wire is running through a conduit, does the conduit need supporting or can it rest on the ceiling?
Comment: In short, you don't need the conduit, and adding conduit probably makes support required.
Answer: A wire is generally not acceptable, period (exception might be a grounding wire as a lone wire.)
A cable (several wires in one outer jacket, such as NM/B aka "Romex® - a brand name) is NOT required to be attached where it cannot be accessed if it's a retrofit into an existing space, (apparently the case here) generally.
Conduit is required for protection of wires and IS required to be attached. There MIGHT be a pass for flexible conduit to be treated like cable for a retrofit, I'm not sure. There is for AC & MC cables, but not finding anything for flex conduit, even though it's very similar to AC & MC cables.
Comment: See https://diy.stackexchange.com/a/108789/18078 and https://diy.stackexchange.com/a/140413/18078 and https://diy.stackexchange.com/a/215342/18078


How to efficiently check different date formats when converting month to number

Question: I'm trying to convert a given month to a month number in integer format. There are three valid formats that I want to try to convert. A month number that's given as a string (input function returns a string), a month abbreviation, and a full month name.
While my function works as intended I feel like it's not that well written, despite my attempts to make it as clean as possible. In particular, I'm not happy that I have an except statement that just passes. Handling both a string conversion to an integer AND checking to see if the string is a valid month to convert to an integer was a tough task.
I tried to change the order of the try-excepts, removing the string-to-int to make it's on try-except block without going straight into the date formatting in the exception but that's about it. The function below is the best attempt I've had. I couldn't think of anything else except maybe create helper functions?
Code
def get_start_month_updated():
    date_formats = ['%b', '%B']
    while True:
        month = input("What is the starting month?")
        try:
            month_num = int(month)
            if 1 <= month_num <= 12:
                return month_num
        except ValueError:
            for date_format in date_formats:
                try:
                    month_num = strptime(month, date_format).tm_mon
                    return month_num
                except ValueError:
                    pass
            else:
                print("You must enter a valid month")
        else:
            print("You must enter a valid month")

My results are correct and the function works as intended, but I feel like the code is messy and there is a better way to do this without getting really convoluted.
Comment: `while True` is wrong approach for the vast majority of cases, including yours. Yes, helper function: this main function should consist solely of input line and `return get_int_month(month)`.
Comment: How do I prompt the user for the correct value without a ```While True``` loop? If the input is not valid, the user should be asked for a new input until a correct one is given
Comment: Ok then, three lines: `value = get_int_month(month); return value if value else get_start_month_updated()`
Comment: So use recursion instead? What's the benefit of using recursion over a while loop in this case? I thought using While loops are fine as long as you make sure you aren't stuck in an infinite loop.
Comment: First of all, everything is fine: pythonic is utopia. I just don't like `while True` out of gui's main loop. It's not really a recursion, it's a call to a mandatory task that has not been finished yet.
Comment: Ah okay! Just for a bit of context, this particular block of code isn't in the main loop, it's just to get this particular input out of many. If you don't mind me asking, why do you prefer not using a ```while True loop``` as opposed a function call?

I'm just wondering since in your first comment you stated "```while True``` is wrong approach for the vast majority of cases, including yours." Just wondering the rational.
Comment: Afaic `while True` should be used only for a GUI main loop, as that's reasonable approach for listening to finite, but unpredictable, number of events. You're listening/expecting a sole event and that's the reason why I think an infinite loop should be avoided.
Answer: First, you should create a parse_month function for better testing.
This parse_month function can have several internal parsers, one for each format: "int", datetime with "%b", datetime with "%B". This is implementation detail.
One way to do that could be:
import datetime
import functools

def parse_month(value):
    def from_int(v):
        month_num = int(v)
        if 1 <= month_num <= 12:
            return month_num
        raise ValueError(v)

    def from_month_fmt(fmt, v):
        return datetime.datetime.strptime(v, fmt).month

    parsers = (
        from_int,
        functools.partial(from_month_fmt, "%b"),
        functools.partial(from_month_fmt, "%B"),
    )
    for parser in parsers:
        try:
            return parser(value)
        except ValueError:
            pass
    else:
        raise ValueError(value)

Then, you can use this function to prompt the user:
def get_start_month_updated():
    while True:
        month = input("What is the starting month?")
        try:
            month_num = parse_month(month)
        except ValueError:
            print("You must enter a valid month")
        else:
            return month_num

If you don't want to reinvent the wheel, Arrow is your friend:
import arrow

def parse_month(value):
    formats = (
        "MMMM",
        "MMM",
        "MM",
        "M"
    )
    for fmt in formats:
        try:
            return arrow.get(value, fmt).month
        except arrow.parser.ParserError:
            pass
    else:
        raise ValueError(value)

Comment: Is there no way to check for a valid conversion without having ```except ValueError: pass```? Or is this one of those cases that it's acceptable because you raise the value later if no value is valid. I Thought it was generally bad form to have a try-except statement where the exception is handled with just pass.
Comment: Both suggestions work! I especially really like the arrow module! Thanks for showing me that, I'm definitely going to read into it more, seems very useful
Comment: Using `except ValueError: pass` is not bad, it's the "EAFP" (Easier to ask for forgiveness than permission) principal. Instead of that, you can use a RegEx to match the input value and then a parser to convert the value. But, here, this is not appropriate.


What strings satisfy regex: (^$)|(^.*\{count\}.*$)

Question: AWS ElasticTranscoder needs thumbnails to satisfy (^$)|(^.{count}.$).
What strings would satisfy this regex requirement?
Answer:
An empty string
A string containing the string {count}

^ means the beginning of the string, and $ means the end. . matches any single character, and * means match 0 or more times. | is the "or" operator and (/) work how you would expect in this case. \ means the next character is literal.
So, ^$ is an empty string, and ^.*\{count\}.*$ means any text, followed by {count}, followed by any text.
Answer: The following strings will satisfy the regex:

Empty strings (will match ^$)
Strings that contain the substring {count} at any location (will match ^.*\{count\}.*$)


Electron with imports (polymer)

Question: I'm trying to create an electron app with polymer. I tried to import a custom element using
<link rel="import" href="src/lux-app.html">

but it dosen't work. Console says:
GET file:///D:/src/lux-app.html net::ERR_FILE_NOT_FOUND

It does not use the correct path. I researched and found that imports only work when they are on a server (e.g. localhost). Is there a way to run localhost in electron or something like that?
Thank you
Edit:
Here is the file structure
lux-app
   |── bower_components
   |── images
   |── lib
       └── artnet.js
   |── lux-app.html
   |── .gitignore
   |── bower.json
   |── ...
node_modules
   └── node stuff
main.js
index.html
polymer.json
package.json
README.json
renderer.js

Answer: Imports work without "localhost", as i see in "Electron Api demos". In the index.html file,  there are some imports like these:
<link rel="import" href="sections/about.html">
<link rel="import" href="sections/windows/windows.html">
<link rel="import" href="sections/windows/crash-hang.html">
<link rel="import" href="sections/menus/menus.html">

So i think your problem is that the path variable in the main renderer (main.js) don't work properly, or if you haven't declared that variable, you need to with const path = require('path') and use the path as in the main.js file in the Electron Api demos.
(I'm not an expert with electron, but i think I can get you oriented to the solution looking inside the files in electron api repo)
Comment: It worked, but I had to remove  and . Thanks a lot!

Electron with imports (polymer)


Views disappear when `translatesAutoresizingMaskIntoConstraints` set `NO`

Question: Problem
Some third party library is used. Some views disappear after their translatesAutoresizingMaskIntoConstraints are set to NO.
Don't have other autoresizingMask setting for my views in my own code; in the library, the autoresizingMask parts of code have been removed too. Instead, explicit bounds/center/frame are set for those views. There're no nib files, views are all programmatically created.
I know some other people solve similar problem by giving a thorough autolayout constraints set, but in my case, I mean to turn off autolayout and do it manually. No idea when autolayout is turned on.
Some people say that "by default, as your app launches, autolayout is switched off, and the system behaves as in iOS 5 and before. But if, at any time while your app runs, the system sees an autolayout constraint (generated in code or by the loading of a nib that has "Use autolayout" checked), the autolayout system is switched on, and from then on you're running under autolayout." (Programming iOS 6 by Matt Neuberg, pages 383-384), but in my project I don't think there's any autolayout constraints left.
The code is bulky, but will upload some skeleton if necessary.
Thank you for tips!
Answer: If you don't want to use Auto Layout you have to set translatesAutoresizingMaskIntoConstraints to YES. Here's a reference:

This works through the property
  translatesAutoresizingMaskIntoConstraints. When this property is YES,
  which it is by default, the autoresizing mask of a view is translated
  into constraints. For example, if a view is configured as in Figure
  6-1 and translatesAutoresizingMaskIntoConstraints is YES, then the
  constraints |-20-[button]-20-| and V:|-20-[button(20)] are added to
  the view's superview. The net effect is that unaware views behave as
  they did in versions of OS X prior to 10.7.
For views that are aware of Auto Layout, in most circumstances you
  will want translatesAutoresizingMaskIntoConstraints to be NO. This is
  because the constraints generated by translating the autoresizing mask
  are already sufficient to completely specify the frame of a view given
  its superview's frame, which is generally too much. For example, this
  will prevent a button from automatically assuming its optimal width
  when its title is changed.
Comment: The reference link expires, @ArkadiuszHolko, can you renew it?
Comment: @congliu: Fixed. Apple must have changed it yesterday.
Comment: Hi @ArkadiuszHolko, why we have to set translatesAutoresizingMaskIntoConstraints to YES when not using Auto Layout? In my understanding, because we don't use Auto Layout, then then we don't need any constraints. So we don't need to set translatesAutoresizingMaskIntoConstraints to YES.
Comment: @congliu: From what I understood at the time you tried to disable Auto Layout by setting `translatesAutoresizingMaskIntoConstraints` to `NO`, where you should use `YES`. `translatesAutoresizingMaskIntoConstraints` is set to `YES` by default, so you generally don't have to set it explicitly.


Is it possible to determine someones league while playing against them?

Question: Is is in any way possible to determine if my opponent is in a higher/lower or same league as myself while I'm actually playing against them in 1vs1 in starcraft 2, or am I forced to check this after the match is over?
Answer:

Here is a picture of the only way I know of determining what rank your opponent is before the game starts. Keep an eye out for the color of the boarder around your opponents unit portrait during the vs loading screen before the game starts.
http://wiki.teamliquid.net/starcraft2/index.php?title=File:Portrait_Borders.jpg&filetimestamp=20140322032611&
Answer: In theory if you had a person's user name and number, you could look them up (on the blizzard website).  Unfortunately those numbers are hidden by default so unless you get your opponent to give you his number, I don't see how.
Ultimately I tend to ask my opponents, and I find this works well.  I can probably trust their answers about as well as I can trust them to give their hidden number.
More often than not, I can tell a person's league just by scouting:

If they have a lot of workers and are using a known build: probably plat/diamond
If they are doing something weird, or I find a proxy blank, probably gold.
If they don't have more than 13 workers, definitely silver or lower.

These rules aren't hard and fast, but they do tend to explain 90% of my games.
If I'm getting 4 Gate timing push at 6:30 you can bet the guy is in diamond.
Where this breaks down is when you start to get top 10 diamond and then start seeing things like: bunker push, 2 pylon wall in.  And all of a sudden I start sweating...
Comment: What league are you tze?
Comment: @Juan here or on KR?  My usual policy on a ladder reset is to throw my placement games and work my way up the ladder so I get a good cross section of strategies.  The match maker is fairly digressive so usually I quickly end up against Diamond level players.  So while the answer to your question is (usually): Diamond US and Gold KR, that doesn't give you an indication of my skill.  To reference ICCUP rankings I'm probably a C- as zerg, D+ as Terran/Toss... actually that might be generous.
Comment: 'here' is relative, but that answers my curiosity-question :) -- I hadn't thought about *trying* to rank low, it should be fun; the practice matches are absolute fun because both players are inexperienced (in case it wasn't obvious, I just started and I don't have a lot of time to play, so I'm still having fun there).
Comment: @Juan sorry, I live in NA, so "here" means NA to me.  I spent a lot of time trying to figure out the algorithm for advancing from league to league and I intentionally threw games to help with it.  So far the only thing I can verify is that you need some number of losses before it will consider you for moving up (and some number of total games).
Comment: Did you mean moving down? Because that was my next question, suppose you rank high by mere chance, but you lose a lot of matches, how long until it lowers you to a more suitable league?
Comment: Looking them up using their ingame name here is not good enough/reliable? http://sc2ranks.com/
Comment: @PeterK it's semi-reliable if they don't have a common name.  Of course unless you're having someone else look it up it seems like it would be too much of a distraction to alt-tab back and forth between building and looking up.  But maybe that's cause my APM's below 50 :p
Comment: @Juan nope, I mean moving up.  To move up a league you must have a minimum number of losses.  There is also a minimum number of games.
Comment: has that "minimum number of losses" thing been confirmed? I moved up to gold at the end of a 10 game winning streak.
Comment: also, back when i was in silver, several people lied to me about what league they were in, so certainly don't adjust your strategy/paranoia level based on what they say!
Comment: @Peter there is both a minimum number of losses, and minimum number of games.  As a result you can move up on a win, but unless you have enough losses you won't move up.  There were some rather extreme examples of this where players had 60+ wins and less than 7 losses.
Comment: hah! that must have been frustrating...
Comment: @Peter: It's never good to adjust your strategy to anything you haven't scouted in-game (though it's ok to add your off-game knowledge). I can't remember who it was, but in a tournament in the beta some pro played against IdrA, thinking IdrA would go roaches... and got seriously beaten by hydras. Don't assume - scout.
Comment: @Dbemerlin I'll do you one better.  In GSL IdrA went against LotzePrime.  Now the openings for your games are public on the Bnet so if you know your opponent you can practice against their BO.  So IdrA knew Lotze's BO and beat him easily in G1.  Artosis was bragging about this on the stream.  Someone told Lotze and for G2 he did proxy Void Ray.  Now IdrA was so sure Lotze was going his standard 3 Gate/Colossus, that he didn't even scout him. Instead he went 14 hatch/15 pool.  By the time Lotze Void Rays showed up IdrA had only 2 queens and tapped out.
Comment: If you want to, you can watch game 1 here: http://www.gomtv.net/2010gslopens1/vod/1055  You'll see Artosis talking about checking out BOs.  Sadly Game 2 isn't up for free.
Comment: What do you mean by "find a proxy blank"?
Comment: @Jed Proxy Barracks, Proxy DT Shrine, Proxy Hatch, etc
Comment: @tzenes Ok, thanks, that makes more sense. I thought you were saying something about an empty proxy. You might want to say "any type of proxy" instead, to make it more clear.


Querying in MongoDB Compass

Question: Just a quick question I hope someone can answer for me.
I have a collection in MongoDB containing 84 thousand documents. The data looks something like this:

There are several thousand documents containing the word "BOND" as the category name such as this:

And many thousands more...
Currently in MongoDB Compass I am using the following query:
<code>{ "Category" : "BOND" }
</code>
But of course this just returns 1 document that where the Category is BOND.
Can anybody tell me how I can query to find all documents where the field name "Category" contains the word "BOND" within it?
Many thanks,
G
Comment: BTW, This question is surprisingly popular, may be you consider changing its title? Something like "Query by substring in MongoDB" or so?
Answer: You should use regexp for this, i.e.
<code>{ "Category" : /^BOND.*/ }
</code>
for categories begins with BOND, or
<code>{ "Category" : /.*BOND.*/ }
</code>
for categories contains BOND within
Comment: @vibs2006 You can read complete documentation on mongo's $regex here - https://docs.mongodb.com/manual/reference/operator/query/regex/  For case insensitivity you can query your collection like { "Category" : /^BOND.*/i } (note i after closing /)
Comment: What if i want to search all the documents from the data in a file. (for the above example)say a file containing a list of oSum values, and i want all the documents matching the those oSum
Comment: @Alexey-Sviridov what can we do for case sensitivity as that is not working ?
Comment: @ParasSingh I guess you should import your file into a separate collection and then use aggregation with $lookup statement ( see here about $lookup https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/ )
Answer: It should be something like this {'category': /BON?/ }

Querying in MongoDB Compass


Why would the documentation say to wire a pole of the 3-way occupancy switch to ground?

Question: I'm currently wiring up an occupancy sensor to a 3-way switch, I'm leaving one of the mechanical switches in place, and here is the wiring instructions.
according to the instructions I need to wire one of the poles on the second switch to ground (fig 5). I've never seen this before, is it safe to do? Do I wire that pole and the ground nut together to go to ground?
Comment: That does seem odd, I wonder why they didn't suggest wiring it to Neutral, which should be identical to ground to the device. Interestingly, on their product page they say _[No neutral required](https://www.legrand.us/passandseymour/motion-sensors/occupancy/single-pole-2-wire-multiple-loads/rw600utc.aspx)_, so maybe this is their way of getting around requiring a neutral and maybe the current passed to the ground is low enough to not be an issue?
Answer: Follow the manufacturer's instructions for wiring the device. If the instructions say make a ground connection, then make it.
For argument's sake, that ground could very well be for nothing more than grounding the switch (so it wouldn't necessarily be a pole).
However, it is likely that this device is indeed passing some current to ground. Below is a reference from a competing manufacturer of similar products. Notice that this only becomes a concern when combined with many such (twenty!) devices, or with other devices that are prone to leaking current to ground. Also note that this is only a concern on GFCI protected circuits.


no wifi after upgrade to 15.04 (no interface showing) bcm4313

Question: I just upgraded to 15.04 and now the network connection icon shows but there is no wifi in the network options. This is on a hp dm1 bcm4313.
ifconfig only shows "eth1" and "lo"
iwconfig says no wireless

running kernel 3.19.0-17
I tried this:
HP-Pavilion-dm1-Notebook-PC:~$ lshw -C network

WARNING: you should run this program as super-user.
  *-network UNCLAIMED
       description: Network controller
       product: BCM4313 802.11bgn Wireless Network Adapter
       vendor: Broadcom Corporation
       physical id: 0
       bus info: pci@0000:03:00.0
       version: 01
       width: 64 bits
       clock: 33MHz
       capabilities: bus_master cap_list
       configuration: latency=0
       resources: memory:f0200000-f0203fff
  *-network
       description: Ethernet interface
       product: RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller
       vendor: Realtek Semiconductor Co., Ltd.
       physical id: 0
       bus info: pci@0000:07:00.0
       logical name: eth1
       version: 06
       serial: 80:c1:6e:5a:45:30
       size: 10Mbit/s
       capacity: 1Gbit/s
       width: 64 bits
       clock: 33MHz
       capabilities: bus_master cap_list ethernet physical tp mii 10bt 10bt-fd 100bt 100bt-fd 1000bt 1000bt-fd autonegotiation
       configuration: autonegotiation=on broadcast=yes driver=r8169 driverversion=2.3LK-NAPI duplex=half firmware=rtl8168e-3_0.0.4 03/27/12 latency=0 link=no multicast=yes port=MII speed=10Mbit/s
       resources: irq:41 ioport:2000(size=256) memory:f0104000-f0104fff memory:f0100000-f0103fff
WARNING: output may be incomplete or inaccurate, you should run this program as super-user.

then I followed this thread :
http://ubuntuforums.org/showthread.php?t=2277063
and the adapter now recognizes wifi networks BUT the connection is extremely slow.
Any ideas?
Comment: How can it be runnin kernel 3.13, if you have Ubuntu 15.04? Kernel 3.19 should be there.
Comment: Pilot6: you are right!  my kernel is 3.19. I will update it! I was looking at another laptop, guess I got confused!
Comment: User68186: I did not follow any of that. My problem started with me not seeing the wifi card.
Answer: You should install the driver of your WiFi card.
If you can connect to internet via cable then go to Dash > Softwares Sources > Additional Drivers, and you should see the driver of your WiFi card: enable it, and you're done.
If you have no cable then you should mount the Ubuntu ISO Image (right click on the image > open with disk image mounter). From the mounted image root, go to pool/restricted/b and double click on the package there. The software installer will pop up, click install and restart once finished. You should now be able to see the wlan0 interface.
Answer: ok so here is what I did (not yet solved!):
I had signal and networks showing but slow connection so I un-blacklisted the bcma driver and blacklisted all of the following:
sudo gedit /etc/modprobe.d/blacklist.conf
mac80211
brcm80211
cfg80211
wl
lib80211_crypt_tkip
lib80211
And now I still have a problem...
after coming out of suspend I have to do the purge, then reinstall the driver. does anyone have any ideas about what command i need to use to keep my present installation and not have to constantly redo it?


Trying to add text field below table in GUI in java

Question: The code I have currently works but only displays the table. I'm trying to add a text field below it but I'm not sure how I would do it. I'm also trying to set a listener on the text field and I'm not too sure how to do that either. Sorry if this is a dumb question, I'm not experienced in Java forms
public class table extends JFrame {
    JTable TestDB;
    public table(){
        setLayout(new FlowLayout());

        String[] columnNames={"First Name","Last Name","Address"};
        Object[][] data={{"Bob","Hazel","HelpMeDr"},{"Yo","Whattup","ezpz"}};

        TestDB=new JTable(data,columnNames);
        TestDB.setPreferredScrollableViewportSize(new Dimension(500,50));
        TestDB.setFillsViewportHeight(true);

        JScrollPane scrollPane=new JScrollPane(TestDB);
        add(scrollPane);
    }
}

Answer: You can add a text field using the next code
textField = new JTextField(20);

//add a listener
textField.addActionListener(this);

Now for make something happend after interact with the text field you need to make a method
public void actionPerformed(ActionEvent evt) {
    //do this when action performed at the textfield
}

I recommend you to visit the next website for more information https://docs.oracle.com/javase/tutorial/uiswing/components/textfield.html
Answer: fist of all

do not extend JFrame
here is why you should not
set a listener on the text field you don't !! you add a listener , huge difference . @P Dev answer is clear and neat in the listener matter.
do not use add directly with the frame object instead use getContentPane().add and the same goes on with the setLayout method because you don't really use it on the frame it self and it might crash your application in many cases . see when should I use JFrame.add(component) and JFrame.getContentPane().add(component) in java

last thing , in simple words , the FlowLayout is meant to be used only when you are aligning your components in horizontally as if it's a text in lines .
instead use another layout like BoxLayout
like this
    public Table() {
        getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));

        String[] columnNames = {"First Name", "Last Name", "Address"};
        Object[][] data = {{"Bob", "Hazel", "HelpMeDr"}, {"Yo", "Whattup", "ezpz"}};

        TestDB = new JTable(data, columnNames);
        TestDB.setPreferredScrollableViewportSize(new Dimension(500, 50));
        TestDB.setFillsViewportHeight(true);

        JScrollPane scrollPane = new JScrollPane(TestDB);
        getContentPane().add(scrollPane);
        JTextField textField = new JTextField();
        getContentPane().add(textField);
    }

and one last thing is that text components have not less than 10 types of listener you have to use the one that fit your needs,our friend' answer(which i upvoted ) suggested that you will use ActionListener which it will be invoked every time the user hit 'Enter' in the text field .
see How to Use BoxLayout for better understanding of the layout matter and happy coding ^-^.


How do I turn off the power to my thermostat?

Question: I'd like to replace my thermostat with a new one. My current thermostat is one that doesn't have a C-wire and is powered by batteries.
Now, my question is... is there a switch for the power that I need turn off too? I could not find a switch for the thermostat in the breaker box.
I'm assuming just removing the batteries is fine for replacing my thermostat?
Comment: There is usually a 24V transformer in the furnace that powers the thermostat. You should turn the furnace off or you risk shorting the leads and anything from blowing a fuse in your furnace to dammage a control board.
Comment: I have a Carrier FX4CNF. I searched all over the manual online to see if there is a switch but I am not seeing one...
Comment: The 120v breaker that powers the furnace should kill it if there is not a local switch.
Comment: If your return is in ceiling, the switch is in attic.
Answer: Simply turning off the breaker that feeds the furnace will turn off the thermostat power as well.
Comment: Depending on the installation, there might be a switch near the furnace (serviceman switch). This can also be used to turn power off to the furnace.


JBPM. It is possible to correctly restore the task from status "Exited" to "Reserved" or "InProgress"?

Question: We use jbpm 6.5.0.Final. It is possible to correctly restore the task from status Exited to Reserved or InProgress?
Comment: First of all, welcome to StackOverflow. Following the advices of the community, it is recommended to include source code formatted or directly the image instead of links.
Please check the documentation [on how to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve)
Answer: Its not possible to restart/restore completed or exited task. If you want to regenerate particular humantask then make use of gateway.


Not all updates can be installed

Question: Every time I run software updater, Upgrade manager says not all updates can be installed and wants me to do a partial upgrade.
I have tried sudo dpkg --configure -a and sudo apt-get update && sudo apt-get -f install.
Sometimes it will say the software is up to date.
sudo apt update
Hit:1 http://us.archive.ubuntu.com/ubuntu bionic InRelease
Hit:3 http://us.archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:4 http://ppa.launchpad.net/nemh/systemback/ubuntu xenial InRelease
Hit:5 http://archive.canonical.com/ubuntu bionic InRelease
Hit:6 http://archive.ubuntu.com/ubuntu bionic InRelease
Hit:2 https://phoenixnap.dl.sourceforge.net/project/ubuntuzilla/mozilla/apt all InRelease
Hit:7 http://ppa.launchpad.net/jonathonf/ffmpeg-4/ubuntu bionic InRelease
Hit:8 http://security.ubuntu.com/ubuntu bionic-security InRelease
Hit:9 http://ppa.launchpad.net/mkusb/ppa/ubuntu bionic InRelease
Hit:10 http://ppa.launchpad.net/noobslab/themes/ubuntu bionic InRelease
Hit:11 http://ppa.launchpad.net/sane-project/sane-git/ubuntu bionic InRelease
Reading package lists... Done
Building dependency tree
Reading state information... Done
18 packages can be upgraded. Run 'apt list --upgradable' to see them.

sudo apt upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages were automatically installed and are no longer required:
  ant ant-optional antlr3 app-install-data aspectj autokey-common bnd brainparty-data casper catdoc cube2
  default-jdk default-jdk-doc default-jdk-headless efibootmgr finalrd fonts-dejavu fonts-linuxlibertine
  fonts-sil-gentium fonts-sil-gentium-basic gnome-software-common grub-efi-amd64-bin isolinux java-wrappers
  javahelp2 javascript-common junit junit-doc junit4 junit4-doc k3b-data kactivities-bin kactivitymanagerd
  kate5-data ktexteditor-data ktexteditor-katepart libactivation-java libaldmb1 libalien-sdl-perl
  liballegro4.4 libalut0 libantlr-java libantlr3-runtime-java libantlr4-runtime-java libaopalliance-java
  libapache-pom-java libappstream-glib8 libapr1 libaprutil1 libargs4j-java libasm-java libaspectj-java
  libatinject-jsr330-api-java libaudclient2 libavalon-framework-java libavdevice57 libbeansbinding-java
  libbindex-java libboost-signals1.65.1 libbsh-java libbyte-buddy-java libbytelist-java libcapture-tiny-perl
  libcdi-api-java libcglib-java libclass-inspector-perl libcodemodel-java libcommons-beanutils-java
  libcommons-cli-java libcommons-codec-java libcommons-collections3-java libcommons-compress-java
  libcommons-digester-java libcommons-io-java libcommons-lang-java libcommons-lang3-java
  libcommons-logging-java libcommons-net-java libcommons-parent-java libcompress-bzip2-perl libdom4j-java
  libdtd-parser-java libdumb1 libeclipselink-java libeditorconfig0 libel-api-java libenet7 libepub0
  libequinox-osgi-java libexcalibur-logkit-java libfastinfoset-java libfelix-framework-java
  libfelix-gogo-runtime-java libfelix-main-java libfelix-osgi-obr-java libfelix-resolver-java
  libfile-sharedir-perl libfile-which-perl libfluidsynth1 libfreemarker-java
  libgeronimo-annotation-1.3-spec-java libgeronimo-interceptor-3.0-spec-java
  libgeronimo-j2ee-connector-1.5-spec-java libgeronimo-jms-1.1-spec-java libgeronimo-jta-1.1-spec-java
  libgeronimo-validation-1.1-spec-java libgexiv2-2 libgit2-26 libgspell-1-1 libgspell-1-common libguava-java
  libguice-java libhamcrest-java libhamcrest-java-doc libhawtjni-runtime-java libhidapi-libusb0
  libhtml5parser-java libhttp-parser2.7.1 libhttpclient-java libhttpcore-java libicu4j-4.4-java libini4j-java
  libistack-commons-java libjansi-java libjansi-native-java libjavaewah-java libjaxb-api-java libjaxb-java
  libjaxen-java libjaxrs-api-java libjcodings-java libjcommander-java libjemmy2-java libjgit-java libjna-java
  libjna-jni libjna-platform-java libjnlp-servlet-java libjoda-time-java libjpa-2.1-spec-java libjs-jquery
  libjs-underscore libjsch-agent-proxy-java libjsch-java libjson-simple-java libjsonp-java libjsoup-java
  libjsp-api-java libjsr305-java libjvyamlb-java libjzlib-java libk3b7 libk3b7-extracodecs libkf5activities5
  libkf5calendarevents5 libkf5cddb-data libkf5cddb5 libkf5filemetadata-bin libkf5filemetadata-data
  libkf5filemetadata3 libkf5itemmodels5 libkf5kcmutils-data libkf5kcmutils5 libkf5notifyconfig-data
  libkf5notifyconfig5 libkf5plasma5 libkf5plasmaquick5 libkf5syntaxhighlighting-data libkf5syntaxhighlighting5
  libkf5texteditor5 libkf5texteditor5-libjs-underscore libkf5threadweaver5 libkxml2-java libllvm9
  libllvm9:i386 liblog4j1.2-java liblucene3-contrib-java liblucene3-java libmail-java
  libmaven-file-management-java libmaven-parent-java libmaven-resolver-java libmaven-shared-io-java
  libmaven-shared-utils-java libmaven3-core-java libmikmod3 libmjpegutils-2.1-0 libmodplug1 libmp3splt
  libmusicbrainz5cc2v5 libnb-absolutelayout-java libnb-javaparser-java libnb-org-openide-util-java
  libnb-org-openide-util-lookup-java libode6 libopencore-amrnb0 libopencore-amrwb0 libopenhmd0
  libosgi-annotation-java libosgi-compendium-java libosgi-core-java libphysfs1 libplank-common libplank1
  libplexus-archiver-java libplexus-cipher-java libplexus-classworlds-java
  libplexus-component-annotations-java libplexus-interpolation-java libplexus-io-java
  libplexus-sec-dispatcher-java libplexus-utils-java libplexus-utils2-java libpoppler-qt5-1
  libqscintilla2-qt5-13 libqscintilla2-qt5-l10n libqt5sql5 libqt5sql5-sqlite libquicktime2 libregexp-java
  librelaxng-datatype-java librngom-java libsdl-gfx1.2-5 libsdl-mixer1.2 libsdl-net1.2 libsdl-pango1
  libsdl-perl libsdl-ttf2.0-0 libsdl2-image-2.0-0 libsdl2-mixer-2.0-0 libsdl2-ttf-2.0-0 libsdo-api-java
  libsequence-library-java libserf-1-1 libservlet-api-java libservlet3.1-java libsimple-validation-java
  libsisu-guice-java libsisu-inject-java libsisu-ioc-java libsisu-plexus-java libslf4j-java libsnappy-java
  libsnappy-jni libsox-fmt-alsa libsox-fmt-base libsox3 libsqljet-java libstax-ex-java libstreambuffer-java
  libstringtemplate-java libstringtemplate4-java libsvn-java libsvn1 libsvnclientadapter-java libsvnkit-java
  libswing-layout-java libswingx-java libsystemback libtie-simple-perl libtrilead-ssh2-java libtxw2-java
  libuchardet0 libwagon-http-java libwagon-provider-api-java libwebsocket-api-java libws-commons-util-java
  libxcb-composite0 libxcb-damage0 libxmmsclient6 libxnvctrl0 libxsom-java libxz-java libyaml-snake-java
  linux-hwe-5.4-headers-5.4.0-42 linux-hwe-5.4-headers-5.4.0-45 linux-hwe-5.4-headers-5.4.0-47
  linux-hwe-5.4-headers-5.4.0-48 linux-hwe-5.4-headers-5.4.0-51 linux-hwe-5.4-headers-5.4.0-52
  linux-hwe-5.4-headers-5.4.0-53 linux-hwe-5.4-headers-5.4.0-54 localechooser-data lupin-casper
  open-invaders-data openjdk-11-doc openjdk-11-jdk openjdk-11-jdk-headless pingus-data plasma-framework
  python-pyinotify python-simplejson qml-module-org-kde-kconfig qml-module-org-kde-kquickcontrols
  qml-module-qtquick-controls qml-module-qtquick-dialogs qml-module-qtquick-layouts
  qml-module-qtquick-privatewidgets shotwell-common sox syslinux-utils systemback-cli systemback-efiboot-amd64
  systemback-locales systemback-scheduler testng timgm6mb-soundfont transcode transcode-doc ttf-dejavu-core
  ttf-ubuntu-font-family twolame user-setup
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
  linux-headers-5.4.0-60-generic linux-hwe-5.4-headers-5.4.0-60 linux-image-5.4.0-60-generic
  linux-modules-5.4.0-60-generic linux-modules-extra-5.4.0-60-generic
The following packages have been kept back:
  libsane libsane:i386 libsane-common libsane1 libsane1:i386
The following packages will be upgraded:
  apport apport-gtk libsasl2-2 libsasl2-2:i386 libsasl2-modules libsasl2-modules:i386 libsasl2-modules-db
  libsasl2-modules-db:i386 linux-generic-hwe-18.04 linux-headers-generic-hwe-18.04
  linux-image-generic-hwe-18.04 python3-apport python3-problem-report
13 upgraded, 5 newly installed, 0 to remove and 5 not upgraded.
Need to get 73.9 MB of archives.
After this operation, 349 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 python3-problem-report all 2.20.9-0ubuntu7.21 [10.3 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 python3-apport all 2.20.9-0ubuntu7.21 [82.3 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 apport all 2.20.9-0ubuntu7.21 [125 kB]
Get:4 http://security.ubuntu.com/ubuntu bionic-security/main amd64 linux-modules-5.4.0-60-generic amd64 5.4.0-60.67~18.04.1 [14.3 MB]
Get:5 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 apport-gtk all 2.20.9-0ubuntu7.21 [9,700 B]
Get:6 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libsasl2-modules-db amd64 2.1.27~101-g0780600+dfsg-3ubuntu2.3 [15.0 kB]
Get:7 http://us.archive.ubuntu.com/ubuntu bionic-updates/main i386 libsasl2-modules-db i386 2.1.27~101-g0780600+dfsg-3ubuntu2.3 [15.8 kB]
Get:8 http://us.archive.ubuntu.com/ubuntu bionic-updates/main i386 libsasl2-2 i386 2.1.27~101-g0780600+dfsg-3ubuntu2.3 [52.8 kB]
Get:9 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libsasl2-2 amd64 2.1.27~101-g0780600+dfsg-3ubuntu2.3 [49.2 kB]
Get:10 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libsasl2-modules amd64 2.1.27~101-g0780600+dfsg-3ubuntu2.3 [48.9 kB]
Get:11 http://us.archive.ubuntu.com/ubuntu bionic-updates/main i386 libsasl2-modules i386 2.1.27~101-g0780600+dfsg-3ubuntu2.3 [52.6 kB]
Get:12 http://security.ubuntu.com/ubuntu bionic-security/main amd64 linux-image-5.4.0-60-generic amd64 5.4.0-60.67~18.04.1 [8,976 kB]
Get:13 http://security.ubuntu.com/ubuntu bionic-security/main amd64 linux-modules-extra-5.4.0-60-generic amd64 5.4.0-60.67~18.04.1 [38.0 MB]
Get:14 http://security.ubuntu.com/ubuntu bionic-security/main amd64 linux-generic-hwe-18.04 amd64 126.96.36.199.67~18.04.55 [1,940 B]
Get:15 http://security.ubuntu.com/ubuntu bionic-security/main amd64 linux-image-generic-hwe-18.04 amd64 18.104.22.168.67~18.04.55 [2,704 B]
Get:16 http://security.ubuntu.com/ubuntu bionic-security/main amd64 linux-hwe-5.4-headers-5.4.0-60 all 5.4.0-60.67~18.04.1 [11.0 MB]
Get:17 http://security.ubuntu.com/ubuntu bionic-security/main amd64 linux-headers-5.4.0-60-generic amd64 5.4.0-60.67~18.04.1 [1,160 kB]
Get:18 http://security.ubuntu.com/ubuntu bionic-security/main amd64 linux-headers-generic-hwe-18.04 amd64 22.214.171.124.67~18.04.55 [2,576 B]
Fetched 73.9 MB in 41s (1,783 kB/s)
(Reading database ... 470604 files and directories currently installed.)
Preparing to unpack .../00-python3-problem-report_2.20.9-0ubuntu7.21_all.deb ...
Unpacking python3-problem-report (2.20.9-0ubuntu7.21) over (2.20.9-0ubuntu7.20) ...
Preparing to unpack .../01-python3-apport_2.20.9-0ubuntu7.21_all.deb ...
Unpacking python3-apport (2.20.9-0ubuntu7.21) over (2.20.9-0ubuntu7.20) ...
Preparing to unpack .../02-apport_2.20.9-0ubuntu7.21_all.deb ...
Unpacking apport (2.20.9-0ubuntu7.21) over (2.20.9-0ubuntu7.20) ...
Preparing to unpack .../03-apport-gtk_2.20.9-0ubuntu7.21_all.deb ...
Unpacking apport-gtk (2.20.9-0ubuntu7.21) over (2.20.9-0ubuntu7.20) ...
Preparing to unpack .../04-libsasl2-modules-db_2.1.27~101-g0780600+dfsg-3ubuntu2.3_amd64.deb ...
De-configuring libsasl2-modules-db:i386 (2.1.27~101-g0780600+dfsg-3ubuntu2.1) ...
Unpacking libsasl2-modules-db:amd64 (2.1.27~101-g0780600+dfsg-3ubuntu2.3) over (2.1.27~101-g0780600+dfsg-3ubuntu2.1) ...
Preparing to unpack .../05-libsasl2-modules-db_2.1.27~101-g0780600+dfsg-3ubuntu2.3_i386.deb ...
Unpacking libsasl2-modules-db:i386 (2.1.27~101-g0780600+dfsg-3ubuntu2.3) over (2.1.27~101-g0780600+dfsg-3ubuntu2.1) ...
Preparing to unpack .../06-libsasl2-2_2.1.27~101-g0780600+dfsg-3ubuntu2.3_i386.deb ...
De-configuring libsasl2-2:amd64 (2.1.27~101-g0780600+dfsg-3ubuntu2.1) ...
Unpacking libsasl2-2:i386 (2.1.27~101-g0780600+dfsg-3ubuntu2.3) over (2.1.27~101-g0780600+dfsg-3ubuntu2.1) ...
Preparing to unpack .../07-libsasl2-2_2.1.27~101-g0780600+dfsg-3ubuntu2.3_amd64.deb ...
Unpacking libsasl2-2:amd64 (2.1.27~101-g0780600+dfsg-3ubuntu2.3) over (2.1.27~101-g0780600+dfsg-3ubuntu2.1) ...
Preparing to unpack .../08-libsasl2-modules_2.1.27~101-g0780600+dfsg-3ubuntu2.3_amd64.deb ...
De-configuring libsasl2-modules:i386 (2.1.27~101-g0780600+dfsg-3ubuntu2.1) ...
Unpacking libsasl2-modules:amd64 (2.1.27~101-g0780600+dfsg-3ubuntu2.3) over (2.1.27~101-g0780600+dfsg-3ubuntu2.1) ...
Preparing to unpack .../09-libsasl2-modules_2.1.27~101-g0780600+dfsg-3ubuntu2.3_i386.deb ...
Unpacking libsasl2-modules:i386 (2.1.27~101-g0780600+dfsg-3ubuntu2.3) over (2.1.27~101-g0780600+dfsg-3ubuntu2.1) ...
Selecting previously unselected package linux-modules-5.4.0-60-generic.
Preparing to unpack .../10-linux-modules-5.4.0-60-generic_5.4.0-60.67~18.04.1_amd64.deb ...
Unpacking linux-modules-5.4.0-60-generic (5.4.0-60.67~18.04.1) ...
Selecting previously unselected package linux-image-5.4.0-60-generic.
Preparing to unpack .../11-linux-image-5.4.0-60-generic_5.4.0-60.67~18.04.1_amd64.deb ...
Unpacking linux-image-5.4.0-60-generic (5.4.0-60.67~18.04.1) ...
Selecting previously unselected package linux-modules-extra-5.4.0-60-generic.
Preparing to unpack .../12-linux-modules-extra-5.4.0-60-generic_5.4.0-60.67~18.04.1_amd64.deb ...
Unpacking linux-modules-extra-5.4.0-60-generic (5.4.0-60.67~18.04.1) ...
Preparing to unpack .../13-linux-generic-hwe-18.04_126.96.36.199.67~18.04.55_amd64.deb ...
Unpacking linux-generic-hwe-18.04 (184.108.40.206.67~18.04.55) over (188.8.131.52.64~18.04.53) ...
Preparing to unpack .../14-linux-image-generic-hwe-18.04_220.127.116.11.67~18.04.55_amd64.deb ...
Unpacking linux-image-generic-hwe-18.04 (184.108.40.206.67~18.04.55) over (126.96.36.199.64~18.04.53) ...
Selecting previously unselected package linux-hwe-5.4-headers-5.4.0-60.
Preparing to unpack .../15-linux-hwe-5.4-headers-5.4.0-60_5.4.0-60.67~18.04.1_all.deb ...
Unpacking linux-hwe-5.4-headers-5.4.0-60 (5.4.0-60.67~18.04.1) ...
Selecting previously unselected package linux-headers-5.4.0-60-generic.
Preparing to unpack .../16-linux-headers-5.4.0-60-generic_5.4.0-60.67~18.04.1_amd64.deb ...
Unpacking linux-headers-5.4.0-60-generic (5.4.0-60.67~18.04.1) ...
Preparing to unpack .../17-linux-headers-generic-hwe-18.04_18.104.22.168.67~18.04.55_amd64.deb ...
Unpacking linux-headers-generic-hwe-18.04 (184.108.40.206.67~18.04.55) over (18.104.22.168.64~18.04.53) ...
Setting up linux-hwe-5.4-headers-5.4.0-60 (5.4.0-60.67~18.04.1) ...
Setting up libsasl2-modules-db:amd64 (2.1.27~101-g0780600+dfsg-3ubuntu2.3) ...
Setting up libsasl2-modules-db:i386 (2.1.27~101-g0780600+dfsg-3ubuntu2.3) ...
Setting up libsasl2-2:amd64 (2.1.27~101-g0780600+dfsg-3ubuntu2.3) ...
Setting up libsasl2-2:i386 (2.1.27~101-g0780600+dfsg-3ubuntu2.3) ...
Setting up linux-modules-5.4.0-60-generic (5.4.0-60.67~18.04.1) ...
Setting up linux-headers-5.4.0-60-generic (5.4.0-60.67~18.04.1) ...
Setting up python3-problem-report (2.20.9-0ubuntu7.21) ...
Setting up libsasl2-modules:amd64 (2.1.27~101-g0780600+dfsg-3ubuntu2.3) ...
Setting up libsasl2-modules:i386 (2.1.27~101-g0780600+dfsg-3ubuntu2.3) ...
Setting up linux-headers-generic-hwe-18.04 (188.8.131.52.67~18.04.55) ...
Setting up linux-image-5.4.0-60-generic (5.4.0-60.67~18.04.1) ...
I: /vmlinuz.old is now a symlink to boot/vmlinuz-5.4.0-58-generic
I: /initrd.img.old is now a symlink to boot/initrd.img-5.4.0-58-generic
I: /vmlinuz is now a symlink to boot/vmlinuz-5.4.0-60-generic
I: /initrd.img is now a symlink to boot/initrd.img-5.4.0-60-generic
Setting up python3-apport (2.20.9-0ubuntu7.21) ...
Setting up linux-modules-extra-5.4.0-60-generic (5.4.0-60.67~18.04.1) ...
Setting up apport (2.20.9-0ubuntu7.21) ...
apport-autoreport.service is a disabled or a static unit, not starting it.
Setting up linux-image-generic-hwe-18.04 (18.104.22.168.67~18.04.55) ...
Setting up apport-gtk (2.20.9-0ubuntu7.21) ...
Setting up linux-generic-hwe-18.04 (184.108.40.206.67~18.04.55) ...
Processing triggers for libc-bin (2.27-3ubuntu1.4) ...
Processing triggers for systemd (237-3ubuntu10.43) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for hicolor-icon-theme (0.17-2) ...
Processing triggers for mime-support (3.60ubuntu1) ...
Processing triggers for ureadahead (0.100.0-21) ...
Processing triggers for desktop-file-utils (0.23-1ubuntu3.18.04.2) ...
Processing triggers for bamfdaemon (0.5.3+18.04.20180207.2-0ubuntu1) ...
Rebuilding /usr/share/applications/bamf-2.index...
Processing triggers for linux-image-5.4.0-60-generic (5.4.0-60.67~18.04.1) ...
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-5.4.0-60-generic
W: Possible missing firmware /lib/firmware/rtl_nic/rtl8125a-3.fw for module r8169
W: Possible missing firmware /lib/firmware/rtl_nic/rtl8168fp-3.fw for module r8169
W: Possible missing firmware /lib/firmware/amdgpu/renoir_gpu_info.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/renoir_asd.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/renoir_rlc.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/renoir_mec2.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/renoir_mec.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/renoir_me.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/renoir_pfp.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/renoir_ce.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/renoir_sdma.bin for module amdgpu
W: Possible missing firmware /lib/firmware/amdgpu/renoir_vcn.bin for module amdgpu
/etc/kernel/postinst.d/zz-update-grub:
Sourcing file `/etc/default/grub'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.4.0-60-generic
Found initrd image: /boot/initrd.img-5.4.0-60-generic
Found linux image: /boot/vmlinuz-5.4.0-58-generic
Found initrd image: /boot/initrd.img-5.4.0-58-generic
Found linux image: /boot/vmlinuz-5.4.0-56-generic
Found initrd image: /boot/initrd.img-5.4.0-56-generic
Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin
Found Ubuntu 20.04.1 LTS (20.04) on /dev/sda2
done

Is there something else I can try?
Comment: @user535733 I have updated my question.
Comment: That's a suspiciously large number of orphaned packages eligible for autoremoval. Have you looked into that?
Comment: user535733@ I ran all the commands offered here and update manager is now working correctly. sudo apt upgrade no longer shows any orphaned packages. :-)
Answer: sudo apt install aptitude
sudo aptitude update
sudo aptitude dist-upgrade

Comment: dist-upgrade can break your system, because it can remove packages. Without further explanation I don't think this is an appropriate answer.

Not all updates can be installed


Could not log in the ubuntu 16.04 after installing the nvidia geforce drive

Question: I installed an nvidia driver (340, my display card is GTX970) but I could not log in to Ubuntu afterwards. I get a black screen after logging in. When I enter a tty, in the login part, it will continue showing:
None of the NVIDIA graphics adapters were initialized
Nvidia init module failed

As a result, I could not type any command in the tty.
Answer: I had the same problem here is what I did:
Enter the terminal command line by
Ctrl-Alt-F1. Purged all nvidia drivers
sudo apt-get purge nvidia*
sudo apt-get autoclean
sudo apt-get autoremove

Then I renamed the .Xauthority in/home/username/
mv .Xauthority .Xauthority.bak

Then reboot and it worked fine. Hope that works for you too


Does the rounding unit of a floating point system depend only on the mantissa?

Question: The rounding unit (or machine epsilon) of a binary floating point system is usually represented as $\frac{2^{-(p - 1)}}{2}$ or simply $2^{-(p - 1)}$, according to this Wikepedia's article (if I'm not wrong): not sure yet why it has two values...
So it seems that it only depends on the number of bits in the mantissa, but I can't really visualize (and therefore fully understand) why is that.
Could you please try to explain me why the exponent has nothing to do with the rounding unit?
(Maybe I should go to sleep...)
Answer: Because the machine epsilon is defined in terms of "relative error", the relative error is such that the exponent value doesn't affect the error.
Let $x$ be a real number while let $y = RN(x)$ (assume $t$ mantissa digits), assuming rounding instead of truncation you can easily prove that
$$
\epsilon_{abs} = |x - y| \leq 2^{e_x - t - 1}$
$$
($e_x$ is the exponent of the number $x$).
If we compute the relative error instead we have
$$
\epsilon_{rel} = \frac{|x - y|}{|x|} \leq \frac{2^{e_x - t - 1}}{|x|} \leq \frac{2^{e_x - t - 1}}{2^{e_x}} = 2^{-t-1}
$$
The quantity $2^{-t-1}$ is what we define machine epsilon. If instead of "rounding" you assume "truncation" you would get $2^{-t}$ as bound.
Answer: Because the machine epsilon is the smallest quantity you can add to $1$ and get a result that differs from $1$.  So in a sense the definition does not say the exponent has nothing to do with it, instead it says the exponent is the special number $0$.
BTW other definitions of the machine epsilon use the smallest quantity you can subtract from $1$ and get a result that differs from $1$. The definitions differ by a factor of $2$.
Comment: There's also a difference between defining the epsilon as the difference between two representable numbers, or as the addend that will push $1$ sufficiently far towards a neighboring number that round-to-nearest takes it the rest of the way.


How to scan multiple pages to one PDF file using HP Envoy 4500

Question: I am using  UBUNTU 14.04 and have a HP Envoy 4500 printer (hplip 3.14.10) connected via USB.
I have a document of about 12 pages. I want to scan them onto a single PDF. I am able to scan each document individually and therefore have 12 individual PDF files, but not to one single PDF. I have searched to web and am now so confused I don't know what to do. Can anyone help me?
Answer: Did you use Simple Scan?
If you don't press "New Document" but keep on scanning using the button with the scanner icon, you should be able to save all pages in a single file.
Comment: Thank you Klaus. I downloaded Simple Scan and it works perfectly. I appreciate your help thanks.
Answer: I had this same issue, and I downloaded and now use PDF-Shuffler.
PDF-Shuffler will allow you to quickly and easily merge those separate individual files into a single PDF document.
Also, you can take multi-page PDF documents and split them any way you like just as easily by deleting individual pages.
Once you have added or removed the necessarily individual pages and your file is the way you want it, then you can save your work as a new file.
One thing to be aware of is that PDF-Shuffler is totally free (slash awesome), and as such it has just a few minor limitations: the more pages you merge into a single file, the longer processing time the software takes...be patient...the software is working.
Also PDF-Shuffler seems to max out at around 500 megabytes per single file, so if you had more than 12 pages...say something like 75 pages or more...and the finished product was something like 650 megabytes, then you'd have to split that document into two parts like document part "A" with ~500 megabytes and part "B" with ~150 megabytes (or however you wish to divide the data).
And if you're working with PDFs or any imaged documents, then I also recommend you check out ImageMagick (http://imagemagick.org/) because I use PDF-Shuffler in conjunction with ImageMagick in order to produce my finished product for my job. ImageMagick is straight up ninja from the terminal. These two work great for me.
Good luck!