Python threading perforance

Question: I would like to use python multiple threading capability for my app, but had some performance issue (my guess). The site is hosted on GAE and it talks to a REST server based on EC2 to do some calculations. The REST server is powered by bottlepy.
My question is:
On the GAE side, I have a loop which calls the REST server multiple times to do the calculation. To improve performance, I use threading library. But I found some of the calculations are missing. Usually, I do not have this issue if only twenty jobs are fired, but I do have this issue when 200 jobs are fired. I appreciate any suggestions.
Here is my code:
def my_function():
    ...
    response = urlfetch.fetch(url=url, payload=data, method=urlfetch.POST, headers=http_headers, deadline=60)

#In this loop, I use the Thread to enable multiple threading
def loop_fun():
    for i in range(100):
        p=Thread(target = my_function)
        all_threads.append(p)
    # Start all threads
    [x.start() for x in all_threads]
    # Wait for all of them to finish
    [x.join() for x in all_threads]

Below is the error message for one job (usually I receive sever this type error message):
Exception in thread Thread-12:

Traceback (most recent call last):

  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\dist27\threading.py", line 569, in __bootstrap_inner

    self.run()

  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\dist27\threading.py", line 522, in run

    self.__target(*self.__args, **self.__kwargs)

  File "D:\Dropbox\ubertool_src\genee\genee_model.py", line 102, in __init__

    response = urlfetch.fetch(url=url, payload=data, method=urlfetch.POST, headers=http_headers, deadline=60)

  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\urlfetch.py", line 270, in fetch

    return rpc.get_result()

  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\apiproxy_stub_map.py", line 612, in get_result

    return self.__get_result_hook(self)

  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\urlfetch.py", line 403, in _get_fetch_result

    raise DownloadError("Unable to fetch URL: " + url + error_detail)

DownloadError: Unable to fetch URL: http://url_20140122160100678000 Error: [Errno 10061] No connection could be made because the target machine actively refused it

Comment: Is it possible that the web server is refusing the connection because it's overloaded? What you've described doesn't sound like a Python/threading problem. You could `try:` the fetch and complain when an exception occurred. That way, you'd be able to tell how many of the fetch attempts succeeded and how many failed. If some succeed and some fail, the problem is likely not with Python.
Comment: @mojo: That sounds reasonable. I am using bottlepy. Any suggestions on how to find that out?
Comment: @mojo: Thanks. If the bottle neck is on the REST server side, should I reduce the number of tasks fired at a time?
Comment: Have you tried performing these requests using async fetches rather than threads.  I would suggest you might find it simpler and potentially better performing. In your case you are spending all your time waiting on the remote server and async requests will do that fine.
Answer: If the problem is one of overload, this problem might benefit from a "pool of workers" strategy.
import threading
import Queue

def worker( jobs ):
    while True:
        url = jobs.get()
        if url is None:
            break

        # do stuff with the URL

if __name__ == '__main__':
    thread_count = 30

    job_q = Queue.Queue()

    pool = [ threading.Thread(target=worker,args=(job_q,))
             for i in range(thread_count) ]
    for p in pool:
        p.start()

    for url in urls_to_get:
        job_q.put(url)

    # Signal each thread that there are no more jobs.
    for p in pool:
        job_q.put(None)

    for p in pool:
        p.join()

This way, you can control how many simultaneous requests are taking place by limiting the quantity of threads.
FYI: Python is not really good at threading (depending on the interpreter). Some interpreters have a Global Interpreter Lock that prevent multiple threads from running at once. Threading works OK for I/O bound tasks, but not for making efficient use of the CPU. For simultaneity, use multiprocessing. The changes to my (untested) sample code above would be to use multiprocessing instead of threading and create a Process instead of a Thread.
Comment: Last question. You can have any number of threads and they all process jobs from the same job queue? Also `threading.Queue()` should be `Queue.Queue()`
Comment: Thanks for the detailed answer! Is the sequence of `job_q.put(url) loop` and `p.start() loop` correct? Sorry, this is my first time using python multiple-threading.
Comment: I always start the (thread/process) listeners before I put jobs in the queue so that any startup overhead takes place while the main thread is preparing the jobs. The order isn't otherwise important.
Comment: Thanks for pointing out the errors. I wasn't in a position to actually test the code when I wrote it. Yes, any number of threads all use the _same_ queue.
Comment: Sure, but it is `import Queue`.

Python threading perforance


Problem Updating - linux-image-extra-4.4.0-72-generic

Question: Any ideas how to fix this?
I tried using autoclean, rebooting, and manuallt deleting linux-image-extra-4.4.0-72-generic from /boot and nothing helps.
sudo aptitude upgrade -f
<code>The following partially installed packages will be configured:
  initramfs-tools linux-image-extra-4.4.0-72-generic linux-image-extra-4.4.0-78-generic linux-signed-generic
  linux-signed-image-generic
No packages will be installed, upgraded, or removed.
0 packages upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B of archives. After unpacking 0 B will be used.
Setting up initramfs-tools (0.122ubuntu8.8) ...
update-initramfs: deferring update (trigger activated)
Setting up linux-image-extra-4.4.0-72-generic (4.4.0-72.93) ...
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-72-generic /boot/vmlinuz-4.4.0-72-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-72-generic /boot/vmlinuz-4.4.0-72-generic
update-initramfs: Generating /boot/initrd.img-4.4.0-72-generic
W: mdadm: /etc/mdadm/mdadm.conf defines no arrays.

gzip: stdout: No space left on device
E: mkinitramfs failure find 141 cpio 141 gzip 1
update-initramfs: failed for /boot/initrd.img-4.4.0-72-generic with 1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
dpkg: error processing package linux-image-extra-4.4.0-72-generic (--configure):
 subprocess installed post-installation script returned error exit status 1
Setting up linux-image-extra-4.4.0-78-generic (4.4.0-78.99) ...
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-78-generic /boot/vmlinuz-4.4.0-78-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-78-generic /boot/vmlinuz-4.4.0-78-generic
update-initramfs: Generating /boot/initrd.img-4.4.0-78-generic
W: mdadm: /etc/mdadm/mdadm.conf defines no arrays.

gzip: stdout: No space left on device
E: mkinitramfs failure find 141 cpio 141 gzip 1
update-initramfs: failed for /boot/initrd.img-4.4.0-78-generic with 1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
dpkg: error processing package linux-image-extra-4.4.0-78-generic (--configure):
 subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of linux-signed-image-generic:
 linux-signed-image-generic depends on linux-image-extra-4.4.0-78-generic; however:
  Package linux-image-extra-4.4.0-78-generic is not configured yet.

dpkg: error processing package linux-signed-image-generic (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                dpkg: dependency problems prevent configuration of linux-signed-generic:
 linux-signed-generic depends on linux-signed-image-generic (= 18.104.22.168.84); however:
  Package linux-signed-image-generic is not configured yet.

dpkg: error processing package linux-signed-generic (--configure):
 dependency problems - leaving unconfigured
No apport report written because MaxReports is reached already
                                                              Processing triggers for initramfs-tools (0.122ubuntu8.8) ...
update-initramfs: Generating /boot/initrd.img-4.4.0-78-generic
W: mdadm: /etc/mdadm/mdadm.conf defines no arrays.

gzip: stdout: No space left on device
E: mkinitramfs failure find 141 cpio 141 gzip 1
update-initramfs: failed for /boot/initrd.img-4.4.0-78-generic with 1.
dpkg: error processing package initramfs-tools (--configure):
 subprocess installed post-installation script returned error exit status 1
No apport report written because MaxReports is reached already
                                                              Errors were encountered while processing:
 linux-image-extra-4.4.0-72-generic
 linux-image-extra-4.4.0-78-generic
 linux-signed-image-generic
 linux-signed-generic
 initramfs-tools
E: Sub-process /usr/bin/dpkg returned an error code (1)
Failed to perform requested operation on package.  Trying to recover:
Setting up linux-image-extra-4.4.0-72-generic (4.4.0-72.93) ...
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-72-generic /boot/vmlinuz-4.4.0-72-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-72-generic /boot/vmlinuz-4.4.0-72-generic
update-initramfs: Generating /boot/initrd.img-4.4.0-72-generic
W: mdadm: /etc/mdadm/mdadm.conf defines no arrays.

gzip: stdout: No space left on device
cpio: write error: Broken pipe
find: 'standard output': Broken pipe
find: write error
E: mkinitramfs failure find 1 cpio 1 gzip 1
update-initramfs: failed for /boot/initrd.img-4.4.0-72-generic with 1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
dpkg: error processing package linux-image-extra-4.4.0-72-generic (--configure):
 subprocess installed post-installation script returned error exit status 1
Setting up initramfs-tools (0.122ubuntu8.8) ...
update-initramfs: deferring update (trigger activated)
Setting up linux-image-extra-4.4.0-78-generic (4.4.0-78.99) ...
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-78-generic /boot/vmlinuz-4.4.0-78-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-78-generic /boot/vmlinuz-4.4.0-78-generic
update-initramfs: Generating /boot/initrd.img-4.4.0-78-generic
W: mdadm: /etc/mdadm/mdadm.conf defines no arrays.

gzip: stdout: No space left on device
cpio: write error: Broken pipe
find: 'standard output': Broken pipe
find: write error
E: mkinitramfs failure find 1 cpio 1 gzip 1
update-initramfs: failed for /boot/initrd.img-4.4.0-78-generic with 1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
dpkg: error processing package linux-image-extra-4.4.0-78-generic (--configure):
 subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of linux-signed-image-generic:
 linux-signed-image-generic depends on linux-image-extra-4.4.0-78-generic; however:
  Package linux-image-extra-4.4.0-78-generic is not configured yet.

dpkg: error processing package linux-signed-image-generic (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of linux-signed-generic:
 linux-signed-generic depends on linux-signed-image-generic (= 188.8.131.52.84); however:
  Package linux-signed-image-generic is not configured yet.

dpkg: error processing package linux-signed-generic (--configure):
 dependency problems - leaving unconfigured
Processing triggers for initramfs-tools (0.122ubuntu8.8) ...
update-initramfs: Generating /boot/initrd.img-4.4.0-78-generic
W: mdadm: /etc/mdadm/mdadm.conf defines no arrays.

gzip: stdout: No space left on device
cpio: write error: Broken pipe
find: 'standard output': Broken pipe
find: write error
E: mkinitramfs failure find 1 cpio 1 gzip 1
update-initramfs: failed for /boot/initrd.img-4.4.0-78-generic with 1.
dpkg: error processing package initramfs-tools (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 linux-image-extra-4.4.0-72-generic
 linux-image-extra-4.4.0-78-generic
 linux-signed-image-generic
 linux-signed-generic
 initramfs-tools
</code>
Answer: Unless your /boot partition is incredibly small it should be able to handle more than two versions of the kernel.  I see a "no space left on device" error but not sure if that relates to a kernel upgrade or something else.  If /boot is full, look for some really big file that obviously doesn't belong there and move it to a temporary location such as in your /home directory.
If by "manually deleted" 18.104.22.168 or parts of it you mean you did a "rm" on individual files you could have problems.  Assuming you didn't do that. see what version of the kernel you are currently running.  If it is not newer than 188.8.131.52, reboot.  It's not clear (at least to me) if your upgrade to 184.108.40.206 was successful.
uname -a
Get rid of oldest kernel version
sudo apt-get purge linux-image-220.127.116.11-generic
sudo apt autoremove -- purge
The above will work in most cases.  Since you manually deleted a portion of the 188.8.131.52 kernel, you will be getting complaints every time you try to do an upgrade.  You need to make apt happy again.  Try these commands:
sudo dpkg -P linux-image-4.4.0-72-generic
This tells the system to delete the package. This is likely to result in a complaint about broken dependencies. In this case, you should add the package(s) it claims as being dependent on the old kernel you just tried to remove.  In your case, this would be dependencies such as
sudo dpkg -P linux-image-extra-4.0.0-72-generic
And so on.
Again, be sure to do a uname -a and verify what version of the kernel you are currently running before deleting anything!
Comment: Unfortunately, I did  "rm" to remove some files.
Comment: Unfortunately, I did  "rm" to remove some files.

uname -a

    Linux nuc 4.4.0-78-generic #99-Ubuntu SMP Thu Apr 27 15:29:09 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

sudo apt-get purge linux-image-22.214.171.124-generic

I get this - https://pastebin.com/SE2xJmd6

sudo apt autoremove --purge

I get this - https://pastebin.com/mzsvrUkv
Comment: If /boot is completely full, try removing the oldest kernel version that you HAVEN'T fiddled with by manually deleting anything.   This looks like sudo dpkg -P linux-image-4.4.0-62-generic
Comment: sudo dpkg -P linux-image-4.4.0-62-generic

dpkg: dependency problems prevent removal of linux-image-4.4.0-62-generic:
 linux-image-extra-4.4.0-62-generic depends on linux-image-4.4.0-62-generic.
 linux-signed-image-4.4.0-62-generic depends on linux-image-4.4.0-62-generic (= 4.4.0-62.83).

dpkg: error processing package linux-image-4.4.0-62-generic (--purge):
 dependency problems - not removing
Errors were encountered while processing:
 linux-image-4.4.0-62-generic


issue to Export to Excel from datagrid in Silverlight

Question: I bind a paged collection view to datagrid. When I export to Excel that datagrid, it only exports visible page's data, not all Item source (all records).
ex- my code-
<code> PagedCollectionView page = new PagedCollectionView(_leads);
 Pager.Source = page;
 datagrid.ItemsSource = page;
</code>
When I did export to Excel it only export the records from the one at a time which is visible. I want to export all.
How do I do that?
Answer: There's a code sample in the top-voted answer to this question that deals with exporting a DataGrid to CSV.
Answer: thanks Town for the reply .. I got the solution actually my Item source is of Paged collection view ..
and In Export to excel I used ..
<code>PagedCollectionView source = (grid.ItemsSource as PagedCollectionView);
source.SourceCollection;
</code>
which return me all records and not only from visible page ..and problem is solved
thanks again


How to hide other section of chartjs on click of lengend

Question: In ChartJS if we click on legend, then the section on which we click that will get disappear. Can this be reversed? Like if we click on legend then apart from that section all other section in chart should get disappear. Is this possible? Can anyone suggest any solution on this.I have to do this on angular 2+. Thanks in Advance.
Answer: I have been using this ChartJS wrapper: ng2-charts. It works great on latest Angular 2+, I used it on Angular 5. This wrapper offers you a chartClick for the directive so you can link it with a function in your code. With no more info about what you are trying to do I would suggest you look at this and maybe work using that event object.
<code>(chartClick)="chartClicked($event)"
</code>
Comment: Antonio, that will give me the element event, Even though i will find the legend clicked. but how to hide the rest of the section apart from that on which it got clicked, i can do it via destroy and rebuild chart, which will make it ugly, so is there any option to hide other element?
Answer: Simplest would be to set div around it and set *ngif option and click event.

 Your chart


How to auto refresh a division with some PHP content within it

Question: I googled abit and found a script, to reload a division.

here downshow is my division where contents need to be refreshed. its like chat app, and messages between me and my friend needs to continoulsy reload.
My division downshow is something like below...
$getmessages= mysql_query("SELECT * FROM pvt_messages WHERE (user_from='$active_username' && user_to='$username') || (user_from='$username' && user_to='$active_username')  ORDER BY id ASC ") or die(mysql_error());

                        while ($row = mysql_fetch_assoc($getmessages ))
                        {
                            $body = $row['msg_body'];
                            $date_send = $row['date'];
                            $opened = $row['opened'];
                            $whosent= $row['user_from'];
                            $whoreceived= $row['user_to'];
                            $seen=$row['opened'];

                            /////////////////////////////////////////////////////
                            $get_user_info = mysql_query("SELECT * FROM users WHERE (username='$whosent')");
                            ////////////////////////////////////////////////////
                            $get_info = mysql_fetch_assoc($get_user_info);
                            $profilepic_info = $get_info['profile_pic'];
                            if ($profilepic_info == "") {
                             $profilepic_info = "./images/default_pic.jpg";
                            }
                            else
                            {
                             $profilepic_info = "./userdata/profile_pics/".$profilepic_info;
                            }
                            echo "

                                         $whosent $body

                                    sent on: $date_send

                            ";

                        }

I would have kept the content of this division in some other page i.e. message.php and then include it just as

<?php include("message.php"); ?>

But if i do this, there will be lots of problem like, session_start() issues, variable $active_username ll be obtained easily by $active_username=$_SESSION['username'] bt couldnt obtain varibale $username in message.php.
so instead of including the division content as "message.php". i want that code to be in main php file itself.
so want to as instead of
setInterval("$('#downshow').load('message.php');", 5000);

how can i use
setInterval("$('#downshow').load('????????????');", 5000);

load the division itself?????????????
Thankyou in advance :)
Answer: Try this..
setInterval(function(){ $('#downshow').load('message.php');

}, 5000);

Comment: yes, i tried that. and it works fine only if some constant data was to be retrived. but my page is for chat, so if I only load .load('message.php'). than in message.php, there will be no active session, no $active_username i.e. me and $username i.e. my certain friend whose conversation with me, i am tryin to load in the division
Comment: I even tried setInterval(function(){ $('#downshow').load('message.php?u=$username');

}, 5000); Here $username is the friend whose conversation , i m trying to load.. but its not working
Comment: Try this-> `(function(){ $('#downshow').load('message.php?u='); }, 5000);`
Answer: This is not the best way to do this
You should look at AJAX and create a template for the HTML.
This way you can send information to the server (such as requesting items since a particular time, or from a particular 'room') and only send back the important data (send it back as JSON) and populate your template.
This will reduce traffic and load on your server and will reduce latency in your application as you are only sending back the important data - not the HTML to go with it!
Additionally use classes for each of the items instead of inline styles as it will make your code easier to maintain.
Comment: Thankyou, I appriciate that. But these inline styling is so i would first complete styling fast, and later m planing to use class :)
Comment: No problem - wasn't sure! definately go this route - it will be far more learning BUT you will use AJAX a LOT during coding if you want nice fluid designs and a mini chat application is a great way to learn it! Good Luck and if you find my answer helpful a +1 is always appreciated (and an accept if you don't find a better answer!)


In $mn+1$ positive numbers, we can choose $m+1$ numbers which not exist 2 numbers $a_i | a_j$ or $n+1$ numbers $a_1|a_2|...|a_n|a_{n+1}$ satisfy,

Question: Prove that , In $mn+1$ positive numbers, we always
Or can choose $m+1$ numbers which not exist 2 numbers $a_i,a_j : a_i | a_j$
Or can choose $n+1$ numbers in line, $a_1|a_2|...|a_n|a_{n+1}$ satisfy,

My idea using composite number into prime factorization but it is not working.
Let $mn+1$ number sets  $A_i= \left( x_{i1}, x_{i2},...,x_{ip}\right)$ , where $x_{ij}$ is positive numbers ($i= 1,2,...,mn+1$ and $j=1,2,...,p$),
We call $A_a$ is "bigger" than $A_b$ if $x_{ac} \geq x_{bc} \forall c=1,2,...,n$. Else , $A_a$ is " not bigger" than $A_b$.
Prove that,
We always can choose $m+1$ number sets, which each set "not bigger" than the others or $n+1$ number sets, which we can put in the line , $A_i$ "bigger" than $A_i+1$
Answer: This is just Erdős–Szekeres theorem.


Can a buried electric line cross a buried sewer line?

Question: What are the code requirements for crossing a buried electric line (from meter to panel) with a sewage line?
Comment: Hello, and welcome to Home Improvement. How deep is the sewage line and the potential electric line? A diagram might be helpful...
Comment: You should [edit] your question with the answer to all these questions
Comment: Are you worries about 'clean' energy?
Comment: Is the electrical line direct buried, or in conduit?  Which line is the existing one, and which line is being added?
Comment: Is the sewer line PVC or cast iron? There could be a difference
Comment: Code requirements will depend on **your specific location,** and the code that is in effect there. That said, it happens all the time. It's **a good idea** to consider upgrading the protection and marking of the electric line in the area of the sewer line crossing, but it may not be **required** to do so. Code sets *minimum* standards, and sometimes it makes sense to aim a little higher than that.
Answer: Here it's not an issue:  Sewer lines have to be below frost line, so they are put at 8 feet.  Electrical lines are, I think 3 feet, and can be less if protected.  This of course makes it difficult to run a sewer line after the electrical is in.
I would try very hard to keep buried lines from crossing.  SOMETIME one is going to be dug up for maintenance.
Answer: Code is whatever local ordinances tell you that you can do.   It isn't good to cross lines but there has to be thousands of examples where you would have to so obviously it is done.   Whether it is a use case, safety, or other type of reason needed is up to your local city in the US.


Is there anyway to make a macro to redeploy an application in Eclipse?

Question: Every time I need to redeploy something (for example in Glassfish), I have to right click glassfish, click add or remove, select the source and then deploy it. Now, Iam not asking to deploy with one button the same source everytime. I would like just to open that window to select the source and then deploy it. This will save me and a lot of other people from 2 unnecessary clicks.
Comment: I don't know if that functionality exists in Eclipse without extensions, but with the GlassFish Tools plugin, one can press CTRL+ALT+P for republishing _all_ deployed modules.
Comment: Thank you I will try it and tell you what happened !
Answer: I found that selecting the project and with Control+Shift+X and then R you can redeploy. But this will also launch a browser within eclipse which I don't need.


Making a path less slippery

Question: I have a path (in Indonesia; rainfall 4000 mm per year) that is a combination of steps and slope.
This picture shows a relatively steep slope over a brief section that's a bridge over a hole. The total path length is around 50m and I guess it climbs around 10m over that distance.

It probably had some sort of gravel finish at one point, as on this part of the path:

but now it's basically just slippery.
Basically I'm constantly falling over, and I want to fix it up.
Is it sensible to just try and resurface it, subject to some sort of maximum gradient, or am I better just to make the whole path completely flat with stairs?
Comment: That's a 20% grade, which seems too steep for a path. I'd look at installing steps instead.
Comment: Is it bare dirt now, or gravel, rocks, or something else?
Comment: it's a concrete path as shown in the picture. some parts steps, some parts ramp
Comment: They make 2-part epoxy garage floor paint to which you can add coarse grit. **Don't use it**.  Epoxy *does not like sunlight*, it will degrade rapidly from the UV light and leave you with a mess.
Answer: Anything you add on top will likely wash away. So I agree with the rest that steps would be the best solution.
An easy way to add steps may be put a board on edge the width of the path every 3-5 ft. Then fill in behind it with stones or gravel. The boards, be sure to use pressure treated, would keep the gravel from washing away. The gravel would give you flat sections to walk on which would reduce the slip issue.
I think this would be much easier then building an entire wooden or stone staircase.
Answer: Are you able to use the handrail? I do not think you should convert any of the ramp to steps because the injury potential from falling on steps can be far worse than a ramp.
Can you reduce the slipperiness of the surface by cleaning the surface of the path with some relatively non-polluting cleaner and a scrub brush on a pole? Or is the surface glazed? If the latter, you might have to roughen it with an abrasive.
Answer: It kind of looks to me like there is some stuff caked on top of the concrete. Maybe try pressure washing first? If that doesn't work, yea I guess some stairs would be fine.

Making a path less slippery


Tuple in function argument list

Question: I have old Python 2 code that contains
def __init__(self, (gv_to_python, python_to_gv), values, bgl_type='object') :

Using this in Python 3 gives a syntax error (2to3 can't fix this).
What is the Python 3 equivalent of this Python 2 function definition?
Comment: What is the error?
Comment: See https://www.python.org/dev/peps/pep-3113/
Answer: PEP 3113 indicates that tuple parameters are being removed. The transition plan at the bottom of that page suggests

Second, the 2to3 refactoring tool [1] will gain a fixer [2] for
  translating tuple parameters to being a single parameter that is
  unpacked as the first statement in the function. The name of the new
  parameter will be changed. The new parameter will then be unpacked
  into the names originally used in the tuple parameter. This means that
  the following function:
def fxn((a, (b, c))):
    pass

will be translated into:
def fxn(a_b_c):
    (a, (b, c)) = a_b_c
    pass

Basically, change the parameter into a single value, and unpack it in the body of your function.

Tuple in function argument list


How Azure Application Gateway's **cookie based affinity** works on VMSS downsizing

Question: I was wondering how cookie-based affinity option in Application Gateway works while **downsizing **VMSS instance
I am having 2 VMSS instances with IIS installed & 10+ .NET applications,
I have setup a custom autoscale rule that if my CPU usage goes up by >70% for 5 mins if will spin up new instance(3rd instance) and route the traffic to the newly created one , but suddenly if the CPU percentage comes <50% then it will automatically delete newest instance that is created.
but what if one my request is still active on 3rd(newly created instance ). will my VM(3rd instance)wait for the request to complete or simply shutdown the instance?
Thanks.
Enabled Cookie-based affinity option
enter image description here
Answer: The 3rd instance will be removed, you will need to configure connection draining on your Azure Application Gateway HTTP settings for existing sessions to complete.


What are the different missions in Pinball 3D Space Cadet?

Question: In the classic version of Pinball for Windows XP (image of the game below) the player after hitting certain targets would get a few missions. Some missions had the player hit certain targets for a number of hits, other missions had the player re-enter the same place where he first accepted the mission.
However, there were other different types of missions in this simple game. What were they?
Comment: That's generally a meta question; if there's already a tag for a game, please use it instead of creating a new one.  If it needs to be changed, then make a case for it on meta.  Don't just create the tag.
Comment: @KenzoEngineer the already existing one is "pinball-microsoft" or something similar; that's like me creating a tag for dungeon-siege-microsoft;  It's redundant because the Dungeon Siege **only** came out for Windows (And that there are other pinball games for microsoft). pinball-microsoft could be changed or made a synonym of this, as this is the correct game title; or more accuratly, a standalone table of Full Tilt! Pinball
Comment: Please try not to create new tags, rather use existing ones
Answer: There are total of 17 different missions, each with different objectives, and only available to specific rank:

Cadet

Launch Training (top): Pass the Launch Ramp 3 times.
Re-entry Training (middle): Pass the Re-entry Lanes 3 times.
Target Practice (bottom): Hit the Attack Bumpers 8 times.
Science Mission (all): Hit 9 Drop Targets.

Ensign & Lieutenant

Bug Hunt Mission (top): Hit 15 targets (Drop and/or Hit).
Rescue Mission (middle): Upgrade Flags, then enter the Hyperspace Kicker.
Alien Menace Mission (bottom): Upgrade the Attack Bumpers, then hit them 8 times.
Secret Mission (all): Enter the Yellow Wormhole, then Red Wormhole, then Green Wormhole.

Captain & Lt. Commander

Stray Comet Mission (top): Light all 3 Right Hazard Target Lights, then enter the Hyperspace Kicker.
Space Radiation Mission (middle): Light all 3 Left Hazard Target Lights, then enter any Wormhole.
Black Hole Mission (bottom): Upgrade the Engine Bumpers, then enter the Black Hole Kicker.
Cosmic Plague Mission (all): Spin flags 75 times, then hit Space Warp Rollover.

Commander & Commodore

Satellite Retrieval Mission (top): Hit the Satellite Bumper 3 times.
Recon Mission (middle): Pass any of the lanes 15 times.
Doomsday Machine Mission (bottom): Send the Ball through the Out-Lanes 3 times.
Time Warp Mission (all): Hit the Rebounds 25 times, then Enter the Launch Ramp (promotion) or Hyperspace Kicker (rank demotion).

Admiral & Fleet Admiral

Cosmic Plague Mission (top, Captain's all mission)
Secret Mission (middle, Ensign's all mission)
Time Warp Mission (bottom, Commander's all mission)
Maelstrom (all):

Hit 3 Drop Targets.
Hit 3 Spot Targets.
Send the Ball through 5 lanes.
Shoot the ball up the fuel chute.
Send the Ball up the launch ramp.
Roll a Flag.
Enter any Wormhole.
Enter the Hyperspace Kicker.

Source: GameFAQs by froesch14 | PINBALL.DOC mirrored on Dokumen.tips.
Answer: Background on this game. It was originally a part of a collection published by Maxis, of SimCity fame. Full Tilt! Pinball (Wikipedia) included three tables, one of them made it to Windows ME and XP Games packs.
As for missions, here is what I can recall:

Launch: Lower left elevated ramp.
Attack bumpers: ball hits against upper bumpers, and other targets *
Orbits (I can't recall if this is an actual mission): Full orbits of back passageway around the top of the table
Wormhole: (can't remember, but it was a thing)

Completing missions lights up the yellow ring in the center of the table, or maybe Blues first.  Wikipedia has some detail on the game mechanics.


What does the hyphen "-" mean in "tar xzf -"?

Question: When try to install dropbox from command  line, I read the commands
cd ~ && wget -O - "https://www.dropbox.com/download?plat=lnx.x86_64" | tar xzf -

what does  - mean here? is it previous directory?
Comment: A bit of pedantry: the option you're asking about is `f -`. This might make finding the answer in the man pages a little easier.
Comment: It would be really helpful if you could explain what, *precisely* is unclear to you about the documentation of `wget` and `tar`. That way, the respective developers can improve their documentation so that future users don't stumble over the same problems again. In other words: be a hero and make the world a better place!
Comment: It would be a nice default for tar to use stdin, but since it's heritage is to work with tapes it did not do that. Instead it learned how to work with files (with the f option) and then follows the convention to have a - in place of the filename for stdin (In case of eXtract or stdout in case of Create)
Comment: @eckes In the case of GNU tar, stdin *is* the default unless `$TAPE` is set.
Answer: Some commands accept - in place of a filename, either:

To write to standard output instead of to a named file. This is what the - argument passed to wget after -O is doing.
To read from standard input instead of from a named file. This is what the - argument passed to tar after xzf.

The command you showed downloads an archive file with wget and unpacks it with tar. To achieve this, the output of wget is piped (|) to the input of tar. This is why wget writes to standard output instead of a file and tar reads from standard input instead of a file.
Comment: @Barmar Yes and no: [Guideline 13:
For utilities that use operands to represent files to be opened for either reading or writing, the '-' operand should be used to mean only standard input (or standard output when it is clear from context that an output file is being specified) **or a file named `-`.**](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html). So **if** `-` is an operand for a "file option" *and* it has a special meaning, *then* it must be that of stdin/stdout. The program is free to not treat as a special case and simply look for file `-`
Comment: @Barmar One way to follow the guideline is to *decline* to treat `-` specially at all, treating it as a literal filename. The only way to go against the guideline is to treat `-` specially but with some other meaning than the ones the guideline suggests.
Comment: I'd say "most commands" rather than just "some commands". I believe it's part of the POSIX option syntax specification.
Comment: (and typically in those cases omitting the option will be the same as using `-`)
Comment: @Bakuriu I don't see how that refutes what I said. I suspect most commands take filename arguments, so they're supposed to follow that guideline. But maybe I should have qualified it as "most commands that operate on files".
Comment: @Barmar Your comment can be misinterpreted to read that all POSIX commands interpret `-` like that, so only the few that are not POSIX do not, while the correct interpretation is that among all POSIX commands, most implement this convention and the rest treat `-` to simply mean "file named `-`" and don't have other conventions. I wanted to clarify that ambiguity
Comment: @EliahKagan The only point I was trying to make was that this isn;t something that a few commands implement, it's widespread convention that's recommended by the specification.
Comment: Possibly worth noting that `f -` is redundant with `tar`, although I certainly type the magic spell `xvpf` without actually thinking.
Answer: That's just a filename that a lot of Unix programs interpret as "instead of actually opening a file, read from stdin (or write to stdout)."
That means reading from the input that gets streamed into the program; in your case, that's the output of wget.
Comment: @EricDuminil It's a filename in the sense that programs accept it in some places where they would otherwise only accept filenames, but you're right that it's not really about an actual name of a file in some directory.
Comment: Is it really a *filename*, though?
Comment: @EricDuminil: In particular, for programs that follow this convention, you have to use `./-` if you *actually* want to open a file named `-`.
Comment: @EricDuminil In fact: yes! It *names* a *file*; in the unix sense, `stdin` is a file descriptor, and `-` is the name you supply to use that. It's not a file name from the OS's perspective, though. Only from the user perspective.
Comment: @rexkogitans no. `/dev/stdin` is just a convenience file name offered by some kernel facility. There's usually **no** `fopen("/dev/stdin", "r")` happening anywhere when you write a program that chooses to use stdin; you just go ahead and use the `extern FILE* stdin` that your libc header provided you with; by the way, that is the integer file descriptor `0`.
Comment: no, it's not "opened" at start. It's simply there. There's no `fopen` happening anywhere.
Comment: @MarcusMüller *no, it's not "opened" at start. It's simply there. There's no `fopen` happening anywhere.*  Pedantically, it would be an `fdopen()` (or equivalent) since only the raw POSIX-style file descriptor and not the standard C `FILE *` is inherited by a child process. Wrapping that POSIX file descriptor in a `FILE *` stream has to happen some time after the new process is `exec`'d and before `main()` is called.
Comment: @EricDuminil No, it is not a filename. Their respecitve filenames are `/dev/stdin` and `/dev/stdout`. These files are opened by default when starting a process, so no need to open them once more.
Comment: @MarcusMüller That's exactly what I wrote. The file is opened on process start, and FILE* stdin is a handle to this opened file. `man 3 stdin` tells you that _Under normal circumstances every UNIX program has three streams opened for it when it starts up, one for input, one for output, and one for printing diagnostic or error messages._
Comment: @MarcusMüller The discussion runs into a wrong direction. The point is, that device files called `/dev/stdin` and `/dev/stdout` exist, whilst there is no file named `-`.
Answer: The - argument to tar specifies that the archive should be read from stdin instead of a file. From the GNU tar manual:

If you use - as an archive-name, tar reads the archive from standard input (when listing or extracting files)

Other commands have the same behavior, and it is specified by the POSIX.1-2017 standard:

Guideline 13:
For utilities that use operands to represent files to be opened for either reading or writing, the '-' operand should be used to mean
  only standard input (or standard output when it is clear from context
  that an output file is being specified) or a file named -.


How to extract a td from html

Question: I have one variable its having some html data. I want to extract one td from that html.
If I give alert(returnData) its giving the following output.

    DOM-001
        <input id="bill_details_1_narration" name="bill_details[1][narration]" type="hidden" />

    DOMSTAL O CAPSULES

        <select id="item_details_batch_number" name="item_details[batch_number]">
            <option value="47">BATCH-830</option>
        </select>

        <input id="bill_details_quantity" name="bill_details[quantity]" size="2" type="text" value="2.0" />

        <input id="item_details_cost_price" name="item_details[cost_price]" size="2" type="text" value="23391.0" />

Here I want to extract the value 1 from bill_details_1_narration.
How do I achieve this?
Comment: rather than trying to the parse strin gof id, I woul duse data-aid, relying on the new html 5 data attribute
Answer: If returnData is HTML node that should work:
var bill_details = $(`#bill_details_1_narration`,returnData).val();

But since you alert it I it's string, why is it so? How do you return that data?
UPDATE:
var valArray = [],
billDet = $('input[name$="[narration]"]', returnData);

billDet.each(function () {
    valArray.push($(this).val())
});

Comment: var i = 1; i < 3; i++ here we can't limit it to 3. it might be anything
Answer: You can transfer value from one element to another like this:
$(function(){
    $('#id_Expeditor').html($('#id_Receiver').html());
});

Answer: The title of the question refers to the td but from my understanding I believe you want to retrieve 1 from the name attribute since 1 does not appear anywhere else in your markup:
If you want to retrieve the value from:
bill_details[1][narration]

Firstly I'd suggest using data-attributeName
You could then use this code to extract 1 from the attribute.
var obj = $("#bill_details_1_narration");
var attr = obj.attr("name");
var sub = attr.substring(attr.indexOf('[') +1, attr.indexOf("]"));

alert(sub);

http://jsfiddle.net/t8uFC/
Comment: ("#bill_details_1_narration"); here the 1 will change. first time 1, second time 2,,,

How to extract a td from html


Equivalent to SQL group_concat() aggregation function using Unix?

Question: In ZSH, a ZLE command can have multiple key bindings, e.g.:
▶ bindkey | grep accept-and-hold
"^[A" accept-and-hold
"^[a" accept-and-hold

How do I produce a list from bindkey that aggregates all key sequences for a given command into one line?
One solution using q:
▶ bindkey | q "select c2, group_concat(c1) from - group by c2" | grep accept-and-hold
accept-and-hold ^[A,^[a

But I'm wondering if there is a way to do this without using using fancier tools such as perl, awk, sed, q, etc.
Answer: Some awk to the rescue:
% bindkey | awk -v zle=accept-and-hold '$2==zle{s=s" "$1};END{print zle s}'
accept-and-hold "^[A" "^[a"

And if you really want to have the quotes removed:
% bindkey | awk -v zle=accept-and-hold '$2==zle{s=s" "gensub(/\"/,"","g",$1)};END{print zle s}'
accept-and-hold ^[A ^[a

Answer:
But I'm wondering if there is a way to do this without using using fancier tools such as perl, awk, sed, q, etc.

There's not much left over… but we could use an associative array to aggregate the key sequences (value) for a given command (key):
b=`bindkey`
typeset -A a
setopt EXTENDED_GLOB
eval "${b//(#b)([^$'\n']#) ([^$'\n']#)/a[$match[2]]+=\ $match[1]}"
print -RaC2 ${(kv)a}


How to properly overload an operator in kotlin

Question: I have a Vec2 class in kotlin.
I overloaded the operator * like this:
operator fun times(v:Float): Vec2 {
    return Vec2(this.x * v, this.y * v)
}

End the behavior is just as I expected, I can use * and *= to scale the vector
var a = Vec2() * 7f; a *= 2f

However, from my understanding what I do here, is I create a new object, by calling Vec2(), every time I use *
Even if I use *= and I do not really need to return anything, as I could just edit the object itself (using this keyword)
Is there any way to overload the *= operator, so that it has the similar behavior to this function?
fun mul(v:Float) {
    this.x *= v; this.y *= v
}

I need my application to run smoothly, and these operators are used quite a lot,
I do not want any lags caused by garbage collector's work.
Answer: There is no need to create a new object, you should just change your x and y to var's so they become reassignable.
Doing this will most likely end you up with something like this:
class Vec2(var x: Float, var y: Float) {
    operator fun times(v: Float) {
        x *= v
        y *= v
    }
}

Then in your implementation it is as simple as:
val a = Vec2(1.0f, 1.0f)

a * 2f
// After this line both x and y are 2.0f

If you really want to overload the *= operator then add the timesAssign operator function instead for more info see the kotlin docs
Comment: Worth mentioning, if you overload `timesAssign`, then you'll need to remove the `times` operator overload if you want to be able to use `*=` on a `var`. Otherwise, the compiler won't let you use it. And I'm guessing OP doesn't want to lose the `*` operator functionality.
Comment: Thank you, I had tried the same solution before, unfortunately it's not what I need, the problem with this your solution is that I cannot use it that way: `a = b * c`, as `b` would get overwritten
Comment: You have to choose one behavior or the other. Either `*` mutates the object or it doesn't. In the case of `a = b * c`, when you really do want to create a new object, then you could use a copy function like `a = b.copy() * c`. If you're really concerned about the GC, a solution commonly used in games is object pooling.
Comment: Thank you, that's the answer I needed :)
`a = b.copy() * c` seems like the best way around to me.
Comment: Isn't having `*` mutate the object likely to be counterintuitive and confusing?  That's not how it behaves for any other types; that's why there's also `*=` which does mutate.


Bash get process ID of a process started in subshell

Question: I am looking at this question here, but it does not seem to be working for me: How to get the process id of a bash subprocess on command line
So I have a command I start in a subshell, like:
<code>(sleep 10 &)
</code>
How can I then get the process ID of that sleep command, and wait for it?
If I do ps after none of the process IDs from the link above match what I see.
Thanks.
Answer: Parents are the only process that can properly wait for a child to finish, so you'll want to do the waiting from the subshell.
<code>(sleep & wait)
(sleep & pid=$!; wait $pid)
</code>
Comment: Or don't create a subshell in the first place -- leave out the parentheses.


How to make standalone after linking Qt Statically?

Question: I think I've rebuilt Qt statically (ran this line configure -static -nomake examples -qt-sql-mysql -I C:\MySql\include -L C:\MySql\lib) and then mingw32-make. It didn't give me any errors. What is next? I am using Qt5.1.0
Comment: add CONFIG += static to your .pro file. Use QT\mkspecs\mingw32\qmake.conf edited to static builds
Comment: in your %QTDIR%, the directory your QT Framework is installed, there are build specifications under the directory mkspecs. Given your needs you may need to change them. Try building a small app an run it in a non-development environment not having QT installed, then you will see if your app is compiled static.
Comment: Build your application?
Comment: Idk what I use to "build" (location of the static qt). I'm the the brightest person on the block
Comment: Idk where the static qt I use to build is is what im trying to say
Comment: @SebastianLange I don't get what you mean by the second part "Use Qt\...\qmake.conf edited to static builds"
Answer: Add the static Qt version into Creator's Qt versions and than add a kit (select the static version, the right compiler and debugger) and don't forget to name the kit so that you recognize it that is the static one (especially if you have many Qt versions on your system) and last step is to add the kit for your project (use Projects -> Add Kits)


Whenever I run my code the screen goes blank with no error message

Question:     import pygame       #setup

pygame.init()
screen = pygame.display.set_mode((800,600))
DISPLAYSURF = pygame.display.set_caption("Smley Pong")
keepGoing = True
pic = pygame.image.load("Crazysmile.bmp")
colorkey = pic.get_at((0,0))
pic.set_colorkey(colorkey)
picx = 0
picy = 0
BLACK = (0,0,0)
WHITE = (255,255,255)
Clock = pygame.time.Clock()
speedx = 5
speedy = 5
paddlew = 200
paddleh = 25
paddley = 550
picw = 100
pich = 100
points = 0
lives = 5
font = pygame.font.SysFont("Times", 24)

while keepGoing:      # Game loop

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            keepGoing = False
picx += speedx
picy += speedy

if picx <= 0 or picx + pic.get_width() >= 800:
    speedx = -speedx
if picy <= 0:
    speedy = -speedy
if picy >= 500:
    lives -= 1
    speedy = -speedy

screen.fill(BLACK)
screen.blit(pic, (picx, picy))

# Draw Paddle
paddlex = pygame.mouse.get_pos()[0]
paddlex = paddlew/2
pygame.draw.rect(screen, WHITE, (paddlex, paddley, paddlew, paddleh))

# Check for paddle bounce
if picy + pich >=paddley and picy + pich <=paddley + paddleh \
   and speedy > 0:
    if picx +picw / 2 >= paddlex and picx +picw / 2 <= paddlex + \
       paddlew:
        points += 1
        speedy = -speedy

# Draw text on screen
draw_screen = "Lives: " + str(lives) + "points: " + str(points)
# Check whether game is over
if lives < 1:
    speedx = speedy = 0
     draw_String = "Game Over.Your score was: " + str(points)                                                 draw_string += ". Press F1 to play again. "

text = font.render(draw_string, True, WHITE)
text_rect = text.get_rect()
text_rect.centerx = screen.get_rect().centerx
text.rect.y = 10
screen.bilt(text, text_rect)
pygame.display.update()
timer.tick(60)

pygame.quit()    # Exit

This is a pong game with using the help of a book, i wanted to test out
pygame but the screen just went blank, so i searched up if anyone had the same problem but they all had different answers so i couldn't fix it.I added a few extra parts but if you think i dont need them or you want me to add something just say what you think i should do.
 If there are any suggestions please answer, also recommendations also answer.
Comment: Fix your indentation please
Comment: Are you sure you don't get an error message?  I can see several errors:

    1) 'bilt' instead of 'blit'
    2) you have timer.tick(60) but you named your clock object 'Clock' - there's no 'timer' variable anywhere

Other than that, it's really hard to read the code with the indenting messed up.  Fix that, and we can try running your code to see what else is wrong.
Comment: There is a lot going on here that you need to understand before trying to implement it in code. Start with the basics such as displaying a white screen or moving a square across the screen. Then you can grasp basic game programming.
Answer: You will have to indent your code from the line picx += speedx, to the line before pygame.quit()
You will then have to add in pygame.display.flip() before the line pygame.quit()(and indent it!)
Then the line text.rect.y = 10 does not make sense. font.render() returns a surface and you can only set the x and y positions when you blit().
also the line:
draw_String = "Game Over.Your score was: " + str(points)                                                 draw_string += ". Press F1 to play again. "

has some wierd indentation.
you will also have to add timer = pygame.time.Clock() somewhere after the import of pygame.


What is the manufacturer of this 1990s toilet?

Question:
I'm going to get a better pic today. But this toilet is from 1991, bone in color and elongated. The elongated toilet seat replacements at Home Depot are an inch or two too short.
We just purchased this home and are trying to find the manufacturer. So far, we are unable to locate any identifying marks.
Ok, we just found a number inside the tank, 1957 12 7 89. I'm trying to look it up now.
Thank you, Susan
Comment: This can be absolutely anything. American Standard? You may be better off replacing the whole toilet and buying a few extra seats.
Comment: Go buy some Kohler toilets and just replace them. The new ones take so little water to flush they'll pay for themselves in time
Comment: Look at the top of the bowl, between/behind the bolt-holes for the seat - that's the most common location for a brand-name IME. Sometimes there will be something stamped into the inside of the tank, too.
Comment: Did you look under the tank lid?
Comment: Ok, we just found a number inside the tank, 1957 12 7 89
Comment: 12 7 89 is the date it was made, almost certainly. Might be an Eljer Preserver?
Comment: Yep! It Is Eljer Preserver! I just looked it up!  Thanks to all! Much appreciated.
Answer: Without gettng anything useful directly from the number, my search on the number lead me to a "toilet identification page" where the peculiar shape of the tank provided the tentative ID (Eljer Preserver) in my comment.


Non-consuming regular expression split in Python

Question: How can a string be split on a separator expression while leaving that separator on the preceding string?
>>> text = "This is an example. Is it made up of more than once sentence? Yes, it is."
>>> re.split("[\.\?!] ", text)
['This is an example', 'Is it made up of more than one sentence', 'Yes, it is.']

I would like the result to be.
['This is an example.', 'Is it made up of more than one sentence?', 'Yes, it is.']

So far I have only tried a lookahead assertion but this fails to split at all.
Answer: >>> re.split("(?<=[\.\?!]) ", text)
['This is an example.', 'Is it made up of more than once sentence?', 'Yes, it is.']

The crucial thing is the use of a look-behind assertion with ?<=.
Comment: @all @ThomasH I draw the attention of the ten upvoters so far that they have upvoted an answer that is wrong: the separator used in this answer is a blank and this blank isn't kept in each separated string, contrary to the crucial demand of the OP. ThomasH, I draw your attention to the fact that an answer, even if it is terse, can't be a better one if it is a wrong one.
Comment: +1, after careful consideration ;-). I, too, think that a terse answer can be better, as it highlights the important thing.
Answer: import re

text = "This is an example.A particular case.Made up of more "\
       "than once sentence?Yes, it is.But no blank !!!That's"\
       " a problem ????Yes.I think so! :)"

for x in re.split("(?<=[\.\?!]) ", text):
    print repr(x)

print '\n'

for x in re.findall("[^.?!]*[.?!]|[^.?!]+(?=\Z)",text):
    print repr(x)

result
"This is an example.A particular case.Made up of more than once sentence?Yes, it is.But no blank !!!That'sa problem ????Yes.I think so!"
':)'

'This is an example.'
'A particular case.'
'Made up of more than once sentence?'
'Yes, it is.'
'But no blank !'
'!'
'!'
"That's a problem ?"
'?'
'?'
'?'
'Yes.'
'I think so!'
' :)'

.
EDIT
Also
import re

text = "! This is an example.A particular case.Made up of more "\
       "than once sentence?Yes, it is.But no blank !!!That's"\
       " a problem ????Yes.I think so! :)"

res = re.split('([.?!])',text)

print [ ''.join(res[i:i+2]) for i in xrange(0,len(res),2) ]

gives
['!', ' This is an example.', 'A particular case.', 'Made up of more than once sentence?', 'Yes, it is.', 'But no blank !', '!', '!', "That's a problem ?", '?', '?', '?', 'Yes.', 'I think so!', ' :)']

Comment: @someone Thank you for the one who upvoted my answer that gives a correct result in all the cases (I hope) while some other impressionable-by-Matthew's-effect (I suppose it's the reason) people continue to upvote the other answer that gives correct result only for a limited case.
Comment: @eyquem Wauw, that's not really the way to induce sympathy. The simple answer gives the correct result for a limited case *which* matches exactly what OP requested. It's easy to introduce further complexity (in scenario as well as solution), especially for regex-related questions, but not always does the added complexity serve any purpose (or have a hold in the real-world requirements). In order words: Your indentified shortcomings in the other answer *may* be valid, but it's really only for OP to decide.
Comment: @jensgram I think that a good answer can't merely answer to the delimited case considered in a question . It's a matter of love of good code and of respect for the person who questioned and that may not think to all the particular, but not rare, cases that a solution will practically encounter.
Comment: @jensgram I don't agree with your expression _"It's easy to introduce further complexity"_ 1) Because it's not a matter of introducing, it's a matter of the reality : _"90% of coding is debugging. The other 10% is writing bugs. Bram Cohen."_ So an interesting answer is one that widen the context of the question by giving ideas to which the person who questioned didn't think and that warns her/him of the potential bugs.
Comment: @jensgram  I don't pretend that I always do that : very often, the lack of sufficient information in the question discourages to do a developed answer because it would be a too dense one, considering too much possibilities; or I have not enough time or I am not very much inspired, or etc. But I don't start with the idea that minimalist answer is always the best.
Comment: @jensgram 2) Because it is much more easy to do a laconic answer than to try to taking account of the potential complexity of the real-world requirements, that exist despite what we would like. On the other point , I agree with you _"Your indentified shortcomings in the other answer may be valid, but it's really only for OP to decide"_ , but to decide, he must be aware of them, and I think it's better to warn him about the potential shortcomings than letting him to practically bump into them at any moment
Comment: @jensgram Concerning the fact that my comment doesn't induce sympathy, it's a problem indeed. Think that this comment is only one among others that I could do but that I don't really write because I fear to be reproached to write non sympathic stuff. But must we always hide the truth behind such considerations ?
Comment: @jensgram By the way, remark that I don't precisely criticize the other answer in fact , but rather the upvoters that seem to me to be quick to react without a lot of reflection. -*- Moreover, I could write something else, but I don't dare to do it. If you write me at firstname.lastname@example.com (with eyGuem, not eyQuem !) , I will say it to you. Anyway, thank you for your point-of-view and reflection.
Comment: @eyquem as much as you do sound like a bit of a hissy little girl, I have to admit you put me closest to the final solution. Thanks!
Comment: @Rob Young _"you do sound like a bit of a hissy little girl"_ I wonder why. Thank you for the upvote and acceptation of the answer.
Comment: @eyquem why not just "[^.?!]*[.?!]" ?
Comment: @bcorso Because, **concerning the regexes, there is often a specific problem at the end of a string**. Here, the pattern ``[^.?!]*[.?!]`` requires that after a substring matched by ``[^.?!]*``, there must be one character ( any of the set ``[.?!]`` ) : then if the analysed string ends on a character that isn't one of this set, the last substring that should be matched wouldn't be.


Bottle/Python - "IOError: [Errno 9] read() on write-only GzipFile object" when trying to decompress request body

Question: I use Bottle to receive gzipped request body. When the size of the request is small, everything is fine. However, if the size of request body is a bit larger (say, >= 20kb), an IOError is thrown.
The following is the code used to read and decompress the request body:
@post("/receive")
def receive():
    try:
        f = request.body
        g_f = gzip.GzipFile(fileobj=f)
        content = g_f.read()
        # other stuff on the content...
    except IOError, e:
        # handle the error

The error message is:
[2015-09-07 16:27:27,967][ERROR   ] Failed to decompress gzipped data: [Errno 9] read() on write-only GzipFile object
127.0.0.1 - - [07/Sep/2015 16:27:27] "POST /receive HTTP/1.1" 400 756

Comment: does this also happen when you specify read only mode when creating the GzipFile object?
Comment: @Oz123 The compressed request body is generated by another program and sent as binary data.
Answer: This problem is caused by the inheritance of the read/write mode of the fileobj used to create the GzipFile object.
If the size of the request.body is less than 20k, Bottle loads the whole binary data as a StringIO object. GzipFile deals with StringIO very well, everything works fine.
On the other hand, if the size of the request.body is larger than 20k, Bottle will use tempfile module to create a temporary file for this request body, for platform-consistency, the default mode of files created by tempfile is 'w+b'.
However, GzipFile determines if a file readable or not only by the mode string obtained by hasattr(fileobj, 'mode'), if this string is something like 'rxx', GzipFile considers it as readable, and vice versa. If the read() function of a non-readable GzipFile is invoked, an IOError will be thrown.
Since the mode of the file which will be used by the GzipFile is 'w+b', the GzipFile is still going to consider it as 'non-readable', so, boom! Error thrown. To fix this, just add the mode argument when creating the GzipFile object:
try:
    f = request.body
    g_f = gzip.GzipFile(fileobj=f, mode='rb')
    content = g_f.read()
    # other stuff on the content...
except IOError, e:
    # handle the error


Maximum time of exploring the wasteland and possible rewards

Question: So, my little vault was doing nice, so i decided to send my dearest Lisa Powell into the wasteland. I got a power armor and a minigun from the lunch boxes which appears to be a good starting gear since she can kill pretty much everything - at least she never looses a fight.
Now, shes on the hunt for 11 hrs and 35 minutes, and i was wondering about a few things:

Is there a maximum amount of time a dweller can explore the wasteland?
Does the level of the dweller matter? Like, can a high-level dweller find better gear than a low level dweller?
How much time has to pass so i can get the best stuff out of the exploration?
Answer: There seems to be no limit to the exploration time, some events occurr at 75 hours of exploration, but some player touched the 90 hours mark.
The level of the dweller does not matter for the chances at finding gear, but the S.P.E.C.I.A.L. do, because some fixed events are based on tests on the dweller S.P.E.C.I.A.L.; plus, as a rule of thumb, Luck always helps in finding gear and caps.
Generally the more your dwellers are out, the better gear they will find, even though there seems to be a cap of 1 legendary for expedition, and there is a confirmed cap of 100 items for expedition.
After getting 100 items your dwellers will come back on their own.
Comment: Yes, I usually let them go until they have 100 items, that actually happens all the time since they have full 70 S.P.E.C.I.A.L.
As you can see here http://imgur.com/ERsdlSQ when your dweller reaches the 100 items cap, the explore button becomes gray.
The las log line is something like "this is my maximum capacity, better to go back and show the overseer what I found"
Comment: Can you confirm that they come back on their own?
Comment: @DocKuro thanks for that bit about automatic return! So, when they're finally loaded up with stuff, they will return by themselves? That's good to know :-)
Answer: (Note that this post was written early in the life of the game is likely out of date.)
In theory you can just keep reviving any explorer that dies in the wasteland to keep them out exploring indefinitely. I had an explorer out over 200 hours (more than 8 days) this way. However explorers can only carry 100 items, and they'll reach this limit long before that. With the latest patch explorers automatically stop exploring and start heading home once they reach 100 items, so it's no longer possible to have an explorer out this long.
Maximum Time Exploring
An explorer will collect 100 items after 3 to 4 days of exploring, so the current maximum time is about 100 hours. Since having higher stats means that the explorer will find more items, its actually the explorers with the lowest stats that can stay out the longest.
Maximum Time Without Dying
To maximize the time an explorer can survive in the wilderness without dying, you need three things. High hit points (HP), a high damage weapon and 25 stimpacks. To get explorers with the most possible HP you need to raise their endurance to 10 while they're still level 1. You then need to equip them with the outfit that gives them highest endurance bonus (ideally +7, but +5 is probably the best you'll be able to manage), and then start levelling them in the wasteland. Once they're level 50 and equipped with a good legendary weapon (20+ damage) they have a decent chance of surviving 100 hours in the wasteland without dying.
(Actually, sending them out before they reach level 50 can increase the amount of they survive in the wasteland. This is because levelling up restores the explorer's HP without using a stimpack. I'm not sure what the most optimal level is, but you can only do this once per explorer so it doesn't matter too much.)
Maximizing Item Quality
Length of time exploring does increase the quality of the items you'll find. However even after 200 hours my explorer was finding mostly junk. So it never gets that good. The one possible exception is a specific encounter that explorers will find after about 60 hours (2 days 12 hours) of exploring, the National Guard Depot. I've never gotten anything better than a "rare" blue item from this encounter, but others have reported getting legendary (gold) items from it. So you want to have your explorers out for a least 60 hours to have the best chance of getting the best items.
Recommended Strategy
At the start of the game, don't worry about any of this. Just send out explorers to get whatever stuff they can.  Once you've unlocked endurance training rooms, fill them with level 1 dwellers and raise their endurance stats to 10. Then make those dwellers your main explorers. You should raise their other stats eventually, but once they've levelled up and you've equipped them with a good rare weapon (15+ damage) they should survive long enough to reach the National Guard Depot.
There doesn't appear any point of exploring beyond the National Guard Depot encounter. I always recall my explorers once they're past it.  The sooner they're on their way back home, the sooner they can be sent back out for another chance at the depot. With the new limit of 10 explorers in the wasteland this is even more important.
So in other words, 60 hours is the amount of time that has to pass for you to get the bust stuff from exploration.
Comment: Excellent point about hitting the depot over and over making 60 hours the measure for getting the best stuff.
Answer: I've been testing various things. I currently have a dweller out for 105h 55min and she still has 5 stim packs. I go through a rather extensive training regime starting with training at level 1. I leave them in training until they are 10 in all 7 SPECIAL attributes. The endurance is most important because it seem to influence how many HP they get when they level up. Next I send them out into the wasteland for their alpha run which only lasts about 24h because they are so low level. It is important to give them a high endurance outfit to boost their HP when they level. When they come back they are usually near level 12-15. I heal them and send them right back out. This beta run will last much longer approaching 48h. I often cut it short when they are near level 30 which so far seem the optimal level for a max run. I need to test some at level 25 to see if that works any better. When they get back I have a dweller with the most HP I can give them, max SPECIAL stats, and at or around level 30. I give them the best weapon I have which right now is a hardened missile launcher (20-23), the best high endurance armor, and typically my best sphynx or husky variant to get them back sooner. They typically go for 48h without using their first stim pack by leveling up before they need one. After they hit level 50 they must rely exclusively on stim packs and by then encounters still do 2 dmg even when they succeed in killing it. They will kill behemoths (4000exp) but the 2 dmg will eventually whittle them down. Things I still want to test are different pets, the Abyssinian seem like it might help, I want to see if the DR reduces the 2 HP attrition. I doubt the pets that increase healing speed will help because dwellers don't have a healing speed while exploring.
Anyone know of pets that really boost wasteland survival time?
edit: One last observation, legendary dwellers are at a disadvantage because they start at level 20-35 and don't get the extra HP from having max endurance from level 1 up. I still keep them but they won't last as long in the wasteland. Yes, Colonel Autumn I'm talking to you, ya big pansy!
Comment: This would be a lot better if you broke it up a bit. It's just a huge wall of text right now. I agree that level 30 or so seems to be the best level for a long expedition without dying. I've had a lvl 33 guy with a Plasma Rifle and Sturdy Wasteland gear with all max SPECIAL as of level one stay out for 5d 8h 15m.
Comment: My pet with +63% HP is real wasteland booster xD....however I never got anything from national depot than 125xp.... O_o
Answer: I just logged back in after a little hiatus and I had a lvl 26 and 38 specials not maxed that survived for 38 days and 19 hours. They died fighting super mutant behemoths and super mutant overlords doing about 9 dmg per fight to my guys.
Answer: I find that my level 38 Sarah Lyons is mostly collecting junk and once in a while, she will find something like an enhanced laser rifle, but then she always seemed to run from some deadly creature.  So the point is, if you find something incredably good, your explorer will always get low health as a result of finding a death claw or something deadly to an level 20-35 explorer. But if you're explorer is out for a day or two,you will find that instead of fighting radroaches you're explorer will start to fight radscorpions and fire ant soldiers and after 3 days or so out in the wasteland you're explorer will get more adventurous and start to fight super mutants and explore abondoned houses instead of broadcasting towers.
Always carry StimPaks and RadAways.fighting super mutants etc. Can be hard after a while.                                            P.s tap the weird guy who you see in the vault and he will vanish into caps.by Steve 73,3:44


Referees in Dota 2 matches

Question: Watching the International qualifiers, there are green named referees, talking to players about why they're pausing (and maybe other powers that aren't so visible, such as allowing a team that calls gg to end the game early?).
Is this a special Valve only feature, or is it possible to get it in "normal" games, or casual matches between two teams that'd like a referee?
Answer:
Is this the kind of green colour you mean ?
If so, they are not necessary admins of the tournament but rather spectators directly in the lobby of the game played (unlike spectators from DotaTV who generally have delay), either as caster/cocaster or as specatators. They can speak to everyone in the game, pause it and most of the time an admin/organizer of the tournament will fill one of these slots to act as a referee in extreme cases but not always, for example in some small amateur tournaments where players have to report the game score themselves.
By the way their colour isn't always green, I believe it depends on the order they joined the lobby (their spectator slot).

Referees in Dota 2 matches


Surjection between two finite sets of different sizes

Question: Suppose I have two sets $A$ and $B$. $A = \{1, 2\}$ and $B = \{2, 4, 6, 8\}$. I am trying to prove that there is no surjection from $A$ to $B$ by finding at least one $y$ value from $B$ such that for every element $x\in A$,  $f(x)\ne y$. I am not entirely sure how to prove this and kind of stuck.
Comment: For every function $f:A\to B$, there are two values of $f$ and four elements of $B$ so there are at least $2=4-2$ elements of $B$ which are not values of $f$, so $f$ is not surjective.
Comment: That approach won't work since you could always define a function $f$ so that $f(x) = y$. (Namely, the function $f_y$ defined by $f_y(x) = y$ for all $x \in A$. Give me a $y$, I'll give you a function mapping to it.)
Answer: Recalling the definition of function, two elements from $B$ can't correspond to the same element in $A$. (Considering $f:A\to B$).
Since you have $|B|=4>2=|A|$, the definition of suerjection won't be satisfied.
Answer: A fully rigorous argument here can be extremely hard.  To give a mostly rigorous argument:  Suppose for contradiction that $f:A\to B$ is a surjection.  Then $f(A)⊆ B$ and $f(A)=\{f(1),f(2)\}$ so that there are only two elements in $f(A)$.  Since there are four elements in $B$ then there must be some element in $B\smallsetminus f(A)$ (the "relative complement").  If we call this element $y$ then there is no $x$ such that $f(x)=y$.


How to retrieve the user story and build model changesets from Rally

Question: I need to pull the changeset belongs to userstory along with build changesets.
<code>// load the data
_loadData : function(loadUi) {
console.log('load data started');
Ext.create('Rally.data.wsapi.Store', {
    model : ['User Story','Build']
    autoLoad : true,
    listeners : {
        load : function(myStore, data, success) {
            return this._processChangesetData(myStore, data, loadUi);
        },
    scope : this
    },
    fetch : [ 'FormattedID', 'Name', 'ScheduleState','Changesets', 'Iteration', 'Release' ,'Number', 'Status','Uri',]
});
},
</code>
Comment: You may need to post a little more information and it seems to be a little more geared towards your server's RallyAPI implementation (unless you are hitting the api directly from the client, which you shouldnt.) Sidenote, im not certain, but it also would be logical to assume your UserStory model wouldnt have a space. In addition to that, you should check associated relationships between models if you want to include both within a single store.... A little more information on how you are trying to build your data store would be helpful. :)
Answer: This is a bit complicated.  Stories have a Changesets collection, and each Changeset entry in there has a Builds collection.
So, in pseudocode:
1) Load stories, making sure to fetch Changesets
2) For each story loaded in step 1, load the Changesets collection, making sure to fetch Builds
3) For each changeset loaded in step2, load the Builds collection
There's a good guide in the docs on how to work with collections: https://help.rallydev.com/apps/2.1/doc/#!/guide/collections_in_v2-section-collection-fetching
Note that this will likely be very slow due to the volume of nested loads occurring in loops.  Is there a way you can filter your data down to avoid loading everything?  What is the question you're trying to answer with all this data?
Code example:
<code>Ext.create('Rally.data.wsapi.Store', {
    model: 'UserStory',
    fetch: ['Changesets'],
    autoLoad: true,
    listeners: {
        load: function(store, records) {
            records.each(function(story) {
                story.changeSets = story.getCollection('Changesets');
                story.changeSets.load({
                    fetch: ['Builds'],
                    callback: function(changesets) {
                        changesets.each(function(changeset) {
                            changeset.builds = changeset.getCollection('Builds');
                            changeset.builds.load({
                                fetch: ['Number', 'Duration', 'Status', 'Uri'],
                                callback: function(builds) {
                                    builds.each(function(build) {
                                        console.log(build);
                                    });
                                }
                            });
                        });
                    }
                });
            });
        }
    }
});
</code>
As mentioned above, I would not recommend running this code in production.  It will be very slow.  If you can limit the top level to a specific story it probably won't be too bad.
Comment: @Morse thanks for information it was helpful ,now i'm able to get the builds in changesets so i'm itirating each changeset and getting builds link which has count value equals to 1, can please help out how can i make call back function to hit builds "_ref" link so that i can get deatils of 'Number', 'Status','Uri' related to build.
"Builds":{
            "_rallyAPIMajor": "2",
            "_rallyAPIMinor": "0",
            "_ref": "https://rally1.rallydev.com/slm/webservice/v2.0/BuildDefinition/133668244192/Builds",
            "_type": "Build",
            "Count": 2
        }
Comment: @Morse thanks for reply , i have taken care of -limit the top level to a specific story under  perticualr release .Its performance is good now.


How to change class in Ogre Battle 64?

Question: I've got enough sets of items, but the attributes graph has red in it for certain attributes. I'm assuming that means I'm not high enough in the attribute, but it might just mean I'll lose that much if I change to the class. I've also got enough sets of the class, since I just bought 5.
It's not listed in the old site I used to use, either.
Do I just level up a fighter a bunch and eventually his stats will be high enough?
Comment: Also note that alignment is _incredibly_ difficult to control.  If your unit is at 100% alignment and you want to grow into a class that requires low alignment, that unit has to survive around 42 battles against high alignment units.  Fighting any low alignment units can make that take even longer.  Also fighting units lower in level drops alignment and fighting units higher in level raises it. A little.
Answer: According to the gamefaq here, the stats are also a requirement, but it has to be the base stats, not the boosted ones.

Q: Why can't I advance in class?
A: There are several requirements to being able to advance in class.
  The very first thing you need to do is find the basic set of equpiment
  for your target class.  What you want is to check shops whenever you
  enter a new area and find any equipment you have none of, then buy it.
The other requirements are simple in comparison.  You'll need to have
  reached specific levels in your physical attributes and experience
  level.  Also, you'll need to be at a specific alignment for most
  classes.
Q: Why can't I get (insert class here)?  I have everything I need!
A: Obviously, you don't.  Remember, you need the proper stats,
  alignment, and equipment for a class to appear on the board.
Q: Okay.  I have all the stats, alignment, and equipment, but I STILL
  can't get the class!  What's wrong?
A: One last thing.  Make sure your stats are not increased past their
  limit due to a weapon or armor modifying your strength.  The class
  limits are derived from BASE stats, not one's increased to due to
  equipment.

How to change class in Ogre Battle 64?


Complex integration and Laurent Series

Question: i was asked to calculate the following integral:
 $$\int_{|z|<1}\frac{1}{z^2\sinh(z)}\: dz$$
I was suggested to calculate the Laurent Series of the integrand function, but how does one determine such series? So far i've just done some manipulations, such $$\frac{1}{z^2\sinh(z)}=\frac{1}{z^2}\frac{2}{e^{z}-e^{-z}}$$ but i'm far away from finding a series. Can someone help me finding such series?
Thanks!
Answer: We have that
$$z^2\sinh z = z^3\left(1+ \frac{z^2}{6} + \cdots\right)$$
Since we are finding a residue for a pole located at $0$, we can use geometric series to conclude that
$$\frac{1}{z^2\sinh z} = z^{-3}\left(1 - \frac{z^2}{6} - \cdots\right) = \frac{1}{z^3} - \frac{1}{6z}+\cdots$$
which means the residue is $-\frac{1}{6}$.
Comment: Thank you for your answer, but i'm not familiar with the term residue, what does it have in common with the value of the integral?
Comment: @riemannfanboy Calculate $\oint z^n \:dz$ on the unit circle for all integer $n$ and tell me what you get.
Comment: the value of such integral on he unit circle is zero.
Comment: @riemannfanboy you didnt do it carefully enough, that's not true for all $n$
Comment: yes  u are correct. It is either zero or $2 \pi i$
Comment: @riemannfanboy and which $n$ has $2\pi i$ ? If you could decompose a function into a series $f(z) = \sum_{-\infty}^\infty a_nz^n$ which terms would survive the integral?
Comment: the negative ones.
Comment: @riemannfanboy no that is not correct, there is only one value that survives.
Comment: i'm sorry, i'm not understanding...

Complex integration and Laurent Series


Test that Verifies Element Text H2 equals "some text " + ${variable}

Question: I have created a simple test which opened browser, navigated to url, keyed in a search value of 123456789123456 and checked the page navigated to has an H2 element with the text "No Details for Device with IMEI Number 123456789123456 found". This works fine. I now have introduced a variable IMEINumber which is linked to an internal Data File of 5 IMEINumbers
I have successfully altered the Set Text step to utilise the variable but struggling with the Verify Element Text step.
My Step values are:
<code>Item                   Object  Input
Verify Element Text    H2      "No Details for Device with IMEI Number " + ${IMEINumber} + " found"
</code>
How do I incorporate the variable into the string. Or is there a way to just test that the H2 element contains the value of variable IMEINumber.
Any help apreciated
Answer: Schoolboy error... anything in ${} can be included in the text as long as you use back ticks... so the fix is:
<code>`No Details for Device with IMEI Number ${IMEINumber} found`
</code>


How can I add my own rating system?

Question: How can I add a rating system? My blog gets its posts from database.
CREATE TABLE IF NOT EXISTS `posts` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `video` varchar(255) NOT NULL,
  `title` longtext NOT NULL,
  `text` longtext NOT NULL,
  `posted_by` longtext NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1 ROW_FORMAT=COMPACT;

In index.php I call them using echo, everything works fine.
Example:

 My Blog

Title

Text

Footer

Comment: Just search for "_php rating_" or "_jquery rating_" on web ;-). For example [this](https://www.codexworld.com/star-rating-system-with-jquery-ajax-php/), or [this](https://phppot.com/jquery/dynamic-star-rating-with-php-and-jquery/).
Answer: For Rating System create a table
e.g.
posts_rating having columns as
id as int(auto incrememt),
post_id as int,
user_id as int(if applicable in your project)
rating as int
Then when a user wants to give rating insert value to the posts_rating table.
To display current rating for the post execute the sql statement:
select round(AVG(rating),1) as currentRating FROM post_rating WHERE post_id=".$post_id;

How can I add my own rating system?


Splitting Raw data into Columns

Question: This is a line from my sample log file,

[Sun Mar 7 16:05:49 2004] [info] [client 126.96.36.199] (104)Connection reset by peer: client stopped connection before send body completed

Most lines are of the same fixed length, In SAS I used to split this based on Position/location. For example, characters in 2-24 would be the TimeStamp column, 29-31 would be MessageType and so on.
Is there way to do the same kind of location based splitting or how to work this out in Pig/MapReduce?
Answer: Yes it is. In your Map Reduce code have something like
<code> @Override   public void map(LongWritable key, Text value, Context
 context) throws IOException, InterruptedException {

     String fields = value.toString();
      // use the start and end index based on your needs
      String date = fields.substring(2,3);

     .........
</code>
Comment: Thanks Sudarshan, that was helpful. And in PIG I was able to similarly perform this using UDFs.

Splitting Raw data into Columns


What is best practice for connecting/coupling EMT conduit?

Question: I'll be assembling some runs of 1/2" and 3/4" EMT in an unfinished garage in the coming weeks. I've got metal compression couplings and connectors. Aside from making sure the EMT ends are smooth and burr-free before assembly, are there any treatments/procedures in the assembly? Should I be doing any surface prep on the ends like emery paper? Measure the conduit resistance across the coupling to make sure the grounding bond is good? My Kopr-Shield joint compound encourages its use for raceway assembly, but maybe that is just to sell more pricey product?
Comment: I would not use emery paper or anything else that would remove the factory galvanizing. Also be sure to use a saw to cut conduit, and not a tubing cutter that leaves a sharp deformed edge.
Answer: I believe you are over-thinking this.  While I'm sure you want to do the best job possible, this isn't a highly technical thing to do.  If you cut some EMT, de-burring is a good idea.   Make sure you don't have more than 360 degrees of bends in a particular run unless you have pull box in it someplace.   If you need a pull box, be sure it's metal if you intend to use the EMT as ground.
Comment: You're probably right. It's my Dad's garage so I don't want to make any mistakes. :) The runs should all be straight to other boxes or one right angle sweep.


generate multiple border contour

Question: Once a 3D model is sliced against a plane and projected onto it, we get a contour curve at certain height. The contour curve I am generating in this process is made of several line segments in closed loop. Now I want to generate another contour curve with the following characteristics:

Each of the line segment of the newly generated inner contour curve must be parallel to the corresponding line segments at the outer contour curve.
Each of the parallel line segments on both outer and inner contour curve has an adjacent distance in between and defined by a constant value as shown in the attached picture (green mark)

Image Link
I need some suggested algorithms to generate it . I hope that I have explained the issue properly. Please do let me know if it is not clear enough.
Thanks
Comment: The magic keyword to search for is "polygon offsetting". The curves you're trying to generate are called offset curves. [Here is a StackOverflow question](http://stackoverflow.com/questions/1109536/an-algorithm-for-inflating-deflating-offsetting-buffering-polygons) with some good background and links to some libraries that can do it. You can also find plenty of material with a web search.
Answer: Polygon offsetting is certainly possible to do yourself. It is not nearly as involved as Bezier or B-spline offsetting is. First you want to decide how to deal with:

Areas with no info, in essence how to deal with the joins. Do you just extend the line to the common intersection (miter join) or do you just connect the endpoints (bevel). You could also use round, parabolic or other join styles if you wish. Options here are unlimited.
For the purposes of this discussion I will assume you will want a miter or bevel join.
How do you want to deal with sidedness. Is an open curve's offset closed or just on the other side. Other than that the convention is usually in 2D that outside is on the clockwise side of the path

So lets look at what happens when 2 straight lines join and they are offset.

Image 1: Situation in 2D.
For a beveled corner join vector, from any point to its offset is magnitude of $a$. Take the direction of the segment rotated counterclockwise 90 degrees then multiply that with the length of offset. Or in the case of the picture in mathematical notation
$$
 A' = A + a\bigg(\big|B-A\big|   \begin{bmatrix}
    0 & 1\\
    -1 & 0
  \end{bmatrix}\bigg)
$$
Where $a$ is the amount of offset. This assumes lines go from $A$ to $B$ to $C$. Connecting segments must be processed on both sides separately. The same formula can be used for all the points. Then just connect $B'^1$ to $B'^2$ with a line. In case you are matrix illiterate, the matrix says swap x and y coordinate and invert the x value.
For a miter join the following applies:

Image 2: Situation of miter.
$$
 B^{B-B'^{1}} = a\bigg(\big|B-A\big| \begin{bmatrix}
    0 & 1\\
    -1 & 0
  \end{bmatrix}\bigg)
$$
$$
B' = B+\dfrac{ B^{B-B'^{1}}}{B^{B-B'^{1}}  \cdot (|B-A|-|C-B|)}
$$
The above can be heavily simplified but I'll leave that to the reader.
Now the reason to use a library is that when the curves start to self intersect it gets a bit tedious to manage this. So just find a library that does this for you and you'll save a lot of time.

generate multiple border contour


End-of-semester presentation idea on PDE

Question: I am supposed to give a 30-minute class presentation on any PDE subjects as end-of-semester project. Do you have any pet subject you would love to suggest?
I have very little applied maths in my background, therefore I am not very advanced in PDE; I took this class as elective only. Hence I prefer a subject that is not in advanced level, but one that comes handy with lots of online resources.
Thank you very much for your time and effort.

POST SCRIPT: My class uses John Davis' Introduction to Applied PDE as textbook. My professor moves slowly and covers only the first few chapters of the book, namely, Intro to PDE; Fourier Methods: Separation of Variables; Full, Sine & Cosine Fourier Series; Sturm-Liouville Theory. Thanks again.
Comment: Please edit your question to include a short summary of the topics you have touched upon in your course. (Partly because it won't do you any good if we suggest a subject you have already covered in class!)
Comment: Thanks for pointing that out, I will edit shortly. Thanks again.
Answer: From what you described, you have not covered Method of Characteristics in any detail at all? Then for a 30 minute presentation a reasonable thing to do would be to introduce the method of characteristics and discuss the shock formation for the inviscid Burger's equation.
If you have already done that in class, a further extension would be to read a bit about the Fermi-Pasta-Ulam experiment and present it. Richard Palais' article in the Bulletin has a wealth of information, much of it may be a bit too advanced. You should probably just skip sections 1 and 2, and read sections 3.1 through 3.5; in there Palais gives some pretty good intuition on what is happening and why the problem is interesting.
Comment: Thanks! Let me take a look.
Answer: I would like to suggest presenting the Malgrange-Ehrenpreis theorem and its applications, using e.g. Stein's functional analysis or Hörmander's PDE book.
Comment: Thank you! I will give your idea a serious look.


Do we need the [psychology] tag?

Question: We have the psychology tag right now. However, it mostly seems to be a placeholder tag for questions that the asker wasn't sure how to tag. I don't really understand why we would need this tag, since we have a specialized tag for every subfield of psychology: cognitive-psychology, developmental-psychology, abnormal-psychology, social-psychology, etc.
I don't think it is a good idea to keep a very vague and 'can-apply-to-almost-any-question-on-the-site' tag around, especially when we have so many more focuses, but still easy to use tags. What do you think?
Comment: Good point. You can already start by adding relevant subtags in those cases where only psychology is applied. If you encounter one where you can't think of a subtag, you will have prove it might be useful to keep it around. ;p
Comment: @StevenJeuris the only question that has just the psychology tag is [your early question](http://cogsci.stackexchange.com/q/117/29). It should probably be tagged [terminology] or something similar, but I will worry about re-tagging when I have more time.
Comment: Terminology might be a good idea, it could be our own little way [of going against the system](http://blog.stackoverflow.com/2012/02/lets-play-the-guessing-game/). :)
Comment: @StevenJeuris it's not really going against that guessing game "guideline" at all, terminology questions are valid and common on many sites including UX. "What is a term for X" is not the same as "What am I remembering?"
Answer: No. Cognitive-psychology is already catch-all enough, and I'd prefer it if more specific tags were used instead when possible (memory, attention).
I think cognitive-psychology keeps the fields separate enough with social, developmental and abnormal already out there, and by not having a psychology tag we can at least try and get new users to use one of the more specific tags. I'm (slowly) going through and removing the psych tag from the current questions as it's not the best tag on any of them.

The psychology tag has been removed and will be auto-deleted eventually. Please tag questions with more specific fields of psychology.
Answer: One thing to consider about a generic [psychology] tag is keeping the site accessible to new users. If I were new to CogSci and were interested in questions on psychology, what's the first thing I'd type into the search engine? Yep. Psychology. Just food for thought. :)
Comment: from my experience of tag editing, it seems that new users like to make their question seem more sciency and often chose cognitive-psychology as a tag even when it doesn't apply. This is partially because if you type any word upto 'psycholog' (without the final y) all the tag suggestions are more specialized forms of psychology and cognitive-psychology leads the pack because it has so many tagged questions already.
Comment: @ArtemKaznatcheev - That makes sense. My only other question would be do new users know to put the dash in between related words? If the search engine doesn't *need* the dash to return results, then there's no problem.
Comment: I don't understand your question. When a user selects the tag field a little FAQ pops up on the left, one of the points on it is: "combine multiple words into single-words with dashes"
Comment: My question was: Do new users know that a dash is required between individual words? However, if the tag list self-populates or auto-completes, there is no reason to be concerned whether a newbie knows that a dash between words is the norm for tags. You've addressed my questions.

Do we need the [psychology] tag?


Multiplayer. Guy shoot at me. Misses. I die?

Question: The new call of duty 3 on multiplayer is extremely fun to play, with the new added specialist features,thrust jumping and better balancing of weapons it makes quite the experience to play. I only have one BIG issue:
First thing you should know I play it on the PlayStation 3 version. So, its quite irritating when I shoot at someone (using a weevil) get like 5 or 7 hits and they don't die but a lot of the times when I am being shot at (and this is my main concern) the opponent misses completely, maybe getting one hit on my torso (most of the times using a smg), yet...I die? So does anyone else experience this problem? Is this a glitch or Need I to upgrade my internet speed?
Also note when this problem occurs there are no lagging present.
Comment: Sounds like either he's shooting in a vulnerable spot (like the head) or typical online gameplay issues. Knowing Call Of Duty, it's probably the latter. What's your Internet connection bandwidth and ping?
Comment: Welcome to online multiplayer gaming.
Comment: I also assume that this is on core, as opposed to hardcore, right?
Answer: Networks function similarly to this oversimplified scheme:

Player A sends information (bullet) to Server then calculates whether it hit or not (based on the next position predicted by the server). Server sends information Player B that he was hit or not.

What you're experiencing is a game without synchronized shooting, meaning that, you don't need to hit the 'body', but where the body will be. Due to that, you don't need to actually hit people, just try to predict (usually a few pixels in front of them, depending on both of your pings) where he is on HIS computer. With that said, use weapons that shoot a lot of bullets in order to have a higher hit ratio
Comment: I meant hits per clip rather than per bullet. Hit percentage is different because if he's shooting a 'slow' weapon it's much more unlikely that that will hit due to having to lagshoot. That's why 'spraying' is so common in those games. While you may not hit at first, you can spray until you find the hitbox and just go from there
Comment: Lots of bullets does not necessarily mean a higher hit ratio... More hits overall maybe, but likely more misses too, meaning a likely unchanged ration. Assuming his accuracy doesn't improve.