text:
Q: Cassandra CQL - NoSQL or SQL I am pretty new to Cassandra, just started learning Cassandra a week ago.
I first read, that it was a NoSQL, but when i started using CQL,
I started to wonder whether Cassandra is a NoSQL or SQL DB?
Can someone explain why CQL is more or less like SQL?

A: Docs for CQLV3.0
CQL DESCRIBE to get schema of keyspace, column family, cluster
CQL Doesn't support some stuffs I had known in SQL like joins group by triggers cursors procedure transactions stored procedures
CQL3.0 Supports ORDER BY
CQL Supports all DML and DDL functionalities
CQL Supports BATCH

BATCH is not an analogue for SQL ACID transactions.

Just the DOC mentioned above is a best reference :)

A: For all intents and purposes, CQL is SQL, so in the strictest sense Cassandra is an SQL database.  However, most people closely associate SQL with the relational databases it is usually applied to.  Under this (mis)interpretation, Cassandra should not be considered an "SQL database" since it is not relational, and does not support ACID properties.

A: CQL is declarative like SQL and the very basic structure of the query component of the language (select things where condition) is the same.   But there are enough differences that one should not approach using it in the same way as conventional SQL.
The obvious items:  1.  There are no joins or subqueries. 2.  No transactions
Less obvious but equally important to note:

*

*Except for the primary key, you can only apply a WHERE condition on a column if you have created an index on that column.  In SQL, you don't have to index a column to filter on it but in CQL the select statement will fail outright.

*There are no OR or NOT logical operators, only AND.  It is very important to model your data so you won't need these two; it is very easy to accidentally forget.

*Date handling is profoundly different.  CQL permits ONLY the equal operator for timestamps so extremely common and useful expressions like this do not work: where dateField > TO_TIMESTAMP('2013-01-01','YYYY-MM-DD')   Also, CQL does not permit string insert of dates accurate to millis (seconds only) -- but it does permit entry of millis since epoch as a long int -- which most other DB engines do NOT permit.   Lastly, timezone (as GMT offset) is invisibly captured for both long millis and string formats without a timezone.  This can lead to confusion for those systems that deliberately do not conflate local time + GMT offset.

*You can ONLY update a table based on primary key (or an IN list of primary keys).  You cannot update based on other column data, nor can you do a mass update like this: update table set field = value;  CQL demands a where clause with the primary key.

*Grammar for AND does not permit parens.  TO be fair, it's not necessary because of the lack of the OR operator but this means traditional SQL rewriters that add "protective" parens around expressions will not work with CQL, e.g.: select * from www where (str1 = 'foo2') and (dat1 = 12312442);
In general, it is best to use Cassandra as a big, resilient permastore of data for which a small number of very high level, very high performance queries can be applied to drag out a subset of data to work with at the application layer.   That subset might be 1 million rows, yes.   CQL and the Cassandra model is not designed for 2 page long SELECT statements with embedded cases, aggregations, etc. etc.


text:
Q: Is there a way to specify all three resource properties (executor instances, cores and memory) in Spark on YARN (Dataproc) I'm trying to setup a small Dataproc Spark cluster of 3 workers (2 regular and one preemptible) but I'm running into problems.
Specifically, I've been struggling to find a way to let the Spark application submitters to have freedom to specify the number of executors while being able to specify how many cores should be assigned to them
Dataproc image of Yarn and Spark has the following defaults:

*

*Spark dynamic allocation enabled

*Yarn Capacity Scheduler configured with DefaultResourceCalculator
With these defaults the number of cores is not taken into account (the ratio container-vcores is always 1:1), as DefaultResourceCalculator only cares about memory. In any case, when configured this way, the number of executors is honored (by means of setting spark.dynamicAllocation.enabled = false and spark.executor.instances = <num> as properties in gcloud submit)
So I changed it to DominantResourceCalculator and now it takes care of the requested cores but I'm no longer able to specify the number of executors, regardless of disabling the Spark dynamic allocation or not.
It might also be of interest to know that the default YARN queue is limited to 70 % of capacity by configuration (in capacity-scheduler.xml) and that there is also another non-default queue configured (but not used yet). My understanding is that both Capacity and Fair schedulers do not limit the resource allocation in case of uncontended job submission as long as the max capacity is kept at 100. In any case, for the sake of clarity, these are the properties setup during the cluster creation:
capacity-scheduler:yarn.scheduler.capacity.resource-calculator=org.apache.hadoop.yarn.util.resource.DominantResourceCalculator
capacity-scheduler:yarn.scheduler.capacity.root.queues=default,online
capacity-scheduler:yarn.scheduler.capacity.root.default.capacity=30
capacity-scheduler:yarn.scheduler.capacity.root.online.capacity=70
capacity-scheduler:yarn.scheduler.capacity.root.online.user-limit-factor=1
capacity-scheduler:yarn.scheduler.capacity.root.online.maximum-capacity=100
capacity-scheduler:yarn.scheduler.capacity.root.online.state=RUNNING
capacity-scheduler:yarn.scheduler.capacity.root.online.acl_submit_applications=*
capacity-scheduler:yarn.scheduler.capacity.root.online.acl_administer_queue=*

The job submission is done by means of gcloud tool and the queue used is the default.
E.g, the following properties set when executing gcloud dataproc submit:

--properties spark.dynamicAllocation.enabled=false,spark.executor.memory=5g,spark.executor.instances=3

end up in the following assignment:

Is there a way to configure YARN so that it accepts both?
EDITED to specify queue setup

A: You may try setting a higher value, such as 2, for yarn.scheduler.capacity.root.online.user-limit-factor in place of the present value of 1, the value you have set. This setting enables the user to leverage twice the chosen capacity. Your setting of 100% as the maximum capacity allows for this doubling of the chosen capacity.

redpajama_set_name: RedPajamaStackExchange


text:
Q: Qt widget size recalculation at runtime I have a problem with size calculation in Qt when adding new widgets at run time.
I have tried to illustrate the problem with the pruned program down there. Hopefully, it shows the same problem than my other (more complex) program:
When a widget has been shown, using:
w->show();

...and some new widgets are added to it later on (possibly w has a layout),
what should I do to redisplay w and its parents so that the size of the newly added child widgets is taken into account?
The behaviour I want is that the size recalculation propagates upward to the nearest scrolled object (or the main window if there is no scrolled objects)
In the example below, I create a little widget structure: if the call to show() (commented SHOW1) is removed, then the whole widget structure is defined before the first call to show() and everything works.
BUT: if I do call show() (at SHOW1), then the last show does not display the right things: the frame is still too small
 #include <QApplication>
 #include <QtCore>
 #include <QMainWindow>
 #include <QTabWidget>
 #include <QWidget>
 #include <QGroupBox>
 #include <QVBoxLayout>
 #include <QLabel>

 #include <stdlib.h>

 int main(int argc, char *argv[])
 {
    QApplication app(argc, argv);
    QMainWindow* main_window = new(QMainWindow);
    main_window->setObjectName("main_window");
    main_window->resize(800, 600);
    main_window->setWindowTitle("Hello");

    QTabWidget* node_tab_widget = new QTabWidget(main_window);
    node_tab_widget->setObjectName(QString::fromUtf8("tab_widget"));

    QWidget* w= new QWidget(node_tab_widget);
    node_tab_widget->addTab(w, "TAB");

    QGroupBox* group_widget = new QGroupBox("GROUPNAME", w);
    QVBoxLayout*  group_layout = new QVBoxLayout;
    group_widget->setLayout(group_layout);
    group_layout->addWidget((QLabel*)new QLabel(">>>>>>>>>>>>>>>>>>>>>>>>>here1"));

    main_window->show();  // SHOW1: If this one is commented, then OK!

    group_layout->addWidget((QLabel*)new QLabel("here2"));
    group_layout->addWidget((QLabel*)new QLabel("here2"));
    group_layout->addWidget((QLabel*)new QLabel("here2"));
    group_layout->addWidget((QLabel*)new QLabel("here2"));

    main_window->setCentralWidget(node_tab_widget);

    // main_window->update();
    // main_window->hide();

    main_window->show(); // How to I get that to recaclulate the size of its contents?
    return app.exec();
 }

A: Your w widget doesn't have a layout. Try adding the following lines after creating group_widget:
QVBoxLayout *wlayout = new QVBoxLayout(w);
wlayout->addWidget(group_widget);
wlayout->addStretch();

You can get rid of addStretch if you actually want w to span the entire parent.


text:
Q: which is faster? "vector of structs" or "a number of vectors"? Solution 1:
If i have a class like,
class car{ public: int a; string b; bool c;};

i can build a vector of 200 cars:
std::vector<car>   allcas;
allcars.resize(200)

at runtime, i just do:
this_car=allcars[102];

then ....
Solution 2:
i have
std::vector<int> a; a.resize(200);
std::vector<string>b; b.resize(200);
std::vector<bool> c; c.resize(200);

this_car_a = a[102];
this_car_b = b[102];
this_car_c = c[102];

Question:
Which one is faster?
Does anyone have an idea? thanks  a  lot in advance!

A: First of all, splitting them is a horrible idea for maintainability reasons, which should be your foremost concern.
Second of all, you just tripled your allocation time (three allocations instead of one), deallocation time (same), and destroyed cache locality of reference (probably a slowdown).
Third, The only benefit would be if you only read one member for all the cars over and over, and rarely alter the cars.

A: It really depends on how you want to use your data. For example, if you only want to access one field:
car this_car = allcars[12];
cout << this_car.a;

Then this causes you to create a copy of this_car. In this case you would be needlessly copying fields b and c. Of course, you can fix this by getting by reference:
car & this_car = allcars[12];

This is potentially still slower than just doing
a = a[12];

However, if you want to access multiple properties of your class, then it is almost certainly better to store as them together. At this point you'll probably get better performance because of locality of reference, however it is all really dependent on the compiler, memory manager, etc.
In the end, the answer to which is best performance is: it depends. This will definitely not be a bottleneck decision, and it is definitely better to keep them in a single struct for code readability / your own sanity.

A: If a, b and c belong together and form an object together, why the hell would you split them? Go for clarity and readability first. Anything else comes after that. Also, I think v2 would be slower. More access on the vector. Didn't time it though. As always for questions about speed, time it.

A: A "struct of vectors" has a couple of advantages over a "vector of structs":

*

*If your inner loop doesn't use every element of the struct, then struct-of-vectors can save on memory bandwidth, as unused element vectors will not be loaded into cache.

*It is easier to vectorize.  A struct-of-vectors may enable you to use the vector processing instructions of your processor (through assembly, intrinsics, or clever compilers) to speed up your inner loops.

On the other hand, premature optimization is the root of all evil:

*

*Using a struct-of-vectors is more difficult, awkward, and obscure.

*You generally don't know where your performance bottlenecks are until you've got your code up and running.  Is it worth making your code more verbose, fragile, and difficult?  You won't know until you actually profile it.

*The benefits of struct-of-vectors programming vary on a case by case basis.  It doesn't always yield a speedup; you could actually end up with worse performance.

*In particular, if your access pattern is random (as opposed to sequential or otherwise localized) a struct-of-vectors organization could end up loading much more useless data from memory, if each cache line includes elements from multiple nearby objects...

So, my recommendation is to use vector-of-structs by default, but keep struct-of-vectors in mind as an alternative (i.e., make sure you can switch later, if you expect sequential/local access patterns and it doesn't cost much effort up front).  Once your program is running, you can profile it to see where the performance-critical sections are, and try out struct-of-vector and vectorized operations where they'll do the most good.

A: CPUs love prefetching.
If you are going to linearly traverse your data in the following pattern...
abcabcacb...

...then you are better off (performance-wise) with solution #1. If you are going to access them as:
aaa...bbb..ccc...

...then go for solution #2.
However, if you are not going to do a linear traversal or if you did not actually benchmark your code and concluded that you really need to squeeze every last drop of performance out of this piece of code, do your maintainability a favor and stick with Solution #1.
--- EDIT ---
In a multi-threaded environment, the physical layout of data may lead to false sharing. Essentially, keeping too close the pieces of data that are concurrently accessed by different threads may cause cache contention and destroy the scalability.
So, if you concurrently access a from one thread and b from another, it may be worth splitting them physically apart and implementing the solution #2. If, on the other hand, you access two "sibling" as, stick with the solution #1.
--- EDIT 2 ---
For the excellent treatment of this subject, I warmly recommend Herb Sutter's talk "Things Your Programming Language Never Told You", still available at:
https://www.youtube.com/watch?v=L7zSU9HI-6I
https://nwcpp.org/talks/2007/Machine_Architecture_-_NWCPP.pdf

A: It depends on the size of the struct members and on your pattern access. One singleton access is irrelevant, but consider you do an iteration over a vector and you're only interested in member a. The wider the struct is, the fewer struct entries will fit in a cache line and the more cache misses you'll occur. Moving all a members separate in a vector increases the cache line density and thus increases the performance. It can be quite significant (1.5x, 2x, even more).
However, is far more important to focus in code maintainability, make it readable, debuggable and easy to refactor. The code should clearly express the intent. Such micro optimizations as you're asking about should only be considered for measured bottlenecks. Get yourself a copy of the Software Optimization Cookbook.


text:
Q: onDrop event not fired in react app I want to drag from a image to a span like this:
DRAG FROM HERE

DROP HERE:
DROP HERE

DRAG AND DROP HANDLERS:
  dragStartHandler = (idx) => (event) => {
    console.log(idx,"called drag event and loaded data in drag object")
    event.dataTransfer.setData('text', idx);
  }

  dropHandler = () => (event) => {
    event.preventDefault();
    console.log("DROP EVENT")
  }

  preventDefault = () => (event) => {
    event.preventDefault();
    console.log("prevent default")
  }

A fiddle with this code is here: https://jsfiddle.net/69z2wepo/229855/
But the drop event is never called when i click on the draggable image, drag it over the drop area and release the mouse button. This is on chrome, firefox and safari.
How can I call the drop event correctly?

A: Solution:
Change
onDragOver={this.preventDefault}

to
onDragOver={this.preventDefault()}

if you're on ES6. Never harmful to go back to the basics :-)


text:
Q: Remove "faulty state" in RAID 1 I wonder if there is any possibility to remove the state "faulty" in a RAID 1 if (for example) someone failed the wrong hard disk.
I already searched for answers with Google and found several tutorials with re-creating the array and adding "assume-clean" but I can not do this on a running system. So is it possible to "unfail" a hard disk before it was removed from the raid?

A: There is no such command in mdadm. If you have set the partition to faulty state, the only way to get it online again is to remove and readd it, e.g.
mdadm --remove /dev/md0 /dev/sdb1
mdadm --add /dev/md0 /dev/sdb1

A: Faulty state is written in a super-block at the begining of your disk/partition, with other metadata regarding your RAID. Those blocks need to have enough information to rebuild the RAID in case of trouble.
mdadm has a command to set a disk as faulty, but no one to set it as healthy as you could lose data if ever it's wrong. But they are situations when you would like it. For instance, in home NAS with 2 bays you could decide to use one disk only (to start with). Often, in this situation, those NAS OS create a RAID 1 with just one disk without telling. If later on, for whatever reason, this disk is marked as degraded you are stuck. Even if your disk is healthy. Note: It may happen an OS considered a too slow I/O answer as a degraded disk.
In this case (your SMART data are clean), the only solution is to remove the faulty state flag. But this is really dangerous. You have first to stop your RAID. All disks will be detached, but super-block and data will remain on the disks. To get rid of the super-block, you have to create a new raid with this disk/partition and the --assume-clean option. This will write a new super-block above the old one but keep the data. Be careful, without this option you may lose all your data and be warned there is always a risk even with it.
So in this particular example, something like:
# Stop the RAID1
mdadm -S /dev/mdX
# Recreate a RAID1 with just one disk keeping the data as is
mdadm --create --assume-clean --level=1 --force --raid-devices=1 /dev/mdX /dev/sdXY

may remove the faulty flag.
By the way, if ever you wonder why not put a second disk and get it sync. The answer is: it's not possible to sync anything with a disk flaged as faulty with mdadm.


text:
Q: Create a vm or cloud service on azure using libcloud? I'm having a problem with libcloud/drivers/azure.py when I create a VM or a cloud service, I receive always a 400 bad request without a body. Could someone help me out of this please?
Here is my code:
# connectHandler use my pem file to create a connection with the server, return a AzureNodeDriver objet
conn = _connectHandler.api_connect(compute_ressource)
try:
    result = conn.ex_create_cloud_service(name= "testCloudServiceZT200", location= "Central US")
except Exception as e:
    logger.error(e)
else:
    return result

and here is what I got in return:
<LibcloudError in <libcloud.compute.drivers.azure.AzureNodeDriver object at 0x7fceaeb457d0> 'Message: Bad Request, Body: , Status code: 400'>
Could someone please tell me why this error, and maybe give me some examples of azure.py, it will be very grateful. thx!!

A: The Azure driver seems very new, since it's not even included in the latest release available via PyPI. I had the same problem, used ipdb to look at the request and XML that is created by the Azure driver. At first I thought I found a number of problems, but after looking at the source and not only the output of the debugger it boils down to a simple fix.
The following curl request works for me:
curl -v -E {PATH_TO_PEM_FILE} -H 'x-ms-version: 2015-04-01' -H 'Content-Type: application/xml' -d '<?xml version="1.0" encoding="utf-8"?><CreateHostedService xmlns="http://schemas.microsoft.com/windowsazure"><ServiceName>test-cloudservice-libcloud-azure-driver</ServiceName><Label>dGVzdC1jbG91ZHNlcnZpY2UtbGliY2xvdWQtYXp1cmUtZHJpdmVyCg==</Label><Location>West Europe</Location></CreateHostedService>' https://management.core.windows.net/{SUBSCRIPTION_ID}/services/hostedservices

But the XML that is generated by the Azure driver contains encoding='utf8', which doesn't work. It has to be utf-8. If you replace line 2710 in the current head of the github repo (e105433e941262e03eb3bb922db47dabdd8efa75) with result = ensure_string(ET.tostring(doc, encoding='utf-8')), it works, encoding='utf8' was the culprit, at least for me.
I have opened a pull request, hope it solves the issue for you as well: https://github.com/apache/libcloud/pull/538


text:
Q: How to cast HttpErrorResponse i was wondering how it could be possible to substitute my own class instead of HttpErrorResponse like follow.
onSendFormDataClicked(event){
    this.http.post(url, body).catch((response:MyErrorClass)=>{
        console.log(response.GetErrorMessage());
    });
}

export class MyErrorClass extends HttpErrorResponse{
    public GetErrorMessage(){
        return "My Custom logic for error handling";
    }
}

I tried this but am getting GetErrorMessage() is not a function.

A: It looks like what you are trying to do is to change the response parameter in the this.http.post catch handler to be of type MyErrorClass. However you won't be able to do this without overriding the this.http.post method itself, which I doubt is what you want to do.
Instead you can implement your custom error handling within the catch block:
onSendFormDataClicked(event) {
  this.http.post(url, body).catch((response) => {
    const error = new MyErrorClass(response);
    console.log(error.getErrorMessage());
  });
}

export class MyErrorClass {
  constructor(response: HttpErrorResponse) {
    // Your logic here.
  }

  getErrorMessage() {
    return "My Custom logic for error handling";
  }
}


text:
Q: Profile Build vs Normal Build: CPU Usage? Short Version:
Before the TL;DR section, my main question is this, what is difference when building to profile using instruments then a regular build that would result in reduced CPU load of my app by over 200%?
When building to run, it uses well over 200% CPU as reported by activity monitor, but with everything else the same, when building for profiling, using the Time Profiler, it reduces the CPU load down to  <5%, which is a dramatic (orders of magnitude) difference.
TL;DR Version:
As an exercise to learn Cocoa, Swift and DSP (yes all three at once), I am working on writing a simple radio scanner OS X application using the cheap rtl-sdr dongles.
I have written a simple Swift wrapper around librtlsdr, a simple UI to be able to set the frequency, and a couple of simple DSP routines.  My wrapper around librtlsdr uses an NSOperationQueue and my DSP routines use GCD queues in order to move the IO and CPU intense routines off the main thread / queue.
Currently, everything is working to the extent that I can successfully demodulate an AM transmission.
I have implemented a simple low-pass FIR filter and while working on the algorithm, I was surprised when I realized that I couldn't use much more than about 30 coefficients before my filter routine started taking too long and the audio became choppy.  As well, Activity Monitor shows up to 300% CPU usage for my app, which seems crazy high considering my filter contains nothing but a nested loop to do some multiply and accumulate operations.  Anything higher than about 40 coefficients and the UI becomes unresponsive.
For the DSP minded, it's a decimating filter where I am using the entire sample set for filtering (960000 sps) , but only filtering the samples that I need for the rate reduction (48000), using a rectangular windowed sinc function for the coefficients, pre computed.  Not the most efficient algorithm, but on my quad core i7 Macbook Pro and iMac, it should still scream.
To get some insight on where my program was using up all the CPU cycles, I decided to give Instruments a go.  Product->Profile, choosing the Time Profiler and running my app gave my some interesting information.
1) My filter routine was NOT using the most CPU cycles.
2) Activity monitor showed that my app  wasn't even at 5% CPU usage
So I decided to find out how far I can stress things before I see any stress on the CPU and I was up to a 50,000 tap filter before it started to be noticeably choppy and the CPU usage went close to 300%.  So… to recap, normal build and run, I max out at about 35-40 filter taps; profile build and run, I max out at about 50,000 filter taps.
Also worthy of note, while profiling with 50,000 filter taps, the UI still responds instantly and I can change frequency, start / stop the radio and it has choppy audio.  During a normal run, the UI starts to freeze just as soon as I start the radio with no audio, and that happens after I get to only about 50 taps.
Again, why the dramatic difference in CPU usage between between running while profiling, and running just a standard build; what's different aside from the elevated privileges for Instruments and what do I need to do to make it the normal behavior for my app?
JE

A: This is all about build configurations. When you profile an app with Xcode it gets built with optimizations because Xcode uses the "release" build configuration for profiling. As the name suggests, the "release" config is also used on your final product which therefore always is a build optimized for speed. The default "debug" build configuration which comes to play when you build your app in Xcode by pressing ⌘R doesn't apply any compiler optimizations. This is the reason why your app is slower when not being profiled.
You can learn more about build configurations here: https://developer.apple.com/library/mac/recipes/xcode_help-project_editor/Articles/BasingBuildConfigurationsonConfigurationFiles.html#//apple_ref/doc/uid/TP40010155-CH13-SW1


text:
Q: Page for each row with PHP and MySQL I'm making a movie database that's accessible on my local network. I've set up a MySQL database and I have PHP to access the table and to output the results onto a webpage.
I want to have a unique page for each movie/row in the database. I want the webpage to have each value for the movie (title, year, genre, plot, rating)
I've established a connection:
<?php

$username="root"; $password="12345"; $database="videos";

$con1 = mysqli_init();
mysqli_options($con1, MYSQLI_OPT_LOCAL_INFILE, true);
$con = mysqli_real_connect($con1, "localhost", $username, $password, $database);

?>

I have tried the answer from this question: page for each row in mysql
But it does not work. I already have a page to show all the rows in the table, but I'd like a unique page for each row in the table.
Here is the PHP for the table on a single page:
<?php

$username="root"; $password="12345"; $database="videos";

$con = mysqli_init();
mysqli_options($con, MYSQLI_OPT_LOCAL_INFILE, true);
mysqli_real_connect($con, "localhost", $username, $password, $database);

mysqli_select_db($database);

mysqli_query($con, "TRUNCATE TABLE films");
if (!mysqli_query($con, "LOAD DATA LOCAL INFILE '/home/ryan/movies.txt' INTO TABLE films")) {
    printf("Errormessage: %s\n", mysqli_error($con));
}

$result = mysqli_query($con, "SELECT title, yr, genre, plot, rating FROM films") or die("Unable to query.");

echo "
";
echo "
 Title	 Year	 Genre	 Plot	 Rating
";

// keep getting the next row until no rows left
while($row = mysqli_fetch_array( $result )) {
  // print out contents of each row into a table
  echo "
 ";
  echo $row['title'];
  echo "	";
  echo $row['yr'];
  echo "	";
  echo $row['genre'];
  echo "	";
  echo $row['plot'];
  echo "	";
  echo $row['rating'];
  echo "
";
}

echo "
";
?>

A: Are you familiar with get method?
You can use the same layout of a page for each of the movies you have
for example create a page where you want to see every movie you have in the database and when you click in one movie it will redirect to the layout page like so:
<a href='movieLayout.html?movieID=<?php echo movieId; ?>' id='LOTR1' />

with a get method "?movieID=123"specifying what movie you clicked and on top of the layout movie page:
<?php
  if(isset($_GET['ID movie you want to see or name of the movie']){
        send a query to database .."where id_movie =1 " OR "where name_movie LIKE 'LOTR';
  then you receive the path to the file where your movie is and the title of the movie, year, plot, etc..
  }
?>
....

this is all theoretically i can't be more specific


text:
Q: Why does CopyTo throw ArgumentOutOfRangeException? Why does CopyTo cause an exception? The code below it works perfect and is what i thought copyto would do.
using (var mem = new MemoryStream())
{
    using (var memin = new MemoryStream(v.body))
    using (var comp = new BZip2InputStream(memin))
    {
        //comp.CopyTo(mem); //Non-negative number required (System.ArgumentOutOfRangeException)
        var buf = new Byte[1024 * 4];
        int len=0;
        while ((len = comp.Read(buf, 0, buf.Length)) > 0)
        {
            mem.Write(buf, 0, len);
        }

    }

A: Its a bug in BZip2InputStream.Read(byte[] buffer, int offset, int count). It returns -1 rather then 0. I reported the bug
Also CopyTo checks via != 0 rather then >0 as the code in the question does.


text:
Q: loop through a dictionary list and 1) compare a flow value to the flow column element 2) if it matches then append a new list with data I have a data frame
Sensor_Data_df={"Sensor" :[2306,2305,2304,2303,2302 ], "Time" :   [3.06,5.17,6.89,6.83,6.83], "Flow": [60,69,66,104,60]}

I need to loop through a list and compare a flow value to the flow column element and if it matches then append to a new list with the sensor data. There are several thousands of rows of data but only 127 flows. So it seems like a nested loop seems to fit but I'm new to pandas and Python.
Objective is to create a new dictionary list as follows:
flows_df={"60":[2306,2302],"66":[2304],"69":[2305],"104":[2303]}

I need something like this but haven't been able to get the if statement so I can compare a value:
dfc = pd.DataFrame({'A':['aaa','bbb','ccc'],'B':[1,2,3]})
print(dfc)

numrows=len(dfc.loc[:,'A'])

print("The number of elements is " + str(numrows))

z_list=[]
ilist=[0,1,2]
i=0
for i in range(len(dfc['A'])):
#   if dfc[i,'A']==ilist.value()

z_list.append(dfc.loc[:,'B'])

print("____")
print(z_list)

A: If you let df = pd.DataFrame(Sensor_Data_df), then you could do
df.groupby('Flow').Sensor.apply(list).to_dict()

For your example data:
In [164]: df
Out[164]:
   Sensor  Time  Flow
0    2306  3.06    60
1    2305  5.17    69
2    2304  6.89    66
3    2303  6.83   104
4    2302  6.83    60

In [165]: df.groupby('Flow').Sensor.apply(list).to_dict()
Out[165]: {60: [2306, 2302], 66: [2304], 69: [2305], 104: [2303]}

A pure Python solution that would probably also fit the size of your data (unless part of a tight loop) and save you the dependency on pandas would be
from collections import defaultdict

sensors_by_flow = defaultdict(list)
for flow, sensor in zip(Sensor_Data_df['Flow'], Sensor_Data_df['Sensor']):
    sensors_by_flow[flow].append(sensor)

A: Instead of looping through the DataFrame (which is inefficient and generally should be avoided when working with pandas) you can test what flows are in ilist by using .isin() on your flow column.
In your example the relevant values in column A can be extracted like this:
dfc.loc[dfc['B'].isin(ilist), 'A']


text:
Q: Как задать редирект на определенном каталоге сайта? Есть один каталог на сайте, на котором в единичном порядке нужно у второго уровня вложенности убрать все возможные get-параметры. Пример ссылки: site.ru/catalog/row?start=12.
row может всегда меняться, catalog всегда неизменен, но проблема в том, что уже в site.ru/catalog/row/line есть полезные get-параметры


text:
Q: Разбить число на числа входящие в него и создав из них массив Разбить число на числа входящие в него и создав из них массив.
Есть число 120, нужен массив {1},{2},{3},{4},{5},...,{119},{120}.
Тип массива не важен.

Буду премного благодарен, если подскажете.

A: Не совсем понятно задание. Первое и второе предложения противоречат друг другу. Но если по примеру, то вот:
int n = 120;
int[] arr = new int[n];
for (int i = 0; i < n; i ++) {
    arr[i] = i + 1;
}
System.out.println(Arrays.toString(arr));

Очень лаконичный вариант это решения предложили в комментариях.

A: Решение на стримах, предложенное в комментариях:
int[] arr = IntStream.range(0, 120).map(i -> i + 1).toArray();
System.out.println(Arrays.toString(arr));
// [1, 2, 3, 4, 5, ..., 119, 120]

Или проще можно:
int[] arr = IntStream.range(1, 121).toArray();
System.out.println(Arrays.toString(arr));
// [1, 2, 3, 4, 5, ..., 119, 120]

A: Можно использовать метод IntStream.rangeClosed - обход значений из диапазона, включая конечные точки:
int[] arr = IntStream.rangeClosed(1, 120).toArray();
System.out.println(Arrays.toString(arr));
// [1, 2, 3, 4, 5, ..., 119, 120]


text:
Q: Fill Background color from Right to left CSS I am trying to do a background color transition but have been stuck.
My goal is when a button is clicked, I want to transition a background that is half red on the left side and half blue on the right side to slide left and become full blue.
I have attempted it in this jfiddle but I am not sure what I am doing wrong. Any help would be appreciated. Thank you!
https://jsfiddle.net/8Lbw23rt/
HTML code:

test

<button class="test-button" id="test" type="button">Change Color!</button>

CSS Code:
.colorChange {
  width:150px;
  height: 150px;
  padding: 11px 16px;
  text-align:center;
  float:left;
  background: linear-gradient(to right, red 50%, blue 50%);
  background-size: 100% 100%;
  background-position:left bottom;
  margin-left:10px;
  transition:all 2s ease;
  margin-right: 50px;
}

.test-button {
  height: 50px;
  width: 100px;
}

JS Code:
$(function() {
    $('#test').on('click', function() {
        $('.colorChange').css('background-position', 'right bottom');
    })
})

A: Make the background large enough that half of it can cover the entire element, then just move it:

$(function() {
  $('#test').on('click', function() {
    $('.colorChange').css('background-position', 'right bottom');
  })
})
.colorChange {
  width: 150px;
  height: 150px;
  padding: 11px 16px;
  text-align: center;
  float: left;
  /* background: #ff3232; */
  background: linear-gradient(to right, red 50%, blue 50%);
  background-size: 200%;
  background-position: center bottom;
  margin-left: 10px;
  transition: all 2s ease;
  margin-right: 50px;
}

.test-button {
  height: 50px;
  width: 100px;
}

test

<button class="test-button" id="test" type="button">Change Color!</button>

Fiddle


text:
Q: Can't Click on Image Using Selendroid Driver on Android 4.2.2 I am browsing the url:
http://serve.qa.vdopia.com/adserver/html5/inwapads/?sleepAfter=0;adFormat=banner;ak=e833a81e238ce8dc876a5f0a283953c2;version=1.0;cb=[timestamp];output=html.

I am trying to click the image located by xpath=//a/img[1], but I can't click it though I am able to find it successfully. I have tried these options so far, but none of them are successful yet. Any help will be appreciated.
//#1.
    WebElement bannerImage = driver.findElement(By.xpath("//a/img[1]"));
    bannerImage.click();

//#2.
    WebElement bannerImage = driver.findElement(By.xpath("//a/img[1]"));
    TouchActions flick = new TouchActions(driver).flick(bannerImage, -100, 0, 0);
    flick.perform();

//#3.
    String xpath = "//a/img[1]";
    String js = "var targetElement = document.evaluate(\""+xpath+"\",document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue;"
        +"var evt = document.createEvent('UIEvent');"
        +"evt.initUIEvent('touchstart', true, true);"
        +"targetElement.dispatchEvent(evt);";
    ((JavascriptExecutor)driver).executeScript(js);


text:
Q: List directory tree structure in python? I know that we can use os.walk() to list all sub-directories or all files in a directory. However, I would like to list the full directory tree content:
- Subdirectory 1:
   - file11
   - file12
   - Sub-sub-directory 11:
         - file111
         - file112
- Subdirectory 2:
    - file21
    - sub-sub-directory 21
    - sub-sub-directory 22
        - sub-sub-sub-directory 221
            - file 2211

How to best achieve this in Python?

A: Based on this fantastic post
http://code.activestate.com/recipes/217212-treepy-graphically-displays-the-directory-structur/
Here es a refinement to behave exactly like
http://linux.die.net/man/1/tree

#!/usr/bin/env python2
# -*- coding: utf-8 -*-

# tree.py
#
# Written by Doug Dahms
#
# Prints the tree structure for the path specified on the command line

from os import listdir, sep
from os.path import abspath, basename, isdir
from sys import argv

def tree(dir, padding, print_files=False, isLast=False, isFirst=False):
    if isFirst:
        print padding.decode('utf8')[:-1].encode('utf8') + dir
    else:
        if isLast:
            print padding.decode('utf8')[:-1].encode('utf8') + '└── ' + basename(abspath(dir))
        else:
            print padding.decode('utf8')[:-1].encode('utf8') + '├── ' + basename(abspath(dir))
    files = []
    if print_files:
        files = listdir(dir)
    else:
        files = [x for x in listdir(dir) if isdir(dir + sep + x)]
    if not isFirst:
        padding = padding + '   '
    files = sorted(files, key=lambda s: s.lower())
    count = 0
    last = len(files) - 1
    for i, file in enumerate(files):
        count += 1
        path = dir + sep + file
        isLast = i == last
        if isdir(path):
            if count == len(files):
                if isFirst:
                    tree(path, padding, print_files, isLast, False)
                else:
                    tree(path, padding + ' ', print_files, isLast, False)
            else:
                tree(path, padding + '│', print_files, isLast, False)
        else:
            if isLast:
                print padding + '└── ' + file
            else:
                print padding + '├── ' + file

def usage():
    return '''Usage: %s [-f]
Print tree structure of path specified.
Options:
-f      Print files as well as directories
PATH    Path to process''' % basename(argv[0])

def main():
    if len(argv) == 1:
        print usage()
    elif len(argv) == 2:
        # print just directories
        path = argv[1]
        if isdir(path):
            tree(path, '', False, False, True)
        else:
            print 'ERROR: \'' + path + '\' is not a directory'
    elif len(argv) == 3 and argv[1] == '-f':
        # print directories and files
        path = argv[2]
        if isdir(path):
            tree(path, '', True, False, True)
        else:
            print 'ERROR: \'' + path + '\' is not a directory'
    else:
        print usage()

if __name__ == '__main__':
    main()

A: import os

def fs_tree_to_dict(path_):
    file_token = ''
    for root, dirs, files in os.walk(path_):
        tree = {d: fs_tree_to_dict(os.path.join(root, d)) for d in dirs}
        tree.update({f: file_token for f in files})
        return tree  # note we discontinue iteration trough os.walk

If anybody is interested - that recursive function returns nested structure of dictionaries. Keys are file system names (of directories and files), values are either:

*

*sub dictionaries for directories

*strings for files (see file_token)

The strings designating files are empty in this example. They can also be e.g. given file contents or its owner info or privileges or whatever object different than a dict. Unless it's a dictionary it can be easily distinguished from a "directory type" in further operations.
Having such a tree in a filesystem:
# bash:
$ tree /tmp/ex
/tmp/ex
├── d_a
│   ├── d_a_a
│   ├── d_a_b
│   │   └── f1.txt
│   ├── d_a_c
│   └── fa.txt
├── d_b
│   ├── fb1.txt
│   └── fb2.txt
└── d_c

The result will be:
# python 2 or 3:
>>> fs_tree_to_dict("/tmp/ex")
{
    'd_a': {
        'd_a_a': {},
        'd_a_b': {
            'f1.txt': ''
        },
        'd_a_c': {},
        'fa.txt': ''
    },
    'd_b': {
        'fb1.txt': '',
        'fb2.txt': ''
    },
    'd_c': {}
}

If you like that, I've already created a package (python 2 & 3) with this stuff (and a nice pyfakefs helper):
https://pypi.org/project/fsforge/

A: Similar to answers above, but for python3, arguably readable and arguably extensible:
from pathlib import Path

class DisplayablePath(object):
    display_filename_prefix_middle = '├──'
    display_filename_prefix_last = '└──'
    display_parent_prefix_middle = '    '
    display_parent_prefix_last = '│   '

    def __init__(self, path, parent_path, is_last):
        self.path = Path(str(path))
        self.parent = parent_path
        self.is_last = is_last
        if self.parent:
            self.depth = self.parent.depth + 1
        else:
            self.depth = 0

    @property
    def displayname(self):
        if self.path.is_dir():
            return self.path.name + '/'
        return self.path.name

    @classmethod
    def make_tree(cls, root, parent=None, is_last=False, criteria=None):
        root = Path(str(root))
        criteria = criteria or cls._default_criteria

        displayable_root = cls(root, parent, is_last)
        yield displayable_root

        children = sorted(list(path
                               for path in root.iterdir()
                               if criteria(path)),
                          key=lambda s: str(s).lower())
        count = 1
        for path in children:
            is_last = count == len(children)
            if path.is_dir():
                yield from cls.make_tree(path,
                                         parent=displayable_root,
                                         is_last=is_last,
                                         criteria=criteria)
            else:
                yield cls(path, displayable_root, is_last)
            count += 1

    @classmethod
    def _default_criteria(cls, path):
        return True

    @property
    def displayname(self):
        if self.path.is_dir():
            return self.path.name + '/'
        return self.path.name

    def displayable(self):
        if self.parent is None:
            return self.displayname

        _filename_prefix = (self.display_filename_prefix_last
                            if self.is_last
                            else self.display_filename_prefix_middle)

        parts = ['{!s} {!s}'.format(_filename_prefix,
                                    self.displayname)]

        parent = self.parent
        while parent and parent.parent is not None:
            parts.append(self.display_parent_prefix_middle
                         if parent.is_last
                         else self.display_parent_prefix_last)
            parent = parent.parent

        return ''.join(reversed(parts))

Example usage:
paths = DisplayablePath.make_tree(
    Path('doc'),
    criteria=is_not_hidden
)
for path in paths:
    print(path.displayable())

# With a criteria (skip hidden files)
def is_not_hidden(path):
    return not path.name.startswith(".")

paths = DisplayablePath.make_tree(Path('doc'), criteria=is_not_hidden)
for path in paths:
    print(path.displayable())

Example output:
doc/
├── _static/
│   ├── embedded/
│   │   ├── deep_file
│   │   └── very/
│   │       └── deep/
│   │           └── folder/
│   │               └── very_deep_file
│   └── less_deep_file
├── about.rst
├── conf.py
└── index.rst

Notes

*

*This uses recursion. It will raise a RecursionError on really deep folder trees

*The tree is lazily evaluated.  It should behave well on really wide folder trees.  Immediate children of a given folder are not lazily evaluated, though.

Edit:

*

*Added bonus! criteria callback for filtering paths.

A:
List directory tree structure in Python?

We usually prefer to just use GNU tree, but we don't always have tree on every system, and sometimes Python 3 is available. A good answer here could be easily copy-pasted and not make GNU tree a requirement.
tree's output looks like this:
$ tree
.
├── package
│   ├── __init__.py
│   ├── __main__.py
│   ├── subpackage
│   │   ├── __init__.py
│   │   ├── __main__.py
│   │   └── module.py
│   └── subpackage2
│       ├── __init__.py
│       ├── __main__.py
│       └── module2.py
└── package2
    └── __init__.py

4 directories, 9 files

I created the above directory structure in my home directory under a directory I call pyscratch.
I also see other answers here that approach that sort of output, but I think we can do better, with simpler, more modern code and lazily evaluating approaches.
Tree in Python
To begin with, let's use an example that

*

*uses the Python 3 Path object

*uses the yield and yield from expressions (that create a generator function)

*uses recursion for elegant simplicity

*uses comments and some type annotations for extra clarity

from pathlib import Path

# prefix components:
space =  '    '
branch = '│   '
# pointers:
tee =    '├── '
last =   '└── '

def tree(dir_path: Path, prefix: str=''):
    """A recursive generator, given a directory Path object
    will yield a visual tree structure line by line
    with each line prefixed by the same characters
    """
    contents = list(dir_path.iterdir())
    # contents each get pointers that are ├── with a final └── :
    pointers = [tee] * (len(contents) - 1) + [last]
    for pointer, path in zip(pointers, contents):
        yield prefix + pointer + path.name
        if path.is_dir(): # extend the prefix and recurse:
            extension = branch if pointer == tee else space
            # i.e. space because last, └── , above so no more |
            yield from tree(path, prefix=prefix+extension)

and now:
for line in tree(Path.home() / 'pyscratch'):
    print(line)

prints:
├── package
│   ├── __init__.py
│   ├── __main__.py
│   ├── subpackage
│   │   ├── __init__.py
│   │   ├── __main__.py
│   │   └── module.py
│   └── subpackage2
│       ├── __init__.py
│       ├── __main__.py
│       └── module2.py
└── package2
    └── __init__.py

We do need to materialize each directory into a list because we need to know how long it is, but afterwards we throw the list away. For deep and broad recursion this should be lazy enough.
The above code, with the comments, should be sufficient to fully understand what we're doing here, but feel free to step through it with a debugger to better grock it if you need to.
More features
Now GNU tree gives us a couple of useful features that I'd like to have with this function:

*

*prints the subject directory name first (does so automatically, ours does not)

*prints the count of n directories, m files

*option to limit recursion, -L level

*option to limit to just directories, -d
Also, when there is a huge tree, it is useful to limit the iteration (e.g. with islice) to avoid locking up your interpreter with text, as at some point the output becomes too verbose to be useful. We can make this arbitrarily high by default - say 1000.
So let's remove the previous comments and fill out this functionality:
from pathlib import Path
from itertools import islice

space =  '    '
branch = '│   '
tee =    '├── '
last =   '└── '

def tree(dir_path: Path, level: int=-1, limit_to_directories: bool=False,
         length_limit: int=1000):
    """Given a directory Path object print a visual tree structure"""
    dir_path = Path(dir_path) # accept string coerceable to Path
    files = 0
    directories = 0
    def inner(dir_path: Path, prefix: str='', level=-1):
        nonlocal files, directories
        if not level:
            return # 0, stop iterating
        if limit_to_directories:
            contents = [d for d in dir_path.iterdir() if d.is_dir()]
        else:
            contents = list(dir_path.iterdir())
        pointers = [tee] * (len(contents) - 1) + [last]
        for pointer, path in zip(pointers, contents):
            if path.is_dir():
                yield prefix + pointer + path.name
                directories += 1
                extension = branch if pointer == tee else space
                yield from inner(path, prefix=prefix+extension, level=level-1)
            elif not limit_to_directories:
                yield prefix + pointer + path.name
                files += 1
    print(dir_path.name)
    iterator = inner(dir_path, level=level)
    for line in islice(iterator, length_limit):
        print(line)
    if next(iterator, None):
        print(f'... length_limit, {length_limit}, reached, counted:')
    print(f'\n{directories} directories' + (f', {files} files' if files else ''))

And now we can get the same sort of output as tree:
tree(Path.home() / 'pyscratch')

prints:
pyscratch
├── package
│   ├── __init__.py
│   ├── __main__.py
│   ├── subpackage
│   │   ├── __init__.py
│   │   ├── __main__.py
│   │   └── module.py
│   └── subpackage2
│       ├── __init__.py
│       ├── __main__.py
│       └── module2.py
└── package2
    └── __init__.py

4 directories, 9 files

And we can restrict to levels:
tree(Path.home() / 'pyscratch', level=2)

prints:
pyscratch
├── package
│   ├── __init__.py
│   ├── __main__.py
│   ├── subpackage
│   └── subpackage2
└── package2
    └── __init__.py

4 directories, 3 files

And we can limit the output to directories:
tree(Path.home() / 'pyscratch', level=2, limit_to_directories=True)

prints:
pyscratch
├── package
│   ├── subpackage
│   └── subpackage2
└── package2

4 directories

Retrospective
In retrospect, we could have used path.glob for matching. We could also perhaps use path.rglob for recursive globbing, but that would require a rewrite. We could also use itertools.tee instead of materializing a list of directory contents, but that could have negative tradeoffs and would probably make the code even more complex.
Comments are welcome!

A: On top of dhobbs answer above (https://stackoverflow.com/a/9728478/624597), here is an extra functionality of storing results to a file (I personally use it to copy and paste to FreeMind to have a nice overview of the structure, therefore I used tabs instead of spaces for indentation):
import os

def list_files(startpath):

    with open("folder_structure.txt", "w") as f_output:
        for root, dirs, files in os.walk(startpath):
            level = root.replace(startpath, '').count(os.sep)
            indent = '\t' * 1 * (level)
            output_string = '{}{}/'.format(indent, os.path.basename(root))
            print(output_string)
            f_output.write(output_string + '\n')
            subindent = '\t' * 1 * (level + 1)
            for f in files:
                output_string = '{}{}'.format(subindent, f)
                print(output_string)
                f_output.write(output_string + '\n')

list_files(".")

A: This solution will only work if you have tree installed on your system.  However I'm leaving this solution here just in case it helps someone else out.
You can tell tree to output the tree structure as XML (tree -X) or JSON (tree -J).  JSON of course can be parsed directly with python and XML can easily be read with lxml.
With the following directory structure as an example:
[sri@localhost Projects]$ tree --charset=ascii bands
bands
|-- DreamTroll
|   |-- MattBaldwinson
|   |-- members.txt
|   |-- PaulCarter
|   |-- SimonBlakelock
|   `-- Rob Stringer
|-- KingsX
|   |-- DougPinnick
|   |-- JerryGaskill
|   |-- members.txt
|   `-- TyTabor
|-- Megadeth
|   |-- DaveMustaine
|   |-- DavidEllefson
|   |-- DirkVerbeuren
|   |-- KikoLoureiro
|   `-- members.txt
|-- Nightwish
|   |-- EmppuVuorinen
|   |-- FloorJansen
|   |-- JukkaNevalainen
|   |-- MarcoHietala
|   |-- members.txt
|   |-- TroyDonockley
|   `-- TuomasHolopainen
`-- Rush
    |-- AlexLifeson
    |-- GeddyLee
    `-- NeilPeart

5 directories, 25 files

XML
<?xml version="1.0" encoding="UTF-8"?>
<tree>
  <directory name="bands">
    <directory name="DreamTroll">
      <file name="MattBaldwinson"></file>
      <file name="members.txt"></file>
      <file name="PaulCarter"></file>
      <file name="RobStringer"></file>
      <file name="SimonBlakelock"></file>
    </directory>
    <directory name="KingsX">
      <file name="DougPinnick"></file>
      <file name="JerryGaskill"></file>
      <file name="members.txt"></file>
      <file name="TyTabor"></file>
    </directory>
    <directory name="Megadeth">
      <file name="DaveMustaine"></file>
      <file name="DavidEllefson"></file>
      <file name="DirkVerbeuren"></file>
      <file name="KikoLoureiro"></file>
      <file name="members.txt"></file>
    </directory>
    <directory name="Nightwish">
      <file name="EmppuVuorinen"></file>
      <file name="FloorJansen"></file>
      <file name="JukkaNevalainen"></file>
      <file name="MarcoHietala"></file>
      <file name="members.txt"></file>
      <file name="TroyDonockley"></file>
      <file name="TuomasHolopainen"></file>
    </directory>
    <directory name="Rush">
      <file name="AlexLifeson"></file>
      <file name="GeddyLee"></file>
      <file name="NeilPeart"></file>
    </directory>
  </directory>
  <report>
    <directories>5</directories>
    <files>25</files>
  </report>
</tree>

JSON
[sri@localhost Projects]$ tree -J bands
[
  {"type":"directory","name":"bands","contents":[
    {"type":"directory","name":"DreamTroll","contents":[
      {"type":"file","name":"MattBaldwinson"},
      {"type":"file","name":"members.txt"},
      {"type":"file","name":"PaulCarter"},
      {"type":"file","name":"RobStringer"},
      {"type":"file","name":"SimonBlakelock"}
    ]},
    {"type":"directory","name":"KingsX","contents":[
      {"type":"file","name":"DougPinnick"},
      {"type":"file","name":"JerryGaskill"},
      {"type":"file","name":"members.txt"},
      {"type":"file","name":"TyTabor"}
    ]},
    {"type":"directory","name":"Megadeth","contents":[
      {"type":"file","name":"DaveMustaine"},
      {"type":"file","name":"DavidEllefson"},
      {"type":"file","name":"DirkVerbeuren"},
      {"type":"file","name":"KikoLoureiro"},
      {"type":"file","name":"members.txt"}
    ]},
    {"type":"directory","name":"Nightwish","contents":[
      {"type":"file","name":"EmppuVuorinen"},
      {"type":"file","name":"FloorJansen"},
      {"type":"file","name":"JukkaNevalainen"},
      {"type":"file","name":"MarcoHietala"},
      {"type":"file","name":"members.txt"},
      {"type":"file","name":"TroyDonockley"},
      {"type":"file","name":"TuomasHolopainen"}
    ]},
    {"type":"directory","name":"Rush","contents":[
      {"type":"file","name":"AlexLifeson"},
      {"type":"file","name":"GeddyLee"},
      {"type":"file","name":"NeilPeart"}
    ]}
  ]},
  {"type":"report","directories":5,"files":25}
]

A: There is a package (I created) called seedir for doing this and other things with folder tree diagrams:
>>> import seedir as sd
>>> sd.seedir('/path/to/package', style='emoji')
 package/
├─ __init__.py
├─ subpackage1/
│ ├─ __init__.py
│ ├─ moduleX.py
│ └─ moduleY.py
├─ subpackage2/
│ ├─ __init__.py
│ └─ moduleZ.py
└─ moduleA.py

Something similar to the style OP used can be done with:
>>> sd.seedir('/path/to/package', style='spaces', indent=4, anystart='- ')
- package/
    - __init__.py
    - subpackage1/
        - __init__.py
        - moduleX.py
        - moduleY.py
    - subpackage2/
        - __init__.py
        - moduleZ.py
    - moduleA.py

There is also a command-line interface. For example:
seedir -y emoji

For all the options, see
seedir --help

You can also do python -m seedir.

A: A solution without your indentation:
for path, dirs, files in os.walk(given_path):
  print path
  for f in files:
    print f

os.walk already does the top-down, depth-first walk you are looking for.
Ignoring the dirs list prevents the overlapping you mention.

A: Here's a function to do that with formatting:
import os

def list_files(startpath):
    for root, dirs, files in os.walk(startpath):
        level = root.replace(startpath, '').count(os.sep)
        indent = ' ' * 4 * (level)
        print('{}{}/'.format(indent, os.path.basename(root)))
        subindent = ' ' * 4 * (level + 1)
        for f in files:
            print('{}{}'.format(subindent, f))

A: You can execute 'tree' command of Linux shell.
Installation:
   ~$sudo apt install tree

Using in python
    >>> import os
    >>> os.system('tree <desired path>')

Example:
    >>> os.system('tree ~/Desktop/myproject')

This gives you a cleaner structure and is visually more comprehensive and easy to type.

A: I came here looking for the same thing and used dhobbs answer for me. As a way of thanking the community, I added some arguments to write to a file, as akshay asked, and made showing files optional so it is not so bit an output. Also made the indentation an optional argument so you can change it, as some like it to be 2 and others prefer 4.
Used different loops so the one not showing files doesn't check if it has to on each iteration.
Hope it helps someone else as dhobbs answer helped me. Thanks a lot.
def showFolderTree(path,show_files=False,indentation=2,file_output=False):
    """
    Shows the content of a folder in a tree structure.
    path -(string)- path of the root folder we want to show.
    show_files -(boolean)-  Whether or not we want to see files listed.
                            Defaults to False.
    indentation -(int)- Indentation we want to use, defaults to 2.
    file_output -(string)-  Path (including the name) of the file where we want
                            to save the tree.
    """

    tree = []

    if not show_files:
        for root, dirs, files in os.walk(path):
            level = root.replace(path, '').count(os.sep)
            indent = ' '*indentation*(level)
            tree.append('{}{}/'.format(indent,os.path.basename(root)))

    if show_files:
        for root, dirs, files in os.walk(path):
            level = root.replace(path, '').count(os.sep)
            indent = ' '*indentation*(level)
            tree.append('{}{}/'.format(indent,os.path.basename(root)))
            for f in files:
                subindent=' ' * indentation * (level+1)
                tree.append('{}{}'.format(subindent,f))

    if file_output:
        output_file = open(file_output,'w')
        for line in tree:
            output_file.write(line)
            output_file.write('\n')
    else:
        # Default behaviour: print on screen.
        for line in tree:
            print line

A: Maybe faster than @ellockie ( Maybe )

import os
def file_writer(text):
    with open("folder_structure.txt","a") as f_output:
        f_output.write(text)
def list_files(startpath):

    for root, dirs, files in os.walk(startpath):
        level = root.replace(startpath, '').count(os.sep)
        indent = '\t' * 1 * (level)
        output_string = '{}{}/ \n'.format(indent, os.path.basename(root))
        file_writer(output_string)
        subindent = '\t' * 1 * (level + 1)
        output_string = '%s %s \n' %(subindent,[f for f in files])
        file_writer(''.join(output_string))

list_files("/")

Test results in screenshot below:

A: Python2 & Python3:
I saw several answers on here that are much more conscience than my own, however, for my applications, I did not have access to the libraries they relied on. This was my solution to the task. Also, for my application, I needed to know the absolute path for each file so I printed it out along with the file name.
#!/usr/bin/env python
# -*- coding: utf_8 -*-
import os

PIPE = "│"
ELBOW = "└──"
TEE = "├──"
PIPE_PREFIX = "│   "
SPACE_PREFIX = "    "

def list_files(startpath):

    for root, dirs, files in os.walk(startpath):
        break

    tree = []
    for i, file in enumerate(files):
        if i == len(files)-1 and len(dirs) == 0:
            joint = ELBOW
        else:
            joint = TEE
        tree.append('{} {} : {}'.format(joint, file, os.path.join(root, file)))

    for i, dir in enumerate(dirs):
        if i == len(dirs)-1:
            joint = ELBOW
            space = SPACE_PREFIX
        else:
            joint = TEE
            space = PIPE_PREFIX

        tree.append('{} {}/'.format(joint, dir))
        branches = list_files(os.path.join(root,dir))
       for branch in branches:
            tree.append('{}{}'.format(space, branch))

    return tree

if __name__ == '__main__':
    # Obtain top level directory path
    cwd = os.getcwd()
    tree = list_files(cwd)

    string = '../{}/\n'.format(os.path.basename(cwd))
    for t in tree:
        string += '{}\n'.format(t)
    string = string.replace('\n', '\n   ')
    print(string)

The output of the script is:
../TEST_DIR/
├── test.txt : /usr/scripts/TEST_DIR/test.txt
├── a/
│   ├── 1.txt : /usr/scripts/TEST_DIR/a/1.txt
│   ├── 2.py : /usr/scripts/TEST_DIR/a/2.py
│   └── 3.bit : /usr/scripts/TEST_DIR/a/3.bit
├── b/
│   ├── bb/
│   │   ├── 1.txt : /usr/scripts/TEST_DIR/b/bb/1.txt
│   │   ├── 2.py : /usr/scripts/TEST_DIR/b/bb/2.py
│   │   ├── 3.bit : /usr/scripts/TEST_DIR/b/bb/3.bit
│   │   └── bb_copy/
│   │       ├── 1.txt : /usr/scripts/TEST_DIR/b/bb/bb_copy/1.txt
│   │       ├── 2.py : /usr/scripts/TEST_DIR/b/bb/bb_copy/2.py
│   │       ├── 3.bit : /usr/scripts/TEST_DIR/b/bb/bb_copy/3.bit
│   │       └── bb_copy/
│   │           ├── 1.txt : /usr/scripts/TEST_DIR/b/bb/bb_copy/bb_copy/1.txt
│   │           ├── 2.py : /usr/scripts/TEST_DIR/b/bb/bb_copy/bb_copy/2.py
│   │           └── 3.bit : /usr/scripts/TEST_DIR/b/bb/bb_copy/bb_copy/3.bit
│   └── bb_copy/
│       ├── 1.txt : /usr/scripts/TEST_DIR/b/bb_copy/1.txt
│       ├── 2.py : /usr/scripts/TEST_DIR/b/bb_copy/2.py
│       └── 3.bit : /usr/scripts/TEST_DIR/b/bb_copy/3.bit
└── c/

I would appreciate any tips for making this script more streamline, conscience, and robust. I hope this helps.

A: Here you can find code with output like this:
https://stackoverflow.com/a/56622847/6671330
V .
|-> V folder1
|   |-> V folder2
|   |   |-> V folder3
|   |   |   |-> file3.txt
|   |   |-> file2.txt
|   |-> V folderX
|   |-> file1.txt
|-> 02-hw1_wdwwfm.py
|-> 06-t1-home1.py
|-> 06-t1-home2.py
|-> hw1.py

A: For those who are still looking for an answer. Here is a recursive approach to get the paths in a dictionary.
import os

def list_files(startpath):
    for root, dirs, files in os.walk(startpath):
        dir_content = []
        for dir in dirs:
            go_inside = os.path.join(startpath, dir)
            dir_content.append(list_files(go_inside))
        files_lst = []
        for f in files:
            files_lst.append(f)
        return {'name': root, 'files': files_lst, 'dirs': dir_content}

A: @dhobbs's answer is great!
but simply change to easy get the level info
def print_list_dir(dir):
    print("=" * 64)
    print("[PRINT LIST DIR] %s" % dir)
    print("=" * 64)
    for root, dirs, files in os.walk(dir):
        level = root.replace(dir, '').count(os.sep)
        indent = '| ' * level
        print('{}{} \\'.format(indent, os.path.basename(root)))
        subindent = '| ' * (level + 1)
        for f in files:
            print('{}{}'.format(subindent, f))
    print("=" * 64)

and the output like
================================================================
[PRINT LIST DIR] ./
================================================================
 \
| os_name.py
| json_loads.py
| linspace_python.py
| list_file.py
| to_gson_format.py
| type_convert_test.py
| in_and_replace_test.py
| online_log.py
| padding_and_clipping.py
| str_tuple.py
| set_test.py
| script_name.py
| word_count.py
| get14.py
| np_test2.py
================================================================

you can get the level by | count!

A: Just another tree() function, with some features I find useful:

*

*Set max_files to limit the number of files per directory

*Set max_level to limit the depth

*Set sort_by to sort the files and directories, for example sort_by=os.path.getmtime to sort by last-modified date. Default is to sort by name. Note that directories are always shown before files.

*Set indent to set the number of spaces per indent level, default to 4.

from pathlib import Path

def tree(path, *, indent=4, max_files=None, sort_by=None, level=0, max_level=None):
    path = Path(path)
    if not path.is_dir():
        return
    indent_str = " " * indent * level
    print(f"{indent_str}{path.name}/")
    sub_indent_str = " " * indent * (level + 1)
    dir_content = list(path.iterdir())
    subdirs = [filepath for filepath in dir_content if filepath.is_dir()]
    files = [filepath for filepath in dir_content if not filepath in subdirs]
    if max_level is not None and level < max_level:
        for subdir in sorted(subdirs, key=sort_by):
            tree(subdir, indent=indent, max_files=max_files, sort_by=sort_by,
                 level=level + 1, max_level=max_level)
    for idx, filepath in enumerate(sorted(files, key=sort_by)):
        if max_files is not None and idx >= max_files:
            print(f"{sub_indent_str}...")
            break
        print(f"{sub_indent_str}{filepath.name}")

Example output:
some_path/
    some_subdir/
    another_subdir/
        foo.txt
        bar.txt
    big_subdir/
        a00001.txt
        a00002.txt
        a00003.txt
        ...
    deeply_nested/
        max_depth1/
        max_depth2/


text:
Q: Can not install sentry-onpromise using helm chart I trying to install Sentry using helm chart
But error occurs when installing Sentry using the Helm chart: I don't know what the problem is.
This is my helm version and error log
helm version
version.BuildInfo{Version:"v3.10.2", GitCommit:"50f003e5ee8704ec937a756c646870227d7c8b58", GitTreeState:"clean", GoVersion:"go1.19.3"}

~/sentry> helm install sentry sentry/sentry -f values.yaml --debug
install.go:192: [debug] Original chart version: ""
install.go:209: [debug] CHART PATH: /Users/pansukkim/Library/Caches/helm/repository/sentry-17.8.0.tgz

coalesce.go:175: warning: skipped value for kafka.config: Not a table.
client.go:310: [debug] Starting delete for "sentry-sentry-secret" Secret
client.go:128: [debug] creating 1 resource(s)
client.go:128: [debug] creating 61 resource(s)
client.go:310: [debug] Starting delete for "sentry-db-check" Job
client.go:128: [debug] creating 1 resource(s)
client.go:540: [debug] Watching for changes to Job sentry-db-check with timeout of 5m0s
client.go:568: [debug] Add/Modify event for sentry-db-check: ADDED
client.go:607: [debug] sentry-db-check: Jobs active: 0, jobs failed: 0, jobs succeeded: 0
client.go:568: [debug] Add/Modify event for sentry-db-check: MODIFIED
client.go:607: [debug] sentry-db-check: Jobs active: 1, jobs failed: 0, jobs succeeded: 0
client.go:568: [debug] Add/Modify event for sentry-db-check: MODIFIED
client.go:607: [debug] sentry-db-check: Jobs active: 1, jobs failed: 0, jobs succeeded: 0
client.go:568: [debug] Add/Modify event for sentry-db-check: MODIFIED
Error: INSTALLATION FAILED: failed post-install: job failed: DeadlineExceeded
helm.go:84: [debug] failed post-install: job failed: DeadlineExceeded
INSTALLATION FAILED
main.newInstallCmd.func2
    helm.sh/helm/v3/cmd/helm/install.go:141
github.com/spf13/cobra.(*Command).execute
    github.com/spf13/cobra@v1.5.0/command.go:872
github.com/spf13/cobra.(*Command).ExecuteC
    github.com/spf13/cobra@v1.5.0/command.go:990
github.com/spf13/cobra.(*Command).Execute
    github.com/spf13/cobra@v1.5.0/command.go:918
main.main
    helm.sh/helm/v3/cmd/helm/helm.go:83
runtime.main
    runtime/proc.go:250
runtime.goexit
    runtime/asm_amd64.s:1594

kubectl get job
NAME                        COMPLETIONS   DURATION   AGE
sentry-db-check             0/1           8m30s      8m30s
templates-sentry-db-check   0/1           6d21h      6d21h

inspect job event. But I don't know.
kubectl describe job sentry-db-check
Events:
  Type     Reason            Age    From            Message
  ----     ------            ----   ----            -------
  Normal   SuccessfulCreate  8m49s  job-controller  Created pod: sentry-db-check-skvrs
  Normal   SuccessfulDelete  5m41s  job-controller  Deleted pod: sentry-db-check-skvrs
  Warning  DeadlineExceeded  5m41s  job-controller  Job was active longer than specified deadline

kubectl describe job templates-sentry-db-check
Events:           <none>

A: Edit values.yaml and increase activeDeadlineSeconds. Seems like the job sentry-db-check reaches timeout when trying to connect to other components. 1000 worked in my case.
hooks:
  enabled: true
  removeOnSuccess: true
  activeDeadlineSeconds: 1000
  shareProcessNamespace: false


text:
Q: Is there any way Not to detect USB from windows PC? Is there any way Not to detect USB from windows PC?
The USB device should not mount on windows PC ,It should be handled by my application..
Suggestions please...

A: As far as I know there is no way of stopping the mount on the windows PC, however, you could set it up to autorun so that when it is plugged it in attempts to launch your application. This answer has some information on how to do this: https://stackoverflow.com/a/255067
There is also the option to hide a drive in windows by removing is drive letter (http://www.howtogeek.com/97203/how-to-hide-a-drive-in-windows-so-that-no-one-will-know-its-there/) however, this is almost certainly going to stop your application from reading it too.
If this is for a specific security reason then perhaps you could look at encrypting the drive and allowing only the application to decrypt the data. Thus, whilst mounted in windows it will be of little use.
Sorry I couldn't be of much more help.

A: Microsoft provides a utility called devcon for free download.
It's a "Command Line Uility Alternative to Device Manager".
It can actually do many things that I won't get into here, but removing a plug & play device is a simple operation once you know the unique name of the device you want to manipulate.
Refer this to check how to work with it.

A: It sounds like you don't want your device to show up as a drive in My Computer.  In that case, why are you using the Mass Storage Device class at all?  You could make a custom, vendor-specific device and talk to it using control/interrupt/bulk transfers with WinUSB.  You would need to change the Device's USB descriptors to indicate it is a vendor-specific device and not a mass-storage device.


text:
Q: Why is some code still highlight when commented? I was reading a piece of code and noticed that some variables were still highlighted after comments. But when I remove a '*', the code is no longer highlighted. Why is that? What's the difference between the two.Btw,my editor is Visual Studio Code.

when i delete a '*' :


text:
Q: NodeJS convert MYSQL Date I'm struggling a bit with the timeformat that nodejs provides as output.
I do a MYSQL query and get a datetime back (f.e 2020-01-08 20:20:25 is a entry in my DB)
When I get the result from my query the output looks like Wed Jan 08 2020 20:20:25 GMT+0100 (GMT+01:00)
I couldn't find a method to "convert" it back to the format from my database, do you have any solution for this?
Thank you very much.

A: when you create the instance just add the config for use dates as strings
mysql.createConnection({
  dateStrings: true
});

A: I recommend using a third party module named Moment.js.  You can use npm install moment --save to install the module. It helps with date conversion with custom formats.
Below is my code:
const moment = require('moment'); // Importing the Moment.js module

const date = moment(
    "Wed Jan 08 2020 20:20:25 GMT+0100 (GMT+01:00)",
    "ddd MMM DD YYYY HH:mm:ss"
); // This is your query from MySQL

let mydate = date.format("YYYY-MM-DD HH:mm:ss"); // Using moment.format() with the given format, it converts the date

console.log(mydate) // Finally outputting the date to the console

The following code outputs: 2020-01-08 20:20:25


text:
Q: How to get grunt-contrib-copy to ignore folder var developmentFolder = './Development/';
var productionFolder = './Production/';

copy: {
    main: {
        files: [
            {
                expand: true,
                cwd: developmentFolder,
                src: [developmentFolder + "*"],
                dest: productionFolder,
                filter: 'isFile'
            },
            {
                expand: true,
                cwd: developmentFolder,
                src: [
                    developmentFolder + 'lib/images/**',
                    developmentFolder + 'lib/php/**'
                ],
                dest: productionFolder
            }
        ]
    }
}

I currently have this code to copy files from a development folder to a production folder. Whenever I run this grunt copies the Development folder over and sticks it into the Production folder. So I end up with this.
Production
| - Development
| ----- lib
| ------- etc
I want the output to be
Production
| - lib
| --- etc
How can I achieve this?

A: Your task can be simplified to:
copy: {
  main: {
    files: [
      {
        expand: true,
        cwd: 'Development/  ',
        src: '**/*',
        dest: 'Production/'
      }
    ]
  }
}

In result, all the contents of Development directory will be copied to Production directory.


text:
Q: Git pull auto complete OSX Follow some instruction on this site http://denis.tumblr.com/post/71390665/adding-bash-completion-for-git-on-mac-os-x-leopard . I can do git auto complete for MAC OS. However, when I type git pull origin ma (for master), and then tab it takes a long time for git to auto complete to become git pull origin master . I think it connect to the server to get the branch, but I am not sure, is there any way to make it faster and only get the branch on local machine
cd /tmp
git clone git://git.kernel.org/pub/scm/git/git.git
cd git
git checkout v`git --version | awk '{print $3}'`
cp contrib/completion/git-completion.bash ~/.git-completion.bash
cd ~
rm -rf /tmp/git
echo -e "source ~/.git-completion.bash" >> .profile

A: This is necessary by design.  When you are performing a git-pull, the branch name you are pulling from is a remote branch.  It has no choice but to contact the remote repository in order to get the list of possible completions.
You can prove this to yourself if you try to auto-complete a git-push command.  Completing the branch name master will be much quicker because you are pushing a local branch, so you won't need to contact the remote repository.

If you want to make auto-complete always complete using local branch names, then you can change the behavior.  This might only be useful if your local branch names are identical to remote branch names. Edit the file ~/.git-completion.bash and around line 458, look for this code:
fetch)
    if [ $lhs = 1 ]; then
        __gitcomp "$(__git_refs2 "$remote")" "$pfx" "$cur"
    else
        __gitcomp "$(__git_refs)" "$pfx" "$cur"
    fi
    ;;
pull)
    if [ $lhs = 1 ]; then
        __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
    else
        __gitcomp "$(__git_refs)" "$pfx" "$cur"
    fi
    ;;
push)
    if [ $lhs = 1 ]; then
        __gitcomp "$(__git_refs)" "$pfx" "$cur"
    else
        __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
    fi
    ;;
esac

...and change it to this:
fetch)
    if [ $lhs = 1 ]; then
        __gitcomp "$(__git_refs)" "$pfx" "$cur"
    else
        __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
    fi
    ;;
pull)
    if [ $lhs = 1 ]; then
        __gitcomp "$(__git_refs)" "$pfx" "$cur"
    else
        __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
    fi
    ;;
push)
    if [ $lhs = 1 ]; then
        __gitcomp "$(__git_refs)" "$pfx" "$cur"
    else
        __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
    fi
    ;;
esac

(Notice that we changed the "fetch" and "pull" sections to use the same logic as "push". This means it will be looking for local branch names instead of remote branches.)


text:
Q: How to send HTTP POST request from localhost to the nodemailer running on AWS EC2 instance I am new to ReactJS, NodeJS and Linux systems. I am developing React app in which I am creating a contact me form. Once user fills the detials and message, contact form should send me an email on my ID.
I have refered to this link and its working fine on my localhost: https://mailtrap.io/blog/react-contact-form/
Now in order to run my backend part (Express.js + Nodemailer) 24x7, I moved my backend code to the AWS EC2 instance. Using SSH, I run the server and I am listening on port 5000.
port status on Linux server
Here is my code:
code snippet
Is this right way to send post request from my localhost to my backend server?

A: You should probably be using a form inside your react code to handle the post request
<form action="https://amazon-url/your-post-method" action="post">
    <!-- your inputs here -->
    <input type="submit"value="Submit"></input>
</form>

make sure to put name property on every input you want to send in your post if you have  inside the form it Will be sent as a property my_name inside the request body. The form will send the post request for you when you click the Submit button.
Another alternative is to use a custom js like you are using in your code method, for this you could use a Library such as Ajax or arios to send your request or the default fetch js api, your code should work just fine


text:
Q: How catch iframe resize event from inside the iframe (iframe and the page - same domain) I try to listen from inside of iframe to changes of iframe width/height with:
$(window).resize(function(){
    alert('1 on inside iframe');
});

or:
$(window.parent).find('iframe').resize(function(){
    alert('2 on inside iframe');
});

but nothing happens when iframe size changes. (I need a cross-browser solution: IE7, Chrome, Firefox, Safari.)

A: $(body).resize(function(){
    alert('on inside iframe');
});

Edit :

in html
<body onresize="myFunction()">

A: You need to call the resize() handler from the parent document on the iframe:
$('iframe').resize(function() {} );

A: Try that : http://www.iframehtml.com/iframe-scripts.html#resizeable-iframe
Or that : http://css-tricks.com/snippets/jquery/fit-iframe-to-content/


text:
Q: Reading filesystem and returning it In PHP I know how to read a file. However, I want the script to be able to return the contents of the file to be downloaded.
For example:
http://example.com/myfiles.php?source=images.zip
I need myfiles.php to returns the headers of zip file followed by its contents.

A: You need to change the headers in myfiles.php script file so it will force it to download:
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=images.zip");
header("Content-Type: application/zip");
header("Content-Transfer-Encoding: binary");


text:
Q: *args in Python in combination with numpy.add() import numpy as np

a = np.array([1.2, 5.4, 6, 1.5, 9])
b = np.array([5.2, 1.0, 1.2, 1.5, 2])

def sum_arrays(*array: np.array):
    return np.add(array)

print(sum_arrays(*a, *b))

Is there a way to add two arrays together with add function, using variable arguments? I know this example is wrong, but it's just to get the idea

A: If all you want to do is add the arrays component-wise, you can use +, which works on numpy arrays.
a + b

Alternatively, as you've already pointed out, you can use np.add instead.
np.add(a, b)

If you want to sum all of the elements in both arrays, then again the simplest solution is the best: sum them both separately then add them
a.sum() + b.sum()

There's no need to use variable arguments here; numpy handles the vectorization for you, and unpacking everything into a Python tuple is just counterproductive.


text:
Q: 404 returned when trying to access url (Kubernetes/Helm/Ingress) The problem
I'm currently working on a webAPI which I have an nginx ingress controller controlling traffic to my cluster.
I have got it 90% working where the paths for pgweb (http://lnd.local/pgweb) and grafana (http:lnd.local/grafana) are working.
But I have an express server that handles requests to (http://lnd.local/wallets/?) and I am currently getting 404 responses from this address.
I expect to be able to perform REST requests to this endpoint.
Currently I don't have any specific error messages besides the 404. I have checked that that services for the express server exist and so does the ingress (will attach screenshots).
What I've tried
I have been double checking my other ingress and seeing if I'm missing something and was looking in the ingress logs but am yet to find anything.
My Code
Express Service
apiVersion: v1
kind: Service
metadata:
  name: {{ .Chart.Name }}-node-service
  labels:
    app: {{ .Chart.Name }}-node-service
spec:
  type: NodePort
  ports:
    - protocol: TCP
      port: {{ .Values.walletApi.port }}
      targetPort: {{ .Values.walletApi.port }}
  selector:
    app: {{ .Chart.Name }}-node-deployment

Deployoment File for Express service
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Chart.Name }}-node-deployment
  labels:
    app: {{ .Chart.Name }}-node-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: {{ .Chart.Name }}-node-deployment
  template:
    metadata:
      labels:
        app: {{ .Chart.Name }}-node-deployment
      annotations:
          prometheus.io/scrape: "true"
          prometheus.io/path: /metrics
          prometheus.io/port: "{{ .Values.walletApi.port }}"
    spec:
      containers:
        - name: node
          image: node-wallet:{{ $.Chart.Version }}
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: {{ .Values.walletApi.port }}
          env:
            - name: CLUSTER_DB_HOST
              value: "{{ .Values.clusterDb.host }}"
            - name: CLUSTER_DB_PORT
              value: "{{ .Values.clusterDb.port }}"
            - name: CLUSTER_DB_NAME
              value: wallet

Ingress.yaml for pgweb and express server
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: wallet-server
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  rules:
  - host: "lnd.local"
    http:
      paths:
      - path: /wallets(/|$)(.*)
        pathType: Prefix
        backend:
          service:
            name: {{ $.Chart.Name }}-node-service
            port:
              number: {{ $.Values.walletApi.port }}
      - path: /pgweb/?(.*)
        pathType: Prefix
        backend:
          service:
            name: {{ $.Chart.Name }}-pgweb-svc
            port:
              number: {{ $.Values.pgWebApi.port }}
      - path: /static/?(.*)
        pathType: Prefix
        backend:
          service:
            name: {{ $.Chart.Name }}-pgweb-svc
            port:
              number: {{ $.Values.pgWebApi.port }}

IngressNginx
ingress-nginx:
  controller:
    kind: DaemonSet
    hostPort:
      enabled: true

kubectl describe ingress -A output
kubectl describe ingress output
Conclusion
I'm hoping I'm just missing something small. But I would appreciate any help. I'm stilling learning about Ingress and would love some advice.
If there are any other clarifications I can add feel free to chuck me a comment.


text:
Q: Google Compute Engine - Error updating SSH keys for root: mkdir /root/.ssh: read-only file system I run on google compute engine with container and every time I view the logs, I get many occurnces of:
Adding existing user root to google-sudoers group.
Updating keys for user root.
Error updating SSH keys for root: mkdir /root/.ssh: read-only file system.
Any Idea why and how to solve it?

A: Container-optimized OS (COS) images have a read-only root file system by design, the error message appears to be because a SSH key for root was added to the project's metadata.
Once the root key is in the metadata database, the agent tries to update the keys for the user root, whose home directory is on the root file system, here is some more information about COS filesystem.
You can check the project's metadata by running the following gcloud command:
gcloud compute project-info describe

Or by navigating to Metadata from the Console UI.
If you wish to remove the root key (it might not be the best approach as it might impact on the rest of the VMs in the project), you can follow this documentation on how to do it.
An alternative option would be to block project metadata ssh keys for the affected VMs.


text:
Q: To maintain the time relation between 2 actions, is it necessary to backshift the first verb No,  I received his last email about 12 days ago.  He said that he had not forgotten me  and was trying to find some other stuff.
the second sentence is reported speech:the direct speech was
"I did not forget you and I am trying to find some stuff "
Do you think the tenses are well chosen?
I am not sure for the first one; may be to backshift was not necessary because at the time of reporting it was still true . But the first action of not forgetting began a long time before before the trying so, it is better to maintain the time relation between these 2 actions and  to choose past perfect

A:
Do you think the tenses have been properly chosen?

Yes. It does look correct. This is a good application of  past perfect.


text:
Q: Разбить строку после второй запятой Было:
text = "Екатеринбург (г),Славинская (ул),д.17,кв.161"

Стало:
text1 = "Екатеринбург (г),Славинская (ул),"
text2 = "д.17,кв.161"

Пока не понимаю, как это можно регулярками сделать.

A: Вам обязательно регулярки нужны? Можно и без них довольно просто сделать:
text = "Екатеринбург (г),Славинская (ул),д.17,кв.161"
text_split = text.split(',')
text1 = ','.join(text_split[:2])
text2 = ','.join(text_split[2:])

A: как вариант можете попробовать такой код, он создаст вам словарь:
from re import fullmatch

txt = "Екатеринбург (г),Славинская (ул),д.17,кв.161"
m = fullmatch(r'(?P<text1>.*?,.*?),(?P<text2>.*)', txt).groupdict()

>>> m
# {'text1': 'Екатеринбург (г),Славинская (ул)', 'text2': 'д.17,кв.161'}


text:
Q: Why does enabling intarray extension on PostgreSQL cause 10x performance degradation? Here's a log of what I run.
With intarray off, it runs in 56ms.
I then enable intarray, and run the same query, and it's much slower.
Do I need to reindex the table, or something like that after enabling the extension?
test_int=# explain analyze select * from tutor_topic tt1 where tt1.topic_id @> '{5,7,8,9}';
                                                      QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------
 Seq Scan on tutor_topic tt1  (cost=0.00..29742.00 rows=1000 width=105) (actual time=24.903..1937.480 rows=68 loops=1)
   Filter: (topic_id @> '{5,7,8,9}'::integer[])
   Rows Removed by Filter: 999932
 Planning time: 0.084 ms
 Execution time: 1937.521 ms
(5 rows)

Time: 1938.000 ms
test_int=# DROP EXTENSION intarray;                                                                                DROP EXTENSION
Time: 10.516 ms
test_int=# explain analyze select * from tutor_topic tt1 where tt1.topic_id @> '{5,7,8,9}';
                                                            QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------
 Bitmap Heap Scan on tutor_topic tt1  (cost=108.78..487.18 rows=100 width=105) (actual time=55.063..55.138 rows=68 loops=1)
   Recheck Cond: (topic_id @> '{5,7,8,9}'::integer[])
   Heap Blocks: exact=68
   ->  Bitmap Index Scan on message_rdtree_idx  (cost=0.00..108.75 rows=100 width=0) (actual time=55.047..55.047 rows=68 loops=1)
         Index Cond: (topic_id @> '{5,7,8,9}'::integer[])
 Planning time: 0.196 ms
 Execution time: 55.180 ms
(7 rows)

Time: 56.095 ms
test_int=#

This is the schema for the tutor_topic table;
CREATE TABLE IF NOT EXISTS tutor_topic
(
      tutor_id              INT NOT NULL,
      topic_id              INT[]
);

These are the indices:
ALTER TABLE tutor_topic ADD FOREIGN KEY (tutor_id) REFERENCES tutor(tutor_id);
CREATE INDEX ON tutor_topic (tutor_id);
CREATE INDEX message_rdtree_idx ON tutor_topic USING GIN (topic_id)

 Schema |           Name            | Type  | Owner  |    Table
--------+---------------------------+-------+--------+-------------
 public | message_rdtree_idx        | index | xxxxxx | tutor_topic
 public | topic_pkey                | index | xxxxxx | topic
 public | tutor_pkey                | index | xxxxxx | tutor
 public | tutor_topic_tutor_id_idx  | index | xxxxxx | tutor_topic
 public | tutor_topic_tutor_id_idx1 | index | xxxxxx | tutor_topic

A: I figured out the answer!
When creating the index, I need to specify the function from the extension:
CREATE INDEX message_rdtree_idx ON tutor_topic USING GIN (topic_id gin__int_ops);
Now performance matches. From the explain analyze call, it appears it was not using the index at all.


text:
Q: How to delay retrying to send an HTTP request with RxJS5? I'm having problems with making an RxJS5 observable stream behave in a way that I want it to.
The stream is supposed to send an HTTP request to a website using axios, and if the response is an HTTP error (which axios coerces to a JavaScript error), the observable sequence should wait 10 milliseconds and then try resending the request (for some reason the website that I'm sending the request to doesn't like it when you retry sending the request immediately and keeps throwing errors, but mostly behaves fine with a 10 ms delay).
Rx.Observable
  .fromPromise(axios('http://example.com/12345'))
  .map(x => new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve(x)
    }, 2000)
  }))
  .debounceTime(2000)
  .do(console.log)
  .retry(10)
  .subscribe(console.log, console.error)

I have an example on Codepen with a few changes, to make it more apparent, how the stream works: http://codepen.io/leakyabstractions/pen/pNmvyZ?editors=0010
I tried using .delay(), .debounceTime(), .timer(), .timeInterval() and .timeout() in the place of the .map() operator, but nothing (including .map()) works. What am i doing wrong?

A: So basically what you are looking for is a "retry after 10ms, but only 10 times"? (this is what your retry(10) suggests.
I think a sophisticated solution would include retryWhen here:
const mockedRestError$ = Rx.Observable.throw("http://example.com/12345");

// we'll start with an empty string, because otherwhise
// we could not log the "start..."
Rx.Observable.of("")
  .do(() => console.log("start..."))
  .switchMapTo(mockedRestError$)
  .retryWhen(tenTimesWithDelay)
  .subscribe(console.log, console.error, console.info); // is never called, because

function tenTimesWithDelay(errors) {
  return errors
    .scan((count, err) => {
      ++count;
      // optionally to throw the error all the way down to the subscription
      // comment the throw out to have the stream simply complete
      if (count >= 10) {
        throw err;
      }
      return count;
    }, 0)
    .takeWhile(count => count < 10)
    .do(count => console.log(`Retry #${count} in 100ms...`))
    .delay(100);
}

Here is the code-pen: http://codepen.io/anon/pen/bBydwZ?editors=0010
Please also note, that I set the delay to 100ms instead of 10ms just so it shows a little cleaner in the console.

A: olsn's answer worked, however I'd like to share another solution that I accidentally came up with, which to my mind is a bit more straight forward:
console.log('start')
Rx.Observable
// emit observable every 10 ms, change to a bigger number to observe results
.interval(10)
// start immediately
.startWith(0)
// do it 10 times
.take(10)
.do(x => console.log('emitting', x))
// for every observable emitted, do an HTTP request
.flatMap(() => new Promise((resolve, reject) => resolve('resolved promise')))
.first(x => !(x instanceof Error))
.subscribe(console.log, console.warn, () => console.info('done'))


text:
Q: Can a for loop be declared like this? for(int i(5) ; i-->0 ; )
{
  //use i as iterator here
}
Is this the same as
for(int i=5; i>0 ; i--) ??
I tried to find similar declarations in google but didn't find anything
Also please suggest cleaner ways to declare the same thing ?

A: No these aren't the same.  In the first case, i will be decremented before the loop body is executed for the first time.
See http://ideone.com/AbHF3m for a working demo.

A: It's not the same. In the first case, the value of i will be 4 in the first iteration and 0 in the last one. In the second case, i will be 5 in the first iteration and 1 in the last one.
Edit
For @Y.Ecarri:
First case:

*

*Set i to 5

*Compare i > 0, that is, 5 > 0

*Decrement i. i is now 4

*Enter body of loop with i having value 4

*Body finishes

Second case:

*

*Set i to 5

*Compare i > 0, that is, 5 > 0

*Enter body of loop with i having value 5

*Body finishes

*Decrement i. i is now 4

A: No, it's not the same. The first version compares the value of i before the decrement, and performs the decrement before each iteration; the second compares the value after the decrement, and performs the decrement after each iteration.
So the first iterates over {4,3,2,1,0}, while the second iterates over {5,4,3,2,1}.

A: They are not the same as others have pointed out as order is:

*

*first part of the for loop (before first semicolon) is evaluated once only at the start.

*Second section is evaluated prior to the block of the code, which will not be evaluated at all of the second section returns a zero-value (false, null pointer or 0 numeric). Within this section which parses as i-- > 0, the comparison takes place before the decrement, as it is a post-decrement operator. Thus when i was initially 1 it will be true, but then i will decrement to 0 for what comes next which is

*The body of the loop.

*The 3rd part of the for loop is executed at the end of the block of the loop if it is not abnormally terminated (with break or return).

If i is a signed int as here so it can reach -1, you can replace with
for( int i=4; i >= 0; --i ) { // body

which looks a bit more obvious in its intention. If you have an unsigned int e.g. size_t, you can still make it look a bit more obvious in its intent by switching the order
for( size_t i = 5; 0 < i--; ) { // body

You can also remove the 0 and the comparison altogether and just do
for( size_t i = 5; i--; ) { // body

In both of the above two I am still uncomfortable with the fact that you start i=5 when you really want it to start as 4 for the first iteration. So I might even switch to do...while.. Of course I have to initialise i outside the loop.
size_t i = 5;
do { // body
    --i; // clearly 4 now on first iteration
} while( i != 0 );


text:
Q: Use decision variable only in constraint Gurobi Java Usually in Gurobi's Java interface I create the model by adding variables to the model with this for example:
for (int i = 0; i < n; i++){
    for (int j = 0; j < n; j++) {
        XobjectiveCoef = distance(i, j);
        X[i][j] = model.addVar(0.0, 1.0, XobjectiveCoef, GRB.BINARY, "x" + String.valueOf(i) + "_" + String.valueOf(j));

    }
}

When I am done I have my model which is the sum of all Xs over i and j, and I can use X[i][j] in any constraint I want with something like this:
for (int j = 0; j < n; j++) {
    GRBLinExpr expr = new GRBLinExpr();
    for (int i = 0; i < n; i++){
        expr.addTerm(1.0, X[i][j]);
    }
    model.addConstr(expr, GRB.EQUAL, 1.0, "Name_of_constraint");
}

Now what I am  looking for, is a way to use decision variable only in a constraint and not in the model definition. I checked if addVar is available for GRBLinExpr but it is not.
Thanks

A: You can create a GRBLinExpr and reuse it.  For example:
model.addConstr(expr, GRB.EQUAL, 1.0, "ct1");
expr.addTerm(1.0, Y);
expr.addTerm(1.0, Z).
model.addConstr(expr, GRB.GREATER_EQUAL, 2.0, "ct2");

This may or may not be more efficient than creating a new GRBVar object.


text:
Q: How to check if any or all of gridview column values exists in a Datatable I have a Datatable that consists of more than 1000 record and a gridview that contains multiple records.I want to check if values present in grid view column  for ex:- "AID" exists in datatable's AID column values. If any value of the gridview AID exists in Datatable AID i want to set a bool flag to true if no value exists in Datatable then to false.I want to check all values at a time, not one by one using for loop etc.I have tried the folowing code
List<string> lstInvdiscItem = (from row in dtinv.AsEnumerable()
                                    select Convert.ToString(row["AID"])).ToList();
foreach (DataGridViewRow row in GrdItDetail.Rows)
{
    string invdiscitem = row.Cells["AID"].Value.ToString();
    int result = dtinv.Rows.IndexOf(dtinv.AsEnumerable().Where(g => g.Field<String>(0) == invdiscitem).FirstOrDefault());

    if (result >= 0)
    {
        DiscFlag = true;
    }
}

But above code checks one value at a time.My requirement is to check all values at a time just as we do using "IN" clause in sqlserver.
How can I achieve this task using c#.Any ideas? Any suggestions?