Find whats using all my servers bandwidth

Question: TLDR: how can I dig deeper into my Mac mini OSX server to determine what processes are consuming so much bandwidth, or where all the inbound traffic is coming from?
Resource caching is on, all resources are minified or images crushed, our pages are less bandwidth consuming then the website last month (www.vulytrampolines.com), and our traffic in analytics is the same.
Back story: We have 2x mac mini servers running our website/staging/databases etc. Since moving from a dedicated server in America to a colocation place in the city, our bandwidth consumption has somehow quadrupled.  There is a database replication process setup between the two, as well as DNS and various websites (e.g. large files, database tasks, intranet packages etc are on staging server, website and database are on production server)
Our staging server has had 7GB of inbound traffic in 3 DAYS. Does anyone know how to check for inbound traffic sources to see potentially where this consistent stream of inbound traffic at a 200k connection is coming from? We have no idea. We aren't sending it files at all, the only thing that should be active is SSH and a database replication process. netstat [see below] shows we have about 20+ established and 30+ close_weight connections to port 625. We haven't the foggiest how this could be happening.
The annoying thing is, webstats show we haven't used anywhere near 11.66GB for HTTP traffic (it says we used 22GB in the last month, yet our outbound traffic was recorded as over 100GB). Database stats say we haven't used anywhere near enough bandwidth to cause the issue either.
This is our staging server, venus1 (it has been like this for a few weeks):

This is our production server, venus2:

netstat -anp tcp output on venus1. Most of the foreign addresses are from our work IP addresses. 11211 is memcached.
tcp4       0      0  188.8.131.52.49712    188.8.131.52.80      ESTABLISHED
tcp4       0      0  22.214.171.124.11211    18.104.22.168.49711    ESTABLISHED
tcp4       0      0  188.8.131.52.49711    18.104.22.168.11211    ESTABLISHED
tcp4       0     52  188.8.131.52.22       18.104.22.168.56106    ESTABLISHED
tcp4       0      0  220.127.116.11.11211    184.108.40.206.49588    ESTABLISHED
tcp4       0      0  188.8.131.52.49588    220.127.116.11.11211    ESTABLISHED
tcp4       0      0  22.214.171.124.49410    126.96.36.199.3306     ESTABLISHED
tcp4       0      0  18.104.22.168.5432     18.104.22.168.58704    ESTABLISHED
tcp4       0      0  22.214.171.124.58704    184.108.40.206.5432     ESTABLISHED
tcp4       0      0  127.0.0.1.58699        *.*                    LISTEN
tcp4       0      0  126.96.36.199.625      18.104.22.168.62055  CLOSE_WAIT
tcp4       0      0  220.127.116.11.625      22.214.171.124.61838    ESTABLISHED
tcp4       5      0  126.96.36.199.625      126.96.36.199.61741   CLOSE_WAIT
tcp4       0      0  18.104.22.168.625      22.214.171.124.61270  ESTABLISHED
tcp4       0      0  127.0.0.1.54           *.*                    LISTEN
tcp4       0      0  184.108.40.206.53       *.*                    LISTEN
tcp4       0      0  127.0.0.1.53           *.*                    LISTEN
tcp4       0      0  220.127.116.11.625      22.214.171.124.63980  ESTABLISHED
tcp4       0      0  220.127.116.11.625      18.104.22.168.55282   ESTABLISHED
tcp46      0      0  *.80                   *.*                    LISTEN
tcp4       0      0  *.*                    *.*                    CLOSED
tcp46      0      0  *.443                  *.*                    LISTEN
tcp4       0      0  *.*                    *.*                    CLOSED
tcp4       0      0  126.96.36.199.625      220.127.116.11.50766    CLOSE_WAIT
tcp4       0      0  188.8.131.52.625      184.108.40.206.63981    CLOSE_WAIT
tcp4       0      0  126.96.36.199.625      188.8.131.52.60214  ESTABLISHED
tcp4       0      0  22.214.171.124.625      22.214.171.124.65196     ESTABLISHED
tcp4       0      0  126.96.36.199.625      18.104.22.168.60274  ESTABLISHED
tcp4       0      0  184.108.40.206.625      220.127.116.11.53201    CLOSE_WAIT
tcp4       0      0  220.127.116.11.625      18.104.22.168.59662   CLOSE_WAIT
tcp4       0      0  22.214.171.124.625      184.108.40.206.49869    CLOSE_WAIT
tcp4       0      0  184.108.40.206.625      220.127.116.11.53827    CLOSE_WAIT
tcp4       0      0  188.8.131.52.625      22.214.171.124.64678  ESTABLISHED
tcp4       0      0  18.104.22.168.625      220.127.116.11.52810    CLOSE_WAIT
tcp4       0      0  22.214.171.124.625      126.96.36.199.62510  ESTABLISHED
tcp4       0      0  22.214.171.124.625      22.214.171.124.49909    CLOSE_WAIT
tcp4       0      0  184.108.40.206.625      18.104.22.168.56096  ESTABLISHED
tcp4       0      0  188.8.131.52.625      18.104.22.168.53247   ESTABLISHED
tcp4       0      0  184.108.40.206.625      18.104.22.168.62051   ESTABLISHED
tcp4       0      0  126.96.36.199.625      184.108.40.206.59123     CLOSE_WAIT
tcp4       0      0  18.104.22.168.625      18.104.22.168.57173    CLOSE_WAIT
tcp4       0      0  18.104.22.168.625      184.108.40.206.49352   CLOSE_WAIT
tcp4       0      0  18.104.22.168.625      184.108.40.206.64362  CLOSE_WAIT
tcp4       0      0  220.127.116.11.625      22.214.171.124.59772     CLOSE_WAIT
tcp4       0      0  18.104.22.168.625      188.8.131.52.59528    CLOSE_WAIT
tcp4       0      0  *.3306                 *.*                    LISTEN
tcp4       0      0  220.127.116.11.625      220.127.116.11.56812     ESTABLISHED
tcp4       0      0  126.96.36.199.625      22.214.171.124.52987  CLOSE_WAIT
tcp4       0      0  18.104.22.168.625      188.8.131.52.50598    CLOSE_WAIT
tcp4       0      0  22.214.171.124.625      184.108.40.206.63339  CLOSE_WAIT
tcp4       0      0  188.8.131.52.625      188.8.131.52.63283  CLOSE_WAIT
tcp4       0      0  126.96.36.199.625      220.127.116.11.61312    ESTABLISHED
tcp4       0      0  126.96.36.199.625      188.8.131.52.52045  CLOSE_WAIT
tcp4       0      0  184.108.40.206.625      22.214.171.124.49172    CLOSE_WAIT
tcp4       0      0  18.104.22.168.625      220.127.116.11.50501   CLOSE_WAIT
tcp4       0      0  220.127.116.11.625      22.214.171.124.56042     CLOSE_WAIT
tcp4       0      0  126.96.36.199.625      126.96.36.199.55882     ESTABLISHED
tcp4       0      0  220.127.116.11.311      126.96.36.199.55875     ESTABLISHED
tcp4       0      0  18.104.22.168.625      18.104.22.168.58776   ESTABLISHED
tcp6       0      0  *.5432                 *.*                    LISTEN
tcp4       0      0  *.5432                 *.*                    LISTEN
tcp4       0      0  22.214.171.124.625      220.127.116.11.52692     ESTABLISHED
tcp4       0      0  18.104.22.168.625      184.108.40.206.57121   CLOSE_WAIT
tcp4       0      0  126.96.36.199.625      220.127.116.11.54673     CLOSE_WAIT
tcp4       0      0  22.214.171.124.625      184.108.40.206.53915     CLOSE_WAIT
tcp4       0      0  18.104.22.168.625      184.108.40.206.52109     CLOSE_WAIT
tcp4       0      0  126.96.36.199.625      18.104.22.168.51807     CLOSE_WAIT
tcp4       0      0  22.214.171.124.625      22.214.171.124.65049     CLOSE_WAIT
tcp4       0      0  126.96.36.199.625      126.96.36.199.64442     ESTABLISHED
tcp4       0      0  22.214.171.124.311      188.8.131.52.51628   ESTABLISHED
tcp4       0      0  184.108.40.206.625      126.96.36.199.51594   ESTABLISHED
tcp4       0      0  188.8.131.52.625      22.214.171.124.62597     ESTABLISHED
tcp4       0      0  22.214.171.124.625      22.214.171.124.62454     ESTABLISHED
tcp4       0      0  188.8.131.52.625      18.104.22.168.58088     CLOSE_WAIT
tcp4       0      0  188.8.131.52.625      220.127.116.11.57305     CLOSE_WAIT
tcp4       0      0  18.104.22.168.625      22.214.171.124.53724     CLOSE_WAIT
tcp4       0      0  126.96.36.199.625      126.96.36.199.62224     CLOSE_WAIT
tcp4       0      0  126.96.36.199.625      188.8.131.52.62064     CLOSE_WAIT
tcp4       0      0  188.8.131.52.625      126.96.36.199.58236     CLOSE_WAIT
tcp4       0      0  220.127.116.11.625      18.104.22.168.51320   CLOSE_WAIT
tcp4       0      0  220.127.116.11.625      188.8.131.52.51297   CLOSE_WAIT
tcp4       0      0  22.214.171.124.625      18.104.22.168.50864   CLOSE_WAIT
tcp4       0      0  184.108.40.206.625      18.104.22.168.49800  CLOSE_WAIT
tcp4       0      0  188.8.131.52.625      22.214.171.124.50894     ESTABLISHED
tcp4       0      0  126.96.36.199.625      18.104.22.168.50411    ESTABLISHED
tcp4       0      0  22.214.171.124.625      184.108.40.206.54446     ESTABLISHED
tcp4       0      0  188.8.131.52.625      184.108.40.206.51680     CLOSE_WAIT
tcp4       0      0  184.108.40.206.625      126.96.36.199.60797     CLOSE_WAIT
tcp4       0      0  188.8.131.52.625      126.96.36.199.60729     CLOSE_WAIT
tcp4       0      0  220.127.116.11.625      22.214.171.124.49209    CLOSE_WAIT
tcp4       0      0  126.96.36.199.625      220.127.116.11.63371     CLOSE_WAIT
tcp4      81      0  184.108.40.206.625      22.214.171.124.3842     CLOSE_WAIT
tcp4      11      0  220.127.116.11.625      18.104.22.168.55646    CLOSE_WAIT
tcp4       0      0  184.108.40.206.625      188.8.131.52.53655  ESTABLISHED
tcp4       0      0  184.108.40.206.625      126.96.36.199.53644  ESTABLISHED
tcp4       0      0  220.127.116.11.625      184.108.40.206.52146     CLOSE_WAIT
tcp4       0      0  127.0.0.1.8005         *.*                    LISTEN
tcp46      0      0  *.8009                 *.*                    LISTEN
tcp46      0      0  *.8080                 *.*                    LISTEN
tcp4       0      0  126.96.36.199.625      18.104.22.168.50716     CLOSE_WAIT
tcp4       0      0  22.214.171.124.625      188.8.131.52.49872    CLOSE_WAIT
tcp4       0      0  22.214.171.124.625      126.96.36.199.63218     CLOSE_WAIT
tcp4       0      0  220.127.116.11.625      220.127.116.11.62471     CLOSE_WAIT
tcp4       0      0  220.127.116.11.625      220.127.116.11.64758     CLOSE_WAIT
tcp4       0      0  220.127.116.11.625      188.8.131.52.64646     CLOSE_WAIT
tcp4       0      0  188.8.131.52.625      184.108.40.206.56788     CLOSE_WAIT
tcp4       0      0  22.214.171.124.625      188.8.131.52.56770     CLOSE_WAIT
tcp4       0      0  220.127.116.11.625      220.127.116.11.56017     CLOSE_WAIT
tcp4       0      0  188.8.131.52.625      184.108.40.206.53131     CLOSE_WAIT
tcp4       0      0  126.96.36.199.625      184.108.40.206.52519     CLOSE_WAIT
tcp4       0      0  184.108.40.206.625      220.127.116.11.51215     CLOSE_WAIT
tcp4       0      0  184.108.40.206.625      184.108.40.206.51131     CLOSE_WAIT
tcp4       0      0  126.96.36.199.625      18.104.22.168.57058    CLOSE_WAIT
tcp4       0      0  220.127.116.11.625      188.8.131.52.56711    CLOSE_WAIT
tcp4       0      0  18.104.22.168.625      220.127.116.11.50975     CLOSE_WAIT
tcp4       0      0  18.104.22.168.625      126.96.36.199.57209     CLOSE_WAIT
tcp4       0      0  18.104.22.168.625      126.96.36.199.54753     CLOSE_WAIT
tcp4       0      0  126.96.36.199.625      126.96.36.199.60786     CLOSE_WAIT
tcp4       0      0  220.127.116.11.625      126.96.36.199.56174     CLOSE_WAIT
tcp4       0      0  *.11212                *.*                    LISTEN
tcp6       0      0  *.11212                *.*                    LISTEN
tcp4       0      0  127.0.0.1.5348         127.0.0.1.49167        ESTABLISHED
tcp4       0      0  127.0.0.1.49167        127.0.0.1.5348         ESTABLISHED
tcp4       0      0  188.8.131.52.5218     184.108.40.206.49166    ESTABLISHED
tcp4       0      0  18.104.22.168.49166    184.108.40.206.5218     ESTABLISHED
tcp46      0      0  *.5268                 *.*                    LISTEN
tcp46      0      0  *.5218                 *.*                    LISTEN
tcp4       0      0  127.0.0.1.5348         127.0.0.1.49163        ESTABLISHED
tcp4       0      0  127.0.0.1.49163        127.0.0.1.5348         ESTABLISHED
tcp4       0      0  127.0.0.1.5348         127.0.0.1.49162        ESTABLISHED
tcp4       0      0  127.0.0.1.49162        127.0.0.1.5348         ESTABLISHED
tcp4       0      0  127.0.0.1.5348         127.0.0.1.49161        ESTABLISHED
tcp4       0      0  127.0.0.1.49161        127.0.0.1.5348         ESTABLISHED
tcp4       0      0  127.0.0.1.5348         *.*                    LISTEN
tcp4       0      0  *.11211                *.*                    LISTEN
tcp6       0      0  *.11211                *.*                    LISTEN
tcp4       0      0  *.88                   *.*                    LISTEN
tcp6       0      0  *.88                   *.*                    LISTEN
tcp6       0      0  *.2000                 *.*                    LISTEN
tcp4       0      0  *.2000                 *.*                    LISTEN
tcp6       0      0  *.4190                 *.*                    LISTEN
tcp4       0      0  *.4190                 *.*                    LISTEN
tcp4       0      0  *.464                  *.*                    LISTEN
tcp6       0      0  *.464                  *.*                    LISTEN
tcp6       0      0  *.25                   *.*                    LISTEN
tcp4       0      0  *.25                   *.*                    LISTEN
tcp4       0      0  *.749                  *.*                    LISTEN
tcp6       0      0  *.749                  *.*                    LISTEN
tcp4       0      0  *.22                   *.*                    LISTEN
tcp6       0      0  *.22                   *.*                    LISTEN
tcp4       0      0  *.5900                 *.*                    LISTEN
tcp6       0      0  *.5900                 *.*                    LISTEN
tcp4       0      0  *.625                  *.*                    LISTEN
tcp6       0      0  *.625                  *.*                    LISTEN
tcp4       0      0  127.0.0.1.631          *.*                    LISTEN
tcp6       0      0  ::1.631                *.*                    LISTEN
tcp4       0      0  *.311                  *.*                    LISTEN

Answer: Unless you have a very good reason not to, please firewall all non-public ports on your Mac Minis immediately and only expose what you need to! I did a quick check and all of your services currently appear to be completely open to the internet (SSH, SMTP, Tomcat, VNC, MySQL and apple-xsrvr-admin (TCP625) certainly are), which is a very bad idea.
The large amount of inbound traffic you're seeing may quite possibly be hackers/bots trying to brute-force logins and passwords for your services – I see this on servers a lot, particularly against SSH (as it's often public-facing) and directly against popular web software, such as WordPress's /wp-login.php page. From your netstat I can see that IPs from Israel and China were trying to access TCP625 (apple-xsrvr-admin, used for DirectoryService, Open Directory Assistant & Workgroup Manager), which isn't a good sign. I hope all of your usernames and passwords are strong, because – not trying to sound alarmist here, but – 7GB's worth of brute-forcing may have let some bad people get to things they shouldn't have access to, regardless of the security/patch state of any software.
Check with your hosting provider/colo that you have some sort of remote serial console and/or VNC access should you accidentally block yourself from accessing your servers, then add the absolute minimum required for you to remote admin the servers yourself to the rulesets and turn the firewalls on, which I'm assuming they're not already. By default, OS X Server's firewall blocks all incoming ports except those used to configure the server remotely (TCP22, TCP311, TCP626, TCP625, ICMP standard ping (in & out), UDP53 DNS name resolution) so you should be OK to turn it straight on, though you want to lock these down more once you've done so. Create Address Groups that are specific to your office IP (or your ISP's IP netblock(s) if your office doesn't have a static IP address) and use these to open admin access (e.g. SSH, OpenDirectory, VNC) to these only. Create another Group with single IP access for 18.104.22.168 and 184.108.40.206 (or 126.96.36.199/31 mask) to talk to each other and allow this for the MySQL replication. Open the SMTP, HTTP, HTTPS ports to the world, assuming they're public-facing. Lock everything down tight, granting permission only to the IPs that need access to each port. Consider doing this for outbound traffic, too. You want to plan this in advance and make sure you get it all right, but do it soon rather than leaving the server an open sitting duck.
Review your servers' logs and look for suspicious activity. In particular look for any successful logins to services from odd locations or at odd times. Establish some procedures to do this regularly.
I'm not sure which version of OS X Server you have, but guessing at 10.6 or 10.7, this Peachpit document may help get you started on the firewalling front.
As may this Apple support PDF on Networking Services (see chapter 4 for firewalling).
For more advanced firewall configuration, try Waterroof or Icefloor, which provide a simple GUI rather than having to mess with pf on the commandline.

(Edit to address the ipfilter rules pasted from each server)
OK, let's start with venus1 (18.104.22.168). The obvious problem here is that there's no catch-all deny ip from any to any, so we need to fix that immediately. From the commandline, you can issue:
sudo ipfw add 65534 deny log logamount 1000 ip from any to any
Or do it from the Server Admin's Settings tab, under the Advanced sub-tab if you're not too comfortable with manipulating ipfw rules from the commandline (which should make you nervous as it can end badly if you slip up). There should be a list of Advanced Rules somewhat similar to the following image. Assuming that rule is there already at the bottom, tick it to enable it:

Remember that the ipfw rules flow down the priority list, so a priority 1 rule takes precedence over everything else. So adding a 'deny everything' rule down at 65534 is last on the list, meaning it'll only deny a connection if everything above it doesn't allow something first.
OK, with that out of the way, let's deal with some Address Groups. You've defined an Address Group that's 184.108.40.206/29, so 188.8.131.52-22 (where one IP's the gateway), which is your Mac Minis and other co-lo IP addresses. You probably want to define another Address Group for your office location, which I'm guessing at a static IP of 188.8.131.52 (or if your work gets a dynamic IP then the whole netblock of Internode is 126.96.36.199/16). Do this for both venus1 & venus2 and add more for any other offices you have.
Once you've definied your office Groups then give each of these permission to access TCP22, TCP311, TCP626, TCP625, TCP3283 and TCP5900, so you can always admin your Minis even when you disable world-access to these ports. Using the GUI, go to the Services sub-tab of the Server Admin's Settings. Change the "Editing Services for:" to your office Address Group(s), then tick the relevant boxes for the above ports.
Now let's address some more problematic venus1 rules. For instance:
12321    1570      78548 allow tcp from any to any dst-port 3306

Rule 12321 allows everything to connect to MySQL. Disable this rule for the "any" Address Group (using the Services sub-tab again) and while you're there, any other services that the world doesn't need access to. You probably want to keep TCP25 (smtp mail), TCP/UDP53 (dns), TCP80 (HTTP), TCP443 (HTTPS) world-accessible, but do you need world-access to TCP8080 (tomcat's server status)? Anything else? Lock it all down and only grant access to your office Address Group(s) and co-lo where appropriate (e.g. the MySQL replication).
Remember to test everything! Learn to use nmap to scan your server ports so you can see what's open and closed. Scan from different locations (e.g. your office, ssh'ed into your other server, at home through another ISP, etc.) to make sure the rules are working as they should. Be careful not to lock yourself out, but do lock everything down as tight as you can. Re-read the Peachpit doc and Apple support PDF linked above and really learn the material, it'll stand you in good stead. Oh, and keep a regular eye on your logs!
OK, hopefully that should see you right, or at least put you on a better path. Best of luck.
Comment: Well that *should* turn the firewall on, but something's definitely not right because when editing/activating a rule (e.g. disabling access to TCP 625) this should terminate any active connections on that port. The fact that it hasn't means something's up. Further investigation reveals that MySQL's still open to the world on both servers. Can you SSH in to each and run `sudo serveradmin fullstatus ipfilter` then paste the results, please?
Comment: Thank you VERY much for your input! I'll begin working on these things today! I actually had noticed through a tcpdump that we had several hundred MySQL login attempts from Chinese IP addresses! I didn't know about the Israeli ones, so I'll investigate that too.
Comment: Hi Stef, I've enabled the "Firewall" in the Server Admin tool. Is that the right one? Because that hasn't enabled the Firewall in Prefs > Security/Privacy > Firewall. I have disabled access to Port 625, but we still have many established connections (presumably because I have TCP established connections enabled?).
Comment: Damn, that's no good. Thanks a lot for your help Stef. Here is the output of venus2: http://pastebin.com/PpRj3vvT and the output of venus1: http://pastebin.com/TXenWQUK. Would you know how to kill the process of whatever program is running on port 625, or reload it, so we can at least see if its what's using the bandwidth?
Comment: We restarted the server (because I killed opendirectoryd using launchctl, thinking it was what was running on port 625 (it didnt appear to be) and it disabled ssh/screen sharing etc), and now there are no 625 connections lingering (random). Is anyone able to explain that? It's like there was a process running constantly, that only just now got disconnected. I don't understand :S
Comment: If you need to see which app/service is using which port, use `lsof -i`(unfortunately the usual `netstat -antuwp` won't work on Mac OS X). To see a specific protocol use `lsof -i TCP:625`. I'll address the ipfilter outputs in an edit to my post as it'll be too long for a comment.
Answer: The quickest solution would just to use a packet sniffer - tcpdump or wireshark (the latter having a graphical interface).  If there's some kind of constant traffic source it will tend to stick out.  You'll also be able to dig into the particulars of the payload once you do discover the source of the unknown traffic.
Comment: Thanks. I've run a tcpdump -c 2500 and output it to a file, then analysing it in Wireshark. We had 1.2MB of traffic in 30 seconds of recording. Most seems to be from MySQL, but that's still 160k off of our constant 200k connection. So something other than tcp connections???
Comment: tcpdump captures everything on the wire - when you're in wireshark you can apply a display filter to exclude the stuff you know about (i.e. MySQL)... I'd also suggest capturing for a longer interval to get a better feeling about what's happening.  Your traffic level isn't so high that a 10-30 minute capture would be unreasonable to deal with.
Comment: Ok, cool thanks. I'll definitely give that a try. We drop out of SSH every few minutes so hopefully it keeps running while I'm D/C.
Comment: Use nohup and set it collect like 100,000 packets or so and collect it later...
Comment: You sir, are a freaking genius. I had no idea about nohup! *bows to almighty master*
Answer: Based on the close correlation between the traffic stats on the staging and production servers, it appears your two servers are talking to each other.
Port 625 is a management port used by Apple products. From your netstat, it appears that one machine (.19) is connecting to the other (.18) on port 625. From some Google searches, it appears that Mac OS X uses port 625 for Workgroup Manager (which was replaced in Mountain Lion with Profile Manager).
It also appears that a wide variety of other machines on the Internet are connecting to port 625 as well, probably as break-in attempts. You should firewall your server as soon as possible to prevent intrusion.
Comment: Thanks for replying. The weird thing is that most of the traffic to port 625 is from our work network. We have 5 internet connections, so we have 5 different IP addresses. We're not sure how they're connected to the server. How would workgroup manager on a staff members Mac be trying to connect to the server?? Very confusing.. We will look into the servers talking to each other, thank you for that, we hadn't thought of that.


How to export Views data in separate sheets/tables to Excel file?

Question: I've two content types say Reports-1 and Reports-2. Using views I've displayed them as shown in the image. Reports-2 is attachment for Reports-1.
I used Views Calc to display sum at bottom of the table. (Total SUM)

By using Views data export module I could able to export data to Excel format.
Right now the exported excel looks like follows.

But my question is is there any possibility to show the data in separate tables with headers as Reports-1 and Reports-2? (like following image) to recognize the Reports. I need to display sum as well for Individual reports.
I'm also thinking to export views in different sheet of the same Excel. Is it possible?.

Can I do modifications on views-data-export tpl files. Is there any chance to render views output there? Any hints/suggestions!! ?
Answer: You can do it by using Phpexcel
check out the above link.may it will help you.
i have customised my excel and csv files using phpexcel and it works great their.
Comment: +1 for your suggestion. The mentioned link is a library (one of the dependency for [PHPExcel](https://www.drupal.org/project/phpexcel)module). If possible try to elaborate your answer so that I can approve your answer. Just mention module name and it's description in your answer , Otherwise I'll answer my own question ;)
Answer: I guess you can't do that without extending the views data export module.
Maybe have a look at the Sheetnode module  which can edit and write Multiple Worksheets.

Sheetnode integrates the JavaScript spreadsheet engine SocialCalc as a new node type in Drupal. SocialCalc was written by Dan Bricklin, co-author of the original VisiCalc spreadsheet app in 1979, and is used in the OLPC XO laptop and the SocialText Collaboration Platform.

It uses Apache POI for that so you will need to install Java and the PHP Java bridge.
Demo for multiple worksheets can be found here:
Multiple worksheet demo
Comment: I think this module doesn't meet my requirement. Anyway thanks for your answer :)
Answer: Finally I could able to resolve my issue using the PHPExcel module.

The PHPExcel module allows developers to export/import data to/from real Excel files.
The idea behind this module is to have a single module for handling the export or import of Excel files, instead of multiple modules handling specific cases.
The module provides no functionality as-is (the .module file is as good as empty). The phpexcel.inc file must be included to use the export or import functions in your own module.

I've written a custom module using PHPEXcel Hooks (hook_phpexcel_export()) and exported views data to Excel file into different sheets (3).
Hope this helps someone. :)


Shell script to rename multiple files and folders

Question: I have the following structure
Before
-220.127.116.11
--126.96.36.199
---126.96.36.199-->18.104.22.168.file

After
-22.214.171.124
--126.96.36.199
---126.96.36.199-->220.127.116.11.file
...

I would like to use a bash script that searches files and subdirectories name in a specific directory /home for a specific string, and when it finds the search string (in file or
name, file content, subdirectories name), replaces the string (old1) with new string (new1), and so on old2 with new2 ....oldn with newn.
#!/bin/bash
FILES_PATH="/home/pons/test"
FILES=$(find $FILES_PATH -type f -name "*")
for FILE in $FILES; do
    sed -i 's/old1/new1/ ; .... ; s/oldn/newn/' $FILE
done

e.g. replace fadi to server in all
[pons@server1 ~]$ pwd
/home/pons
[pons@server1 ~]$ cd test
[pons@server1 test]$ ls -al
total 12

drwxrwxr-x   3 pons pons 4096 Sep 29 09:50 .
drwx------. 26 pons pons 4096 Sep 29 10:21 ..
drwxrwxr-x   2 pons pons 4096 Sep 29 09:47 fadi
[pons@server1 test]$ cd fadi/
[pons@server1 fadi]$ pwd
/home/pons/test/fadi
[pons@server1 fadi]$ ls -al
total 12

drwxrwxr-x 2 pons pons 4096 Sep 29 09:47 .
drwxrwxr-x 3 pons pons 4096 Sep 29 09:50 ..
-rw-rw-r-- 1 pons pons   27 Sep 29 09:47 xxxfadixx.txt
[pons@server1 fadi]$ cat xxxfadixx.txt
xxxxxxxxxxxxfadixxxxxxxxxx
[pons@server1 fadi]$

Can I add multiple string in one file and do the replace
e.g. create a file that specify filtering routines:
    filter.txt
    s/old1/new1/
    s/old2/new2/
    s/old3/new3/
    ......
    s/oldn/newn/
and then read that file in the script
#!/bin/bash

ROOT_DIR="$HOME/root"  # your target dir
P_FROM="220.127.116.11"
P_TO="18.104.22.168"

# for each directory, starting from deepest first
while IFS= read -r -d $'\0' DIR_NAME; do
cd "$DIR_NAME"           # go to target dir
rename $P_FROM $P_TO *   # rename files
find . -type f -maxdepth 1 -exec sed -i "s/$P_FROM/$P_TO/g" {} \;
cd - > /dev/null         # back to original dir. Suppress stdout
done < <(find $ROOT_DIR -type d -depth -print0) # get only dirs

This above script from Shawn Chin worked perfectly replacing/renaming strings, how can I modify it if I have multiple string to be modified and these strings allocated in a file
 filter.txt
    s/old1/new1/
    s/old2/new2/
    s/old3/new3/
    ......
    s/oldn/newn/
#!/bin/bash
ROOT_DIR="$HOME/test"  # your target dir
FILTER_FILE="$HOME/filter.sed"  # the sed script for renaming

# custom rename function that uses $FILTER_FILE (via sed)
function rename_using_filter {
CURRENT_NAME="$1"
NEW_NAME="$(echo $1 | sed -f $FILTER_FILE)"  # derive new name
if [ "$CURRENT_NAME" != "$NEW_NAME" ]; then  # rename if diff
    mv "$CURRENT_NAME" "$NEW_NAME"
fi
}

# for each directory, starting from deepest first
while IFS= read -r -d $'\0' DIR_NAME; do
cd "$DIR_NAME"           # go to target dir

# for each file/dir at this level
while IFS= read -r -d $'\0' FILE_NAME; do
    rename_using_filter "$FILE_NAME"  # rename it
    if [ -f "$FILE_NAME" ]; then                # if it's a file
        sed -i -f "$FILTER_FILE" "$FILE_NAME";  # replace content
    fi
done < <(find . -maxdepth 1 -print0)

cd - > /dev/null         # back to original dir. Suppress stdout
done < <(find $ROOT_DIR -depth -type d -print0) # get only dirs

I did the  above with filter.sed, it works replacing name files/directories but didnt replace the content of the file... can you check it please.
[pons@server1 test]$ find .
.
./boy_dir
./boy_dir/boy.txt
./papa
./papa/papa_new
./papa/papa_new/papa.txt
./boy
[pons@server1 test]$ cat ./papa/papa_new/papa.txt
xxxxxxxxxxxxxxxxxxxxpapaxxxxxxxxxxxx
[pons@server1 test]$ cat ./boy_dir/boy.txt
xxxxxxxxxxxxboyxxxxxxxxx
[pons@server1 test]$ cd ..
[pons@server1 ~]$ ./replace.sh
[pons@server1 ~]$ cd test
[pons@server1 test]$ find .
.
./girl_dir
./girl_dir/girl.txt
./girl
./mama
./mama/mama_new
./mama/mama_new/mama.txt
[pons@server1 test]$ cat ./mama/mama_new/mama.txt
xxxxxxxxxxxxxxxxxxxxpapaxxxxxxxxxxxx
[pons@server1 test]$ cat ./girl_dir/girl.txt
xxxxxxxxxxxxboyxxxxxxxxx
[pons@server1 test]$

I used this filter
[pons@server1 ~]$ cat filter.sed
s/papa/mama/g;
s/boy/girl/g;
s/old3/new3/g;
s/old3/new4/g;
s/oldn/newn/g;

"filter.sed" 5L, 95C written
[pons@server1 ~]$ ./replace.sh
[pons@server1 ~]$ cd test
[pons@server1 test]$ find .
.
./A.B.C.D.E_
./a.b.c.d.e
./a.b.c.d.e/a.b.c.d.e
./a.b.c.d.e_
./A.B.C.D.E
./A.B.C.D.E/A.B.C.D.E
[pons@server1 test]$ cat ./A.B.C.D.E/A.B.C.D.E
126.96.36.199.5
[pons@server1 test]$ cat ./a.b.c.d.e/a.b.c.d.e
184.108.40.206.0
[pons@server1 test]$ cat ./A.B.C.D.E_
188.8.131.52.5
[pons@server1 test]$ cat ./a.b.c.d.e_
220.127.116.11.0
[pons@server1 test]$ cd ..
[pons@server1 ~]$ ./replace.sh
[pons@server1 ~]$ cd test
[pons@server1 test]$ find .
.
./A.B.C.D.E_
./a.b.c.d.e
./a.b.c.d.e/a.b.c.d.e
./a.b.c.d.e_
./A.B.C.D.E
./A.B.C.D.E/A.B.C.D.E
[pons@server1 test]$ cat ./A.B.C.D.E/A.B.C.D.E
A.B.C.D.E
[pons@server1 test]$ cat ./a.b.c.d.e/a.b.c.d.e
a.b.c.d.e
[pons@server1 test]$ cat ./A.B.C.D.E_
A.B.C.D.E
[pons@server1 test]$ cat ./a.b.c.d.e_
a.b.c.d.e
[pons@server1 test]$

[pons@server1 ~]$ vi filter.sed

s/18.104.22.168.5/A.B.C.D.E/g;
s/220.127.116.11.0/a.b.c.d.e/g;
s/old3/new3/g;
s/old3/new4/g;
s/oldn/newn/g;

~
Comment: are you trying to replace the strings within a file or rename file files/dirs (or both?)? Your before/after structure indicates file/dir renaming, while you code replaces contents of files.
Comment: I want replace strings in files and files name beside that rename directories-names that include the string
Comment: Not a solution for exactly this problem. But I wrote mi (https://github.com/drizzd/mi) to make complicated renaming like this easier.
Answer: From what I gather, you want to traverse a directory structure and do the following:

Replace keywords/patterns within file or directory names.
Replace occurrences of the keywords/patterns within the content of files.

Here's how I would do it.
Warning: long answer. If you're in a hurry, jump straight to the last section for complete script. Might also be over-engineer (there should be an easier way to do this, really...).
Assuming the following file structure (based on your first example):
[me@home]$ find .
.
./18.104.22.168
./184.108.40.206/126.96.36.199
./220.127.116.11/126.96.36.199/220.127.116.11
./22.214.171.124/184.108.40.206/126.96.36.199/188.8.131.52.file
./126.96.36.199/184.108.40.206/184.108.40.206/18.104.22.168-2.file

[me@home]$ cat ./184.108.40.206/188.8.131.52/126.96.36.199/188.8.131.52.file
IP: 188.8.131.52

[me@home]$ cat ./188.8.131.52/22.214.171.124/18.104.22.168/184.108.40.206-2.file
IP: 184.108.40.206 (also)

Replacing patterns within files
This is the easy bit. One can do that quite simply using find and sed
[me@home]$ find . -type f -exec sed -i "s/1\.2\.3\.4/126.96.36.199/g" {} \;

[me@home]$ cat ./220.127.116.11/126.96.36.199/126.96.36.199/184.108.40.206.file
IP: 188.8.131.52

[me@home]$ cat ./18.104.22.168/188.8.131.52/126.96.36.199/188.8.131.52-2.file
IP: 18.104.22.168 (also)

Recursively renaming files/dirs
I first assumed it would be as simple as find . -exec rename 22.214.171.124 22.214.171.124 {} \;.
Unfortunately, that does not work. Prepending the command with an echo shows why it won't work.
[me@home]$ find . -exec echo rename 22.214.171.124 18.104.22.168 {} \;
rename 188.8.131.52 184.108.40.206 .
rename 184.108.40.206 126.96.36.199 ./184.108.40.206
rename 22.214.171.124 184.108.40.206 ./188.8.131.52/22.214.171.124
rename 184.108.40.206 220.127.116.11 ./188.8.131.52/126.96.36.199/22.214.171.124
rename 188.8.131.52 188.8.131.52 ./220.127.116.11/184.108.40.206/22.214.171.124/22.214.171.124.file
rename 188.8.131.52 126.96.36.199 ./18.104.22.168/126.96.36.199/126.96.36.199/22.214.171.124-2.file

The renaming of the top-level directory (./184.108.40.206) will succeed, but once we go down a level to rename ./184.108.40.206/22.214.171.124 this will fail because the parent directory has already been renamed.
We can reverse the order of traversal (using -depth) but that only solves half the problem since we need each step to rename only the lowest-level match and not the whole path.
What we therefore have to do is start the renaming process from the lowest level and work upwards. Here's one way to do it:
#!/bin/bash

ROOT_DIR="$HOME/root"  # your target dir
P_FROM="184.108.40.206"
P_TO="220.127.116.11"

# for each directory, starting from deepest first
while IFS= read -r -d $'\0' DIR_NAME; do
    (cd "$DIR_NAME" && rename $P_FROM $P_TO *)
done < <(find $ROOT_DIR -depth -type d -print0) # get only dirs

The complicated-looking while loop  allows us to handle filenames that contain spaces (see http://mywiki.wooledge.org/BashFAQ/020 for details).
This script assumes the rename command exists.
Running that script on our test directory gives the following results:
[me@home]$ bash renamer.sh

[me@home]$ find .
.
./22.214.171.124
./126.96.36.199/188.8.131.52
./220.127.116.11/126.96.36.199/188.8.131.52
./18.104.22.168/184.108.40.206/126.96.36.199/220.127.116.11.file
./220.127.116.11/126.96.36.199/18.104.22.168/22.214.171.124-2.file

Combining both steps into one script
We can combine both the steps above into one solution by simple adding the find+sed call into the loop.
#!/bin/bash

ROOT_DIR="$HOME/root"  # your target dir
P_FROM="22.214.171.124"
P_TO="188.8.131.52"

# for each directory, starting from deepest first
while IFS= read -r -d $'\0' DIR_NAME; do
    cd "$DIR_NAME"           # go to target dir
    rename $P_FROM $P_TO *   # rename files
    find . -type f -maxdepth 1 -exec sed -i "s/$P_FROM/$P_TO/g" {} \;
    cd - > /dev/null         # back to original dir. Suppress stdout
done < <(find $ROOT_DIR -depth -type d -print0) # get only dirs

Update (renaming and rewriting files based on external sed file)
Assuming you have a sed file filter.sed:
s/old1/new1/g;
s/old2/new2/g;
s/old3/new3/g;
s/old3/new4/g;
s/oldn/newn/g;

Replacing contents of a file is simple as long as filter.sed is a valid sed file. We simply use the -f option:
[me@home]$ cat somefile.txt
hello old1 old2 old3 world

[me@home]$ sed -i -f filter.sed somefile.txt

[me@home]$ cat somefile.txt
hello new1 new2 new3 world

However, renaming files/dirs however is trickier (unless you use the Perl-based rename command available only on debian-based systems. With this you may be able to do something along the lines of rename "$(cat filter.sed)" *).
Using only the standard mv command, here's one way to do it. I suspect this may not the most efficient approach, but after briefly testing it, it appears to work. YMMV.
#!/bin/bash
ROOT_DIR="$HOME/root"  # your target dir
FILTER_FILE="$HOME/filter.sed"  # the sed script for renaming

# custom rename function that uses $FILTER_FILE (via sed)
function rename_using_filter {
    CURRENT_NAME="$1"
    NEW_NAME="$(echo $1 | sed -f $FILTER_FILE)"  # derive new name
    if [ "$CURRENT_NAME" != "$NEW_NAME" ]; then  # rename if diff
        mv "$CURRENT_NAME" "$NEW_NAME"
    fi
}

# for each directory, starting from deepest first
while IFS= read -r -d $'\0' DIR_NAME; do
    cd "$DIR_NAME"           # go to target dir

    # for each file/dir at this level
    while IFS= read -r -d $'\0' FILE_NAME; do
        if [ -f "$FILE_NAME" ]; then                # if it's a file
            sed -i -f "$FILTER_FILE" "$FILE_NAME"   # replace content
        fi
        rename_using_filter "$FILE_NAME"  # rename it
    done < <(find . -maxdepth 1 -print0)

    cd - > /dev/null         # back to original dir. Suppress stdout
done < <(find $ROOT_DIR -depth -type d -print0) # get only dirs

Here's the script in action:
[me@home]$ find .
.
./old1_old2
./old1_old2/old3_old4
./old1_old2/old3_old4/some-oldn.txt
./renamr.sh

[me@home]$ cat old1_old2/old3_old4/some-oldn.txt
hello old1 old2 old3 old4 oldn world

[me@home]$ bash renamr.sh

[me@home]$ find .
.
./.renamr.sh.swp
./new1_new2
./new1_new2/new3_new4
./new1_new2/new3_new4/some-newn.txt
./renamr.sh

[me@home]$ cat ./new1_new2/new3_new4/some-newn.txt
hello new1 new2 new3 new4 newn world

Comment: it works,  but I am getting this message [pons@server1 ~]$ ./replace.sh
find: warning: you have specified the -depth option after a non-option argument -type, but options are not positional (-depth affects tests specified before it as well as those specified after it).  Please specify options before other arguments.
Comment: @madunix That warning should go away if we use `-depth` as the first parameter (before `-type d`). Answer updated.
Comment: Ok .... the warning is gone .... can you look a above how can I add in the script to add multiple string integrated inside a file filter.txt
Comment: Is the multiple string matches for replacing file contents only? or filename/dirname as well? Also, is the format of `filter.txt` fixed?
Comment: yes absolute, same as above for all string  contents file name directories, the filter txt is fixed it will include all old string with new one as I stated above    old1 new1   old2  new2 .......  old3 new3...........................................................
oldn newn    new line for each item and tabs between the old string and new one
Comment: @madunix OK. Updated answer to do roughly that. I didn't have much time to work on this, so I assumed your input `filter.txt` file is formatted as a valid sed script (see answer). It shouldn't be hard to parse your file into that format. Good luck.
Comment: I will check it tomorrow and let you know.
Comment: I checked today it works with the filter file, replacing string in the file names and directory names but it didn't replace the file content
Comment: I paste the result in the original post!
Comment: _@Shawn_ Can you help, see the above result only content I couldn't replace.
Comment: @madunix works find on my end. What happens when you run the `sed` command manually - `sed -i -f filter.sed ./mama/mama_new/mama.txt` ?
Comment: _@Shawn it works ... I checked it again ... but you need to run it twice, it should go in one step check above result
Comment: @madunix I see the problem. My fault. We have to do the replace before renaming the file. Script updated.
Comment: The answer was updated with the fix. Notice that the rename is now done after the replace.
Comment: How can I close this ticket, since my questions its been answered by @@Shawn?
Comment: If the answer solved your problem, you can accept the answer by clicking on the tick (see FAQ link I provided).
Comment: I have tested the script lately... it works .... but found the the following string e.g  **10.6.20.15** been replaced with **A.B.C.D** that's correct  but the string **10.6.20.151** been replaced with wrong term instead to be **a.b.b.d**  its been replaced to **A.B.C.D1**  .. any comments
Comment: That's all down to how you write your filter.sed file. 10.6.20.151 contains 10.6.20.15 so if that rules come first, that replacement will take place. Try swapping the order or write more explicit regex patterns. I'm on the move for the next 2 weeks so I can't really help. If you start another question regarding the correct sed patterns to use, someone might be able to help. Good luck.
Answer: You can run rename (yes, that's an existing program) for each replacement. For example, in Bash >=4.0, here's how to remove a ".bak" extension from all files within the current directory:
shopt -s globstar # Enable recursive globs with **
rename 's/\.bak$//' **.bak

Another example, to do several replacements:
$ touch /tmp/foobarbaz
$ rename 's/foo/bar/g;s/bar/baz/g' /tmp/foobarbaz
$ ls /tmp
bazbazbaz

For your specific replacements, this should work:
rename 's/old1/new1/ ; .... ; s/oldn/newn/' /home/pons/test/**

Comment: Unfortunately, that `rename` syntax is only available on debian-based distros. The standard `rename` is a lot less flexible: http://linux.die.net/man/1/rename
Answer: I didn't completely understand what you want to achieve, but I think this will at least fix your code:
mv "$FILE" "$(echo "$FILE" | sed -i 's/old1/new1/ ; .... ; s/oldn/newn/')"

Comment:  [pons@server1 fadi]$ pwd /home/pons/test/fadi  [pons@server1 fadi]$ ls -al  total 12 drwxrwxr-x 2 pons pons 4096 Sep 29 09:47 . drwxrwxr-x 3 pons pons 4096 Sep 29 09:50 .. -rw-rw-r-- 1 pons pons 27 Sep 29 09:47 xxxfadixx.txt  [pons@server1 fadi]$ [pons@server1 fadi]$ cat xxxfadixx.txt xxxxxxxxxxxxfadixxxxxxxxxx -->then i want to replace all string in failes name or contenet or directories sub above with other name from "fadi" to "server"
Answer:
Sed works on standard input or file content, not argument text or file names or anything like that.
When reading output of find, do not store it all in variable, but read it line by line.

So you want to do something like:
find $FILES_PATH -type f | while read FILE; do
    NEWNAME="$(printf '%s\n' "$FILE" | sed 's/old1/new1/ ; .... ; s/oldn/newn/')"
    mv "$FILE" "$NEWNAME"
done

Note, that you do not want -i for sed, stdin can't be modified in place.
It can be more efficient by having sed output both names, so you can run it just once on the whole output, but with multiple substitutions that requires using the hold space. It goes like:
find $FILES_PATH -type f | sed 'h;s/old1/new1/;...;s/oldn/newn/;x;G' | while read OLD && read NEW; do
    mv "$OLD" "$NEW"
done

Comment: I keep getting this find: unknown predicate `-f'
Comment: That should be `-type f` (instead of `type -f`).
Comment: [pons@server1 fadi]$ pwd
/home/pons/test/fadi
[pons@server1 fadi]$ ls -al
total 12
drwxrwxr-x 2 pons pons 4096 Sep 29 09:47 .
drwxrwxr-x 3 pons pons 4096 Sep 29 09:50 ..
-rw-rw-r-- 1 pons pons   27 Sep 29 09:47 xxxfadixx.txt
[pons@server1 fadi]$ [pons@server1 fadi]$ cat xxxfadixx.txt
xxxxxxxxxxxxfadixxxxxxxxxx         -->then i want to replace all string in failes name or contenet or directories sub  above with other name  from "fadi"  to "server"
Comment: @madunix: I fixed the typo. Your other comment is not readable; edit the question instead, please.


How to extract number from '78 897 dollars' without space between numbers

Question: I have problem with extracting number without space from string in python using regex
re.findall(r'\d+(?:\s)\d+','78 897 dollars')

expecting 78897 but i always get 78 897
Comment: By using the `\s` token, you're finding the white space as well. You're not excluding it
Comment: Extract the numbers and _then_ remove the space character. Alternatively, if the text is always a number followed by "dollars", you may use `re.sub` to replace `^(\d+)\s*(\d*) dollars$` with `\1\2`.
Comment: What's the problem with `'78 897'.replace(' ', '')`?
Answer: try putting .replace(" ","")?
Answer: You can try using something like this.
import re
number = int(re.findall('[0-9]+', '78 897 dollars'.replace(' ',''))[0])

Answer: If you want the string with no non-digit numbers, you can use re.sub to remove them:
import re

int(re.sub(r'\D','', '78 897 dollars'))
#78897

Answer: You can use the pattern that you tried with 2 capture groups, where the second part is optional.
\b(\d+)(?:\s(\d+))?\b

Regex demo | Python demo
import re

pattern = r"\b(\d+)(?:\s(\d+))?\b"
s = r"78 897 dollars"

res = re.sub(pattern, r"\1\2", s)
if res:
    print(res)

Output
78897 dollars


Integral by method of residues

Question: I want to integrate $\displaystyle \int_\gamma \frac{z}{(z-1)(z-2)}dz$ along the curve $\gamma(t)=2+\frac{1}{2}e^{it}$, with $t\in [0,2\pi]$
Can this be done by mean of residues? The curve is not closed, so I think it might be a problem.  The fact that exercise was in a chapter calleed "Cauchy integral formula and residues" suggest that this theorems should be used to solve the integral
Comment: But isn't the curve closed? $e^{it}$ describes a complete circle from $0$ to $2\pi$
Comment: The curve is a circle with radius 1/2 centered about (0, 2). Only one of your poles are in the circle.
Comment: @Kaynex But when $t=0$ doesn't it give the point $(2,0)$?
Comment: Derp, flipped my coordinates. But you know what I mean, and the important part is the pole in the circle.
Answer: The curve is closed. What made you think it is not?
You can compute is using Cauchy's integral formula:\begin{align}\int_\gamma\frac z{(z-1)(z-2)}\,\mathrm dz&=\int_\gamma\frac{\frac z{z-1}}{z-2}\,\mathrm dz\\&=2\pi i\frac2{2-1}\\&=4\pi i.\end{align}
Answer: The curve $\gamma$ described parametrically by $z=2+\frac12e^{it}$, $t\in [0,2\pi]$ is a circle centered at $z=2$ with radius $1/2$.  That curve encloses the pole of $f(z)=\frac{z}{(z-1)(z-2)}$ at $z=2$, but not at $z=1$.
From the residue theorem, we have
$$\begin{align}
\oint_\gamma f(z)\,dz&=\int_{|z-2|=\frac12} \frac{z}{(z-1)(z-2)}\,dz\\\\
&=2\pi i\text{Res}\left(\frac{z}{(z-1)(z-2)}, z=2\right)\\\\
&=2\pi i \lim_{z\to 2}(z-2)\frac{z}{(z-1)(z-2)}\\\\
&=4\pi i
\end{align}$$

Integral by method of residues


A tricky integral involving hyperbolic functions

Question: Can anyone suggest a method for solving the integral below? I've tried numerous things but have had no luck yet. To be honest I'm not sure an analytical solution actually exists.
$$I=\int\cosh(2x)\sqrt{[\sinh(x)]^{-2/3}+[\cosh(x)]^{-2/3}}\,\textrm{d}x.$$
Thanks.
Here is another attempt I have made:
Let $y=[\tanh(x)]^{2/3}$, and rewrite $I$ such that
$$I=\int\cosh(2x)[\sinh(x)]^{-1/3}\sqrt{1+[\tanh(x)]^{2/3}}\,\textrm{d}x.$$
Then $\textrm{d}x=(3/2)[\tanh(x)]^{1/3}[\cosh(x)]^{2}\,\textrm{d}y$. Therefore
\begin{align*}
I&=\frac{3}{2}\int\cosh(2x)[\sinh(x)]^{-1/3}[\tanh(x)]^{1/3}[\cosh(x)]^{2}\sqrt{1+y}\,\textrm{d}y
\\
&=\frac{3}{2}\int\cosh(2x)[\cosh(x)]^{5/3}\sqrt{1+y}\,\textrm{d}y
\\
&=\frac{3}{2}\int[\cosh(x)]^{11/3}\sqrt{1+y}\,\textrm{d}y
+\frac{3}{2}\int[\sinh(x)]^{2}[\cosh(x)]^{5/3}\sqrt{1+y}\,\textrm{d}y
\\
&=\frac{3}{2}\int[\textrm{sech}(x)]^{-11/3}\sqrt{1+y}\,\textrm{d}y
+\frac{3}{2}\int[\tanh(x)]^{2}[\textrm{sech}(x)]^{-11/3}\sqrt{1+y}\,\textrm{d}y
\\
&=\frac{3}{2}\int[\textrm{sech}(x)]^{-11/3}\sqrt{1+y}\,\textrm{d}y
+\frac{3}{2}\int[\textrm{sech}(x)]^{-11/3}y^3\sqrt{1+y}\,\textrm{d}y
\\
&=\frac{3}{2}\int\frac{(1+y)^{1/2}}{(1-y^3)^{11/6}}\,\textrm{d}y
+\frac{3}{2}\int y^{3}\frac{(1+y)^{1/2}}{(1-y^3)^{11/6}}\,\textrm{d}y
\\
&=\frac{3}{2}\int\frac{(1+y^3)(1+y)^{1/2}}{(1-y^3)^{11/6}}\,\textrm{d}y
\\
&=\frac{3}{2}\int\frac{(1-y^6)(1+y)^{1/2}}{(1-y^3)^{17/6}}\,\textrm{d}y
\end{align*}
Comment: Nice work for sure and $\to +1$
Comment: I wouldn't be optimistic: WolframAlpha seems to fail.
Comment: It would be really great if you showed us what you've done even if it hasn't worked :)
Comment: Have edited my original post.
Comment: Thank you! You have earned an upvote from me :)
Comment: Where is this problem from? It looks very tough.
Comment: Hard and nice integral, with the close form expressed via high special functions. Thanks!
Answer: $\color{brown}{\textbf{Version of 03.05.19}}$
Are known the identities

$$\begin{cases}
\cosh^2t-\sinh^2t = 1\\
2\cosh^2t = \cosh2t + 1\\
2\sinh^2t = \cosh2t -1\\
2\sinh t\cosh t = \sinh 2t\\
\cosh^{-2}t = 1-\tanh^2x\\
\sinh^{-2}t = \coth^2x-1\\
(\tanh x)' = \cosh^{-2}t\\
(\coth x)' = -\sinh^{-2}t.
\end{cases}\tag1$$

One can get
$$\cosh^{\large^-\frac23}x + \sinh^{\large-^\frac23}x
 = \sqrt[{\large3}]{1-\tanh^2x} + \sqrt[{\large3}]{\coth^2x-1},$$
$$\cosh^{\large^-\frac23}x + \sinh^{\large-^\frac23}x
 = \sqrt[{\large3}]{\coth x - \tanh x}
(\sqrt[{\large3}]{\coth x} + \sqrt[{\large3}]{\tanh x}),\tag2$$
$$\cosh2x = \dfrac{\cosh^2x+\sinh^2x}{\cosh^2x-\sinh^2x}
=\dfrac{\coth x + \tanh x}{\cot x - \tanh x}.\tag3$$
Therefore,
$$I = \int\cosh2x\sqrt{\cosh^{\large^-\frac23}x + \sinh^{\large^-\frac23}x\,}\,dx,$$
$$I = \int\dfrac{\coth x + \tanh x}{(\coth x - \tanh x)^{\large^\frac56}} \sqrt{\sqrt[{\large3}]{\coth x} + \sqrt[{\large3}]{\tanh x}}\,dx.\tag4$$
Taking in account that
$$\left(\frac65(\sinh x \cosh x)^{\large^-\frac56}\right)'
= \dfrac{\coth x + \tanh x}{(\coth x - \tanh x)^{\large\frac56}}$$
(see also Wolfram Alpha),
$$\left(\sqrt{\sqrt[{\large3}]{\coth x} + \sqrt[{\large3}]{\tanh x}}\right)'
= \dfrac{\left(\coth^{\large^-\frac23}x (1-\coth^2x)
+ \tanh^{\large^-\frac23}x (1-\tanh^2x)\right)}{6\sqrt{\sqrt[{\large3}]{\coth x} + \sqrt[{\large3}]{\tanh x}}}$$
$$= -\dfrac{(\coth x - \tanh x)
\left(\sqrt[{\large3}]{\coth x} - \sqrt[{\large3}]{\tanh x}\right)}{6\sqrt{\sqrt[{\large3}]{\coth x} + \sqrt[{\large3}]{\tanh x}}},$$
is possible the integration by parts:
$$I(x) = -\dfrac65 \int\sqrt{\sqrt[{\large3}]{\coth x} + \sqrt[{\large3}]{\tanh x}}\,\mathrm d\left((\sinh x \cosh x)^{\large^-\frac56}\right),$$
$$I(x) = \dfrac35 I_1(x) - \dfrac65\sqrt{\sqrt[{\large3}]{\coth x} + \sqrt[{\large3}]{\tanh x}}\,(\sinh x \cosh x)^{\large^-\frac56},\tag5$$
where
$$I_1(x) = \int \left((\sinh x \cosh x)^{\large^-\frac56}\right) \dfrac{\mathrm d\left(\sqrt[{\large3}]{\coth x} + \sqrt[{\large3}]{\tanh x}\right)}{\sqrt{\sqrt[{\large3}]{\coth x} + \sqrt[{\large3}]{\tanh x}}}.
\tag6$$
Let
$$\left(\sqrt[{\large3}]{\coth x} - \sqrt[{\large3}]{\tanh x}\right)^2 = y,\tag7$$
then
$$\sqrt[{\large3}]{\coth x} + \sqrt[{\large3}]{\tanh x}
= \sqrt{y+4}\,$$
$$(\sinh x \cosh x)^{-1} = \dfrac{\cosh^2x - \sinh^2x}{\sinh x \cosh x} = \coth x - \tanh x = \sqrt y (y+3),$$
$$I(x) = \dfrac3{10} J\left(\left(\sqrt[{\large3}]{\coth x} - \sqrt[{\large3}]{\tanh x}\right)^2\right) - \dfrac65\sqrt{\sqrt[{\large3}]{\coth x} + \sqrt[{\large3}]{\tanh x}}\,(\sinh x \cosh x)^{\large^-\frac56},\tag8$$
where
$$J(y) = \int (y+3)^{\large^\frac56}(y+4)^{\large^-\frac34}\,y^{\large^\frac5{12}}\,dy\tag9,$$
wherein the last integral can be expressed in the closed form of
$$\begin{align}
&J(y) = \frac2{51} y^{\large^\frac5{12}} \left(-17\cdot 3^{\large^\frac56} F_1\left(\frac5{12}; \frac34, \frac16; \frac{17}{12};-y, -\frac y3\right)\right.\\
& + \left. 5\cdot 3^{\large^\frac56} y F_1\left(\frac{17}{12}; \frac34, \frac16;\frac{29}{12}; -y, -\frac y3\right) + 17 (y+1)^{\large^\frac14} (y+3)^{\large^\frac56}\right) + \mathrm{constant}
\end{align}\tag{10}$$
via the Appell hypergeometric function of two variables.
Formulas $(8),(10)$ $\color{brown}{\textbf{present the given integral in the closed form}}.$
Comment: The first identity you state doesn't seem to be correct. If I set $u^3-v^3=1$ then $4(\frac{u-v}{2})^3+3\frac{u-v}{2}=\frac{1}{2}+\frac{3}{2}(u-v)(1-uv)$ which I cannot seem to reduce further unless $uv=1$. Can you provide a proof of the statement?
Comment: Alpha not finding a solution is a good indication that no closed-form exists.
Comment: In the steps below (3) and above (4) there should be a $$\sqrt[3]{\sinh(2x)}=\sqrt[6]{y^2-1}$$ in the denominator.
Comment: I agree with the above comment. In fact, according to my working, using the substitution proposed I obtain

$$I=\frac{1}{2}\int\left(\frac{\sqrt[3]{\frac{y+1}{2}}+\sqrt[3]{\frac{y-1}{2}}}{\sqrt[3]{\frac{y^2-1}{2}}}\right)^{1/2}\frac{y}{\sqrt{y^{2}-1}}\,\textrm{d}y.$$

Nothing more manageable!
Comment: @YuriNegometyanov: definitely hard, and definitely interesting !
Comment: @YuriNegometyanov:  your imagination + expertise is really admirable.
Comment: @DinosaurEgg Thanks! The new version proposed.
Comment: @Diger Thanks! Generally fixed.
Comment: @DinosaurEgg Generally fixed.
Comment: @Juggler Thanks for the support, generally fixed.
Comment: @YvesDaoust I think that we have exception, due to the Appell hypergeometric function of two variables.
Comment: When starting with (6), possibly in expression (8) $y^{-1/6}$ should be $y^{5/12}/2$ ?
Comment: @Diger Of course. Thanks! Fixed.
Comment: @GCab [Crazy integral](https://math.stackexchange.com/questions/1739358/nested-root-integral-int-01-fracdx-sqrtx-sqrtx-sqrtx/3311446#3311446)
Comment: @GCab [Nice substitution](https://math.stackexchange.com/questions/578605/integral-int-0-infty-frac-ln-left-sqrtx1-vphantomx0-1-right-ln-lef/3489521#3489521)
Answer: Partial answer:
Integration by parts with $$\sf{f(y)=\frac{1-y^6}{(1-y^3)^{17/6}}\implies f'(y)=\frac{y^2(17+5y^3)}{2(1-y^3)^{17/6}}}\\ g'(y)=(1+y)^{1/2}\implies g(y)=\frac23(1+y)^{3/2}$$ gives $$\sf{J=\frac{3}{2}\int\frac{(1-y^6)(1+y)^{1/2}}{(1-y^3)^{17/6}}\,dy=\frac{(1-y^6)(1+y)^{3/2}}{(1-y^3)^{17/6}}-\overbrace{\frac12\int\frac{y^2(1+y)^{3/2}}{(1-y^3)^{17/6}}(17+5y^3)\,dy}^K}$$ and the substitution $\sf{w=1-y^3}$ yields $$\small\sf{K=-\frac16\int\frac{(1+\sqrt[3]{1-w})^{3/2}}{w^{17/6}}(22-5w)\,dw=\overbrace{\frac56\int\frac{(1+\sqrt[3]{1-w})^{3/2}}{w^{11/6}}\,dw}^P-\overbrace{\frac{11}3\int\frac{(1+\sqrt[3]{1-w})^{3/2}}{w^{17/6}}\,dw}^Q}.$$ It is possible to simplify further; let us consider $\sf Q$ first. Integration by parts again with \begin{align}\sf{f(w)=(1+(1-w)^{1/3})^{3/2}}&\sf{\implies f'(w)=-\frac{(1+(1-w)^{1/3})^{1/2}}{2(1-w)^{2/3}}}\\\sf{g'(w)=\frac1{w^{17/6}}}&\sf{\implies g(w)=-\frac6{11w^{11/6}}}\end{align} gives $$\sf{Q=\frac{11}3\left[-\frac{6(1+\sqrt[3]{1-w})^{3/2}}{11w^{11/6}}-\frac3{11}\int\frac{(1+(1-w)^{1/3})^{1/2}}{w^{11/6}(1-w)^{2/3}}\,dw\right]}$$ and the substitution $\sf{t=1+(1-w)^{1/3}}$ yields $$\sf{Q=-\frac{2(1+\sqrt[3]{1-w})^{3/2}}{w^{11/6}}+3\int\frac{\sqrt t}{(1-(t-1)^3)^{11/6}}\,dt}$$ and since $\sf{1-(t-1)^3=(2-t)(t^2-t+1)}$, the substitution $\sf{s=2-t}$ results in $$\sf{\int\frac{\sqrt t}{(1-(t-1)^3)^{11/6}}\,dt=\int\frac{\sqrt{2-s}}{s^{11/6}(s^2-3s+3)^{11/6}}\,ds.}$$ Using a similar procedure, we find that $$\sf{P=-\frac{(1+\sqrt[3]{1-w})^{3/2}}{w^{5/6}}+\frac32\int\frac{\sqrt{2-s}}{s^{5/6}(s^2-3s+3)^{5/6}}\,ds}$$ and putting back $\sf{w=1-y^3}$, we can now derive a simpler expression for $\sf J$: $$\sf{J=\frac{(1-y^6)[(1+y)^{3/2}-y^{3/2}]}{(1-y^3)^{17/6}}+3\int\frac{\sqrt{2-s}}{s^{11/6}(s^2-3s+3)^{11/6}}\,ds-\frac32\int\frac{\sqrt{2-s}}{s^{5/6}(s^2-3s+3)^{5/6}}\,ds}.$$
Comment: That font looks sweet, by the way! :P
Answer: Other attempt:
With $t=e^{2x}$, and omitting a constant factor, you obtain the rational form
$$\int (t+t^{-1})\sqrt{(t^{1/2}-t^{-1/2})^{-2/3}+(t^{1/2}+t^{-1/2})^{-2/3}}\frac{dt}t$$
or
$$\int (t^2+1)(t^2-1)^{-1/3}\sqrt{(t-1)^{2/3}+(t+1)^{2/3}}\,t^{-4/3}\,dt.$$
Nothing more appetizing.
Answer: Thanks to Yuri for his working. Very helpful. I believe I have arrived at the solution now
\begin{align*}
 I&=\int\cosh(2x)\sqrt{[\sinh(x)]^{-2/3}+[\cosh(x)]^{-2/3}}\,\textrm{d}x
\\
&=\int\cosh(2x)\biggl[\frac{\sinh(2x)}{2}\biggr]^{-1/6}[\sqrt[3]{\tanh(x)}+\sqrt[3]{\coth(x)}]^{1/2}\,\textrm{d}x
 \\
 &=\frac{6}{5}\int\frac{\textrm{d}}{\textrm{d}x}\biggl[\frac{\sinh(2x)}{2}\biggr]^{5/6}
 [\sqrt[3]{\tanh(x)}+\sqrt[3]{\coth(x)}]^{1/2}\,\textrm{d}x
 \\
 &=\frac{6}{5}\biggl[\frac{\sinh(2x)}{2}\biggr]^{5/6}[\sqrt[3]{\tanh(x)}+\sqrt[3]{\coth(x)}]^{1/2}
 \\&\quad-\frac{6}{5}
 \int\biggl[\frac{\sinh(2x)}{2}\biggr]^{5/6}\frac{\textrm{d}}{\textrm{d}x}[\sqrt[3]{\tanh(x)}+\sqrt[3]{\coth(x)}]^{1/2}\,\textrm{d}x.
\end{align*}
Now
\begin{equation*}
 \frac{\textrm{d}}{\textrm{d}x}[\sqrt[3]{\tanh(x)}+\sqrt[3]{\coth(x)}]^{1/2}
 =\frac{1}{6}\biggl[\frac{\sinh(2x)}{2}\biggr]^{-1}\frac{[\sqrt[3]{\tanh(x)}-\sqrt[3]{\coth(x)}]}{[\sqrt[3]{\tanh(x)}+\sqrt[3]{\coth(x)}]^{1/2}}.
\end{equation*}
Therefore
\begin{align*}
 I_{2}&=\frac{6}{5}
 \int\biggl[\frac{\sinh(2x)}{2}\biggr]^{5/6}\frac{\textrm{d}}{\textrm{d}x}[\sqrt[3]{\tanh(x)}+\sqrt[3]{\coth(x)}]^{1/2}\,\textrm{d}x
\\&=
 \frac{1}{5}\int\biggl[\frac{\sinh(2x)}{2}\biggr]^{-1/6}
 \frac{[\sqrt[3]{\tanh(x)}-\sqrt[3]{\coth(x)}]}{[\sqrt[3]{\tanh(x)}+\sqrt[3]{\coth(x)}]^{1/2}}\,\textrm{d}x.
\end{align*}
Let $y=[\sqrt[3]{\tanh(x)}+\sqrt[3]{\coth(x)}]^{1/2}$ then
\begin{equation*}
 I_{2}=
 \frac{6}{5}\int\biggl[\frac{\sinh(2x)}{2}\biggr]^{5/6}\,\textrm{d}y=\frac{6}{5}\int[\coth(x)-\tanh(x)]^{-5/6}\,\textrm{d}y
.
\end{equation*}
After a bit of work it is possible to show that
\begin{equation*}
\coth(x)-\tanh(x)=(y^{4}-1)\sqrt{y^{4}-4}.
\end{equation*}
Therefore
$$I=\frac{6}{5}\biggl\{\biggl[\frac{\sinh(2x)}{2}\biggr]^{5/6}y-\int(y^{4}-1)^{-5/6}(y^{4}-4)^{-5/12}\,\textrm{d}y\biggr\},$$
where $y$ is as above and the integral can be written in terms of the hypergeometric function.
A very interesting problem!
Thanks to all.


Como abrir outra viewControler no Swift?

Question: Pessoal sou novo em programação swift e estou com uma duvida. Tenho dois arquivos
O principal: ViewController.swift e um outro que eu criei chamado ViewSegundo.swift.
Fiz a classe
import UIKit

class ViewSegundo: UIViewController {

    @IBOutlet weak var img4: UIImageView!

    override func viewDidLoad() {

    }
}

apontei ela no custom class da segunda View, quando utilizo o botão direito do mouse sobre o botão e seto para segunda view funciona, mais eu preciso fazer via código, e não sei como fazer.
Answer: Para abrir um novo controller você precisa escrever assim dentro do evento do click de um button:
 self.performSegueWithIdentifier("SegundaViewController", sender:self)

Você pode fazer também na forma visual, que seria arrastando o button até a view e selecionando push
Comment: @user1649307 se deu certo marque a respota como aceita, para que as pessoas possam identificar que a resposta resolveu o seu problema.
Comment: Obrigado Gabriel, agora sim com sua dica vi que alem do código precisava identificar o storyboard segue com o nome da segunda View ai eu puxei da View principal a ligação para outra view Secundaria dei o nome e utilizei o o código e deu tudo certo.
Comment: Que tal fazer um tour pelo `SO` ? http://pt.stackoverflow.com/tour


Commerce Rules OR Condition

Question: I am trying to set up a simple OR condition.
If these "blocks" (red) are TRUE or these "blocks" (green) are TRUE execute the rule.

So I've tried added a OR block in various ways, but it does not succeed.

Basically what I want to achieve is that, if red block is NOT EMPTY or green block has value YES, the rule should execute.
Answer: This thread helped me understand the logic.
https://www.drupal.org/node/1784196
Basically what tobiasb said:

OR (All conditions below this or between the lines are OR-Conditions)
  - condition1 (OR)
  - AND  (All conditions below this or between the lines are AND-Conditions, default condition)
  -- condition2 (AND)
  -- condition3
This means:
condition1 OR (condition2 AND condition3)

Commerce Rules OR Condition


The Galois group of automorphisms on the splitting field of the polynomial x^5 - 11.

Question: I think that the splitting field (the smallest subfield of C that contains all the roots of x^5 - 11) is Q adjoined with r and z where r is the real solution of x^5 - 11 = 0 and z is the 5th root of unity.  I think that the degree of r over Q is 5 because x^5 - 11 is the minimum polynomial of r over Q.  I think that the degree of z over Q(r) is 4 because the minimum polynomial of z over Q(r) is 1 + x + x^2 + x^3 + x^4.  Since each automorphism on Q(r,z) must map r to a root of x^5 - 11 and z to a root of 1 + x + x^2 + x^3 + x^4 then there must be 20 elements in GalQ(r,z).  I looked at a list of subgroups of S_5 and there is only one of order 20.  It is <(12345),(2354)>.
An exercise in my textbook states: If f is an automorphism in this group, and f(r)=rz and f(z) = z^3 write T(f) in cycle notation where r~1, rz~2, rz^2~3, rz^3~4, r*z^4~5.  T(f) is f restricted to the roots of x^5 - 11.
I am not certain if anything I have stated above is correct.  I do not know how to complete the exercise.  The answer provided in the text is T(f) = (1254).
Comment: Please use [MathJax](http://meta.math.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-reference) to format your question.
Answer: Everything you say is basically correct. Another way of concluding that the order of the Galois group is $20$ is to note that $[\mathbb{Q}(r,\zeta):\mathbb{Q}] = 20$. Also, the statement that the minimum polynomial of $\zeta$ over $\mathbb{Q}(r)$ is $1 + x + x^2 + x^3 + x^4$ probably requires some justification.
As to your last question, note that since $f$ is a field automorphism, we have
$$f(r\zeta) = f(r)f(\zeta) = r\zeta\zeta^3 = r\zeta^4\sim 5.$$
The others are similar.


pointer default value .?

Question: Look,
  typedef struct jig
   {
         int *a;
         int *b;
   }temp;

now stage 1 :
temp *b;
b= (temp*)malloc(sizeof(temp));

if(b->a != NULL)
    printf("a is not null\n");
else
    printf("a is null\n");
if(b->b != NULL)
    printf("b is not null\n");
else
    printf("b is null\n");

output is :
a is null
b is null

now stage 2 :
temp b;

if(b.a != NULL)
    printf("a is not null\n");
else
    printf("a is null\n");
if(b.b != NULL)
    printf("b is not null\n");
else
    printf("b is null\n");

output is :
a is not null
b is not null

why this is happening?
Comment: Don't rely on implementation-related results.
Comment: Did you get compiler warnings telling you about uninitialised variables?
Comment: using -wall it doesnt show any warning...!!!
Answer: Pointers have no default value. The value they have is just whatever junk was in the memory they're using now. Sometimes a specific compiler will zero out memory, but that's not standard so don't count on it.)
The memory from malloc being NULL was a coincidence; it could have been any other value just as easily. You need to and should always manually set all your pointers to NULL.
Another alternative is you can also use calloc, which does the same thing as malloc but sets all bits to 0 in the block of memory it gives you. This doesn't help with stack variables though, so you still have to set those to NULL by yourself.
Comment: @Mr.32 its a standard C function if that's what you mean.
Comment: in all embedded system 's memory managment will work with calloc..??
Answer: This is completely operating system dependent, there's no telling where pointers will be pointing in what case, since that isn't specified. You should always set your pointers to NULL no matter what.
Answer: Chance, that's what's happening. Nobody says uninitialized, non-static memory needs to hold any value. Both could contain anything.

In the first case it simply happened that malloc returned memory
from an erased page (so it contains 0)
In the second case there was stuff on the stack so the memory contains garbage
Comment: @Mr.32 Then it has automatic storage and there's no telling what it will contain initially.
Comment: @Mr.32 Only if `b` has static storage.
Comment: i have just declared as temp b;
Answer: In both cases the contents of temp will be uninitialized (random) data. They can be null, or non-null. No matter how consistently you get the same values, don't rely on that unless the documentation specifically states what they must be.

pointer default value .?


HLS Client using FFMPEG

Question: I am a beginner to FFMPEG. Currently building a client application for HLS (Http Live Streaming) using FFMPEG. For this I find some useful functions in /libavformat/hlsproto.c and other hls related files. But not sure what are the APIs which are for clients use and how to access them for a simple HLS client. Any small examples or documents will help a lot for this.
Thanks.
Answer: You can look at ffplay.c (or avplay.c in the libav project) to see an example player.
Comment: Thanks. As I understand from FFMPEG framework, to integrate HLS, need not call any specific APIs particular to HLS from client. FFMPEG infers the proper protocol and corresponding APIs based on file/URL format provided in avformat_open_input() function. Hence, client should follow the same principles as in ffplay.

HLS Client using FFMPEG


Using groupby in hook_views_query_alter()

Question: I have a view that is using a format that doesn't include group by fields in its settings. I'm trying to mimic that by using the hook_views_query_alter() function in a module.
I know the code is running, because I see the DPM value and the error log string, but the group by doesn't seem to be working. I know that group by in views is a different thing than mySQL's group_concat (which you can use via aggregation, but that doesn't work in this case because we need one field to not be aggregated.) So I'm not expecting to see a group_concat in the printed-out query. But I would have expected it to produce the same results as if I had set up Group By in unformatted list settings for the same four fields (which does work as expected.)
Here is what my view looks like without any group-by (either in the settings or the module):

You can see that there are two complete chunks of information for April Carlisle, because she is speaking at two sessions.
If I turn on Group By for speaker name (content: title), job title, and company in unformatted list settings, this is what I get (and what I want):

So I had thought that my module code would reproduce that result, but it's not. Can anyone tell me why?
Here's the main function:
function group_speaker_carousel_views_query_alter(&$view, &$query) {
  switch($view->name) {
    case 'speakers_carousel':
      error_log("view name now: ".$view->name);
      $query->groupby[0]['field'] = "title";
      $query->groupby[1]['field'] = "field_job_title";
      $query->groupby[2]['field'] = "field_company";

      $select_query = $query->query();
      $query_string = (string)$select_query;
      dpm($query_string);
      break;
  }
}

Comment: For Drupal 6 there is workaround: http://theoleschool.com/blog/using-hookviewsalter-add-group-statement
Note that doesn't work on postgres databases.
Answer: "Group By" is not working on hook_views_query_alter and it is views module issue. that is reported at https://drupal.org/node/590534, http://drupal.org/node/1608742, http://drupal.org/node/389230#comment-2637200
So, You should use other hooks such as general hook_query_alter.
function hook_query_alter( &$query) {

  if($query->alterMetaData['view']->name == "your_views_name"){
     $query->groupBy("domain_source.domain_id");
     //also you can unset other group by critera by using, unset($query->getGroupBy());
  }
}

Answer: You may use groupby function in hook_views_query_alter() function like:
//$query->add_field('table_alias', 'field_name', 'field_alias', array('function' => 'groupby'));
$query->add_field('node', 'nid', 'node_nid', array('function' => 'groupby'));
//Distinct = TRUE -used to avoid unnecessary groupby conditions
$query->distinct=TRUE;

Answer: The views distinct module will be the best solution to remove duplicates from the view.
INTRODUCTION:

Relationships or other joins in Views often create "duplicate" results. For example, a node with a field that has multiple values may show up in the View once per value in the multi-value field. It's frustrating, and the "DISTINCT" SQL query option in the Views UI does not actually solve the problem because the result row is technically distinct. This module aims to give a simple GUI method to remove or aggregate these "duplicate" rows.
For any given field, including "Global: Text" fields, you can optionally mark the field as filtered ("Filter Repeats") or aggregated ("Aggregate Repeats"). All rows with the same value in that field will either be removed as duplicates (filtered), or aggregated in-line.
The "value" of the field as used for filtering or aggregation can be taken pre-render (fastest and totally cacheable), or post-render (after any rewrite rules or other transformations have occurred). Post-render actions are a bit slower (the View must be re-rendered, though the query is not re-run), but also work with Global fields, like Global: Text w/rewrite rules.


Como compilar uma KB Gx X Ev 2 "na mão"? Via código

Question: Como compilar uma KB Gx X Ev 2 "na mão"? Via código.
Eu tenho um programa gerado pelo genexus, que quando abro via ferramenta mostra uma versao desatualizada do mesmo, mas o .cs esta ok. Preciso gerar a DLL desse programa, por isso da pergunta. Compilar um programa do genexus na via prompt de comando.
Answer: Valdo,
Há algum tempo atrás escrevi em meu blog (https://beyondgenexus.wordpress.com/2011/07/27/recompilando-toda-a-aplicacao-sem-fazer-build-all/) um artigo falando exatamente sobre isso.
Na época acho que era em gx 9, mas deve te atender.
Qualquer dúvida, é só perguntar!
Comment: Complementando, após realizar o touch no .exe, você deverá executar:

gxexec "****\bld****.cs" -r:GxBaseBuilder.dll -arg:csc="_C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\csc.exe_"

Notar que o último parâmetro é o caminho para o compilador do c#, caso utilize outra versão, basta alterar...


Erro na função SCROLL dentro do OnClick

Question: Boa tarde Pessoal, a uma semana mais ou menos um cliente veio reclamando que o link do site dele não estava funcionando e eu não conseguia entender o por que, pois o site foi entregue funcionando, era um link que simplesmente rolava a página. Essa semana então percebi que o mesmo tipo de link parou de funcionar em outros sites meu, e é uma função de scroll que eu utilizo a muito tempo, e ela esta apresentando um erro que eu ainda não consegui decifrar, alguém consegue me dar um help?
Estou colocando nas imagens abaixo o código do link que faz a chamada da função pelo onclick, o erro e também a função js que estou usando.
Comment: Eu já testei direto no console do chrome chamar a função scroll() e ela funciona corretamente, percebi então que o erro está no onclick, mas o que seria?
Comment: Os sites a seguir são sites que já fiz e estão dando esse problema:

• http://braganca.adv.br  (o link de scroll está no contato no topo)
• http://happyday-es.com.br  (o link de scroll está em festas no topo)
Answer: Pelo que li a respeito, a função scroll sendo chamada não corresponde a de sua autoria e sim à função window.scroll, que recebe parametros diferentes, causando esse erro no chrome.
Tente mudar o nome da sua função e verifique se seu problema será resolvido.
Fazendo um teste rápido aqui declarando uma função com outro nome no console e alterando o onclick para chamar esta função, a rolagem funcionou perfeitamente.
Comment: Muito obrigado Breno Costa, funcionou perfeitamente.
Comment: Eu não tinha cogitado isso pois quando eu chamava a função pelo console, sem o onclick ela funcionava. Então o problema mesmo estava no scroll dentro do onclick.
Comment: Por nada! De resto, ficam os mistérios nas implementações das API's pelos navegadores.. kkk

Erro na função SCROLL dentro do OnClick


How to display a window half of its original size

Question: I'm printing a WPF window in A4, so originally the window size is rather big. I would like to display it half the size of the original without modifying the printing output. Any ideas?
This is my method where I print
<code>private void printItemList(string printerName)
    {
        //printButton.Visibility = Visibility.Collapsed;
        //cancelButton.Visibility = Visibility.Collapsed;
        PrintDialog printDlg = new System.Windows.Controls.PrintDialog();
        printDlg.PrintQueue = new System.Printing.PrintQueue(new System.Printing.PrintServer(), printerName);
        System.Printing.PrintCapabilities capabilities = printDlg.PrintQueue.GetPrintCapabilities(printDlg.PrintTicket);

        //get scale of the print wrt to screen of WPF visual
        double scale = Math.Min(capabilities.PageImageableArea.ExtentWidth / this.ActualWidth, capabilities.PageImageableArea.ExtentHeight /
                       this.ActualHeight);

        //Transform the Visual to scale
        this.LayoutTransform = new ScaleTransform(scale, scale);

        //get the size of the printer page
        Size sz = new Size(this.ActualWidth, this.ActualHeight); //(8.5 * 96.0, 11.0 * 96.0);

        //update the layout of the visual to the printer page size.
        this.Measure(sz);
        this.Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz));

        //now print the visual to printer to fit on the one page.
        printDlg.PrintVisual(this, "Print Page");
        this.DialogResult = true;
    }
</code>
Comment: Have you tried wrapping the content in a viewbox?
Comment: Please outline the methodology you are using to print it
Comment: can you elaborate more on your print window
Comment: ViewBox does what I was thinking, I just have to make sure it is resized before printing executed.
Answer: ViewBox does what I was thinking, I just have to make sure it is resized before printing executed. Thanks for the tip.


Como usar uma imagem em uma caixa de alerta em JavaScript?

Question: Aqui eu tenho um simples código em JavaScript:
window.alert("iae");

quando esta caixa de alerta é exibida eu queria que tivesse uma imagem dentro da caixa de alerta já vi isso em muitos sites mais não sei como faz.
Comment: Talvez ajude-o https://pt.stackoverflow.com/a/267911/99718
Comment: esse tipo de coisa não esta em foco atualmente, onde todos falamos de Componentes, mas a titulo de estudo e curiosidade, vc pode dar uma olhada no assunto usando Jquery, nesse link: [ alertas em Jquery](http://jqueryui.com/dialog/)! apesar de não estar no Hype, o Jquery ainda esta espalhado ai por todo lugar. espero que ajude.
abraço!
Comment: Isso não pode ser feito, conforme respondido pelo @Maniero. Caso você queira algo para apresentar uma mensagem com a possibilidade de adicionar uma imagem, você deve seguir a sugestão do ***Marcio Alexandre*** ou do ***Valdeir Psr*** e utilizar uma "Janela Modal".
Answer: Não pode. Não foi feito para isso, foi feito para dar um alerta rápido e simples. Na verdade, quase sempre o seu uso está errado e é praticamente considerado obsoleto (não deveria ser muito usado em aplicações modernas que não sejam muito triviais).
A solução em que se usa seria uma camada de conteúdo que monta o modal de alerta do jeito que quiser, eventualmente usar algum componente pronto mais moderno, e aí pode colocar imagem ou o que desejar, embora provavelmente seja um abuso usar uma imagem em uma alerta, exceto uma de indicação se aquilo é só uma informação, um aviso ou erro. Mas personalizar o alerta padrão do navegador não é possível.

Coloquei no GitHub para referência futura

.
Answer: O alert() é muito limitado e pouco utilizado atualmente. Com ele não é possível formatar e muito menos incluir uma imagem.
A melhor forma é utilizar algum componente de JavaScript mais rico:

$( function() {
  $( "#dialog-message" ).dialog({
    modal: true,
    buttons: {
      Ok: function() {
        $( this ).dialog( "close" );
      }
    }
  });
} );

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <link rel="stylesheet" href="/resources/demos/style.css">

      A sua mensagem a ser apresentada no box. Aqui você pode formatar.

Fonte: jQuery-UI: dialog


Conditional probability and complement

Question: $P(A|C)+P(A|C^{\complement})=P(A|C\cup C^{\complement})=P(A)$  ?
I think this is false, but I cannot think of  a counterexample, can anyone offer some help?
Answer: Taking $C=A$ we find $1+0=P(A)$, so counterexample if $P(A)<1$.
Answer: Your second equation is true, because $P(A | C \cup C^\complement) = P(A \cap C)  + P(A \cap C^\complement)$ and that is just a particular case of the Law of total probability, that is, since $C \cup C^\complement$ is a partition of the sample space, we have $P(A | C \cup C^\complement) = P(A)$.
The problem is with your first equality. If you want a concrete counterexample, take for instance the classic six-face dice with all faces being equally likely, set $A$ for "face 1" and $C$ for "any even face". Then you will see that
$P(A | C) = 0$ and $P(A | C^\complement) = \frac{1}{3}$
but $P(A | C \cup C^\complement) = P(A) = \frac{1}{6}$.
Answer: Because $C\cup C^\complement$ equals the sample space, therefore $\mathsf P(A\mid C\cup C^\complement)~=~\mathsf P(A).$
However, by the Law of Total Probability, $~\mathsf P(A)~=~\mathsf P(A\mid C)\;\mathsf P(C)+\mathsf P(A\mid C^\complement)\;\mathsf P(C^\complement)$
So...

Conditional probability and complement


Consequences if an official interferes with play?

Question: I've seen this happen quite a few times in the 2014 FIFA World Cup - the referee accidentally trips or bumps into a player but nothing is called.
An example of this was USA vs Belgium. The referee actually trips number 13 when he gets open for a shot at net. The player is unharmed but he is very disappointed. Later on, he is making a solo run when he bumps into the referee, losing possession.
What should happen?
Answer: In football, the referee and assistant referees are considered to be part of the field, just like the corner flags, crossbars and goalposts. In the case of the ball hitting the referee, there are two passages that support play continuing.
On page 33 of the 2014/15 FIFA Laws of The Game:

The ball is in play at all other times, including when:

it rebounds off a goalpost, crossbar or corner flagpost and remains in the field of play
it rebounds off either the referee or an assistant referee when they are on the field of play

Also, on page 106:

If, when the ball is in play, it touches the referee or an assistant referee who is temporarily on the field of play, play continues because the referee and the assistant referees are part of the match.

As for a referee contacting a player, there is nothing explicitly written in the Laws about this. However, the only way a free kick or penalty kick can be awarded to a team in football, is if a player, substitute or substituted player on the other team commits an infringement, so this is out of the question.
As for a potential dropped ball restart, this would only occur if the player and/or referee was injured as a result of the collision. Page 31 covers when a dropped ball is appropriate:

A dropped ball is a method of restarting play when, while the ball is still in play,
  the referee is required to stop play temporarily for any reason not mentioned
  elsewhere in the Laws of the Game.

As the referee is not required to stop play, it is not stopped and hence play continues.
Answer: In football (you should ask a separate question for the hockey) the game plays on as if the ball had been touched by a player. It happens quite a lot when, for example, in crowded areas of the pitch the referee can bump into players or be hit by the ball. In all cases, the team that has a disadvantage will feel aggrieved but it's just part of the game.


What is the worst recorded record for a team that was, the previous year, a Stanley cup finalist?

Question: Looking at the Habs this year is... well, pain.
And I'm starting to wonder, will they hit the 'Worst record for a team that was a Stanley cup finalist the year prior' record.
So what is that record in the NHL since it's start?
Comment: Closing this as needs details; please feel free to edit in the requested details and it can be reopened.
Comment: The NHL part of this is a good question; are you able to restrict/refine the "other sports" bit somewhat - I'm sure I can find some relatively obscure sport somewhere where a team was useless the next year. A similar issue applies to "finalist", especially when you move outside US sports into ones which don't have playoffs to determine the champion. That all said, 1998 Marlins.
Comment: Yes - please be very specific what you want to compare to, or this is simply too broad.   Also consider time - there are cases of "American Football champions" that went defunct the next year, and probably the same for baseball, in the "pre modern era" for those.  If you want a useful answer, you should probably define specific sports and what you consider their specific "modern era" (either Superbowl era or post-merger era for NFL, post-merger probably for NBA, MLB you could use a few different cutoffs, NHL probably post-original-six era?)
Comment: Guess the right comparative data point would be win%. But yeah I had the impression i was stretching on a limb with my 'same record in other sports' part.
Comment: @Fredy31 Just clarify what sports you mean and what time period, it's not all that hard to answer, but I don't want to spend time writing an answer that doesn't fit your particulars. :)
Comment: Removed the 'other sports' section because, well, it created a lot of work for a part that was not that important to the question in general.
Comment: @PhilipKendall Btw, while the Marlins are the "classic" example of this, those of us from Chicago remember the true example of first-to-worst... peek at my deleted answer if you want the hint :)
Answer: In the NHL's "modern era", The 2006-7 Hurricanes (40-35-7 OTLs, or 40-42) had the worst record by a defending champion if you count the OTLs as losses (which the NHL doesn't exactly).  If you count OTLs as ties (or just count "points"), then the 1995-96 NJ Devils had a slightly worse winning percentage if you count ties as half-wins (but still over .500), and the 1990-91 Edmonton Oilers won only half their games exactly (37-37-6) - but made the playoffs and advanced to the conference finals, so I'm not sure that is quite the same.
To find a team that was in the class of the other three leagues (the other 3 major leagues have a team around .333), you have to go all the way back before the original six era to the 1938-39 Chicago Blackhawks, who at 12-28-8 had a .300 winning percentage of non-tied games, or a .333 winning percentage if you count ties as half-wins.  However, they're sort of a special case: the 1937-1938 Hawks won the championship with a record of only 14-25-9 - a .385 winning percentage counting ties as half wins!


When is a non-archimedean prime $v$ of a number field unramified in a Kummer extension?

Question: I have been working on the exercises of the book "Algebraic number theory" published by Frölich and Cassels. In one exercise, the following statement is given as a fact:

Let $K$ be a number field and $m\geq 2$. Let $v$ be a non-archimedean prime of $K$ which does not divide $m$, and let $a\in K^*$. Then the extension $K(a^{\frac{1}{m}})/K$ is unramified at $v$ if and only if $v(a)$ is divisible by $m$.

I have trouble writing down a proof for this statement, even after reviewing the chapter on Kummer theory inside the same book. In this chapter, it is proven that the discriminant of the extension $K(a^{\frac{1}{m}})/K$ divides $m^ma^{m-1}$, and hence a prime $v$ is unramified in particular if it does not divide $ma$ (ie in our case if $v(a)=0$, given that $v(m)$ is already $0$), which makes sense to me.
However I fail to see how to prove/justify the more general statement above. Could someone give me a hint or a reference for this ?
Answer: Suppose $v$ is normalized, i.e., its image is exactly $\mathbb{Z}$. $v$ can be extended (though in general not unique) from $K$ to $K(a^{1/m})$, denote this extension also by $v$.
If $m\nmid v(a)$, then from $mv(a^{1/m}) = v(a)$ we see that $v(a^{1/m})$ is not an integer, so $v$ is ramified.
If $m\mid v(a)$, let $\pi$ be a uniformizer of $K$ for $v$, write $a = \pi^{mn} b$ for $v(b) = 0$, then $K(a^{1/m}) = K(b^{1/m})$. The discriminant now divides $m^m b^{m-1}$, which has valuation $0$, therefore $v$ is unramified.
Comment: Very very nice ! Thank you so much for this proof Pisco, it helps me a lot.


How to use an index on a list of values?

Question: I have a query with a join on mytable unique indexed on (col1,col2)
explain
...
join mytable on col1=1 and col2=2

shows the correct use of the index with type: eq_ref
But when using a list the index is not used anymore
join mytable on col1=1 and col2 in (2,3,4)

Extra: Range checked for each record (index map: 0x1);
This gives the same result:
join mytable on (col1,col2) in ((1,2),(1,3),(1,4))

Is there a way to use an index when providing a list of values?
Comment: It may depend on the version, but certainly in my (rather old) version of sql, this is the case. So, the solution is to write it as a series of parenthesised ORs.
Answer:
Normally one does not JOIN x ON c = constant.  The ON clause should specify how this table is related to the other table(s).  The WHERE clause should provide for filtering, such as col1=1 and col2=2.
"Row constructors" have long existed, but only recently (5.7.3) are they the least bit optimized.  What version are you running?  Even with the latest version, I would expect col1=1 and col2 in (2,3,4) to be optimized at least as well as the row-constructor approach.
OR often prevents any optimization.  And perhaps it is never faster than some alternative.
We need to see the entire query, the EXPLAIN, and SHOW CREATE TABLE; there could be other issue lurking in the shadows.


How to change the h1 tag inside a div with the help of map function in react functional component?

Question: const fruit = ["Apple", "Mango", "Litchi", "Pineapple"]

{fruit}

I tried to map the value of fruit for every h1 tag but it is not doing the mapping
Comment: You will need to use a `map` to loop thru your array and render it
Answer: Are you looking for something like this ? Or please write more details how you want your final result result.
const fruit = ["Apple", "Mango", "Litchi", "Pineapple"]

        { fruit.map(f =>
{f}
 ) }