Why apcupsd won't see the UPS connected to the USB posrt on FreeBSD 8.0 amd64

Question: Recently I installed an apcusbd on a FreeBSD 8.0 amd64 box via ports system. It installed perfectly but it won't run.
Here what is says in the log: FATAL ERROR in generic-usb.c at line 636 Cannot find UPS
device
It appeared that HID driver picked the /dev/ugen4.2 which could cause the apcusb being
unable to find the device.  After I had discovered this, I rebuilt the kernel and removed the hid driver. Now it just shows "ugen4.2: <Tripp Lite> at usbus4" and no uhid0 device appears.
Nevertheless the problem persisted. I tried to leave the DEVICE config setting blank ---  won't help. Then I specified the particular device in the config, but it did not help either.
Below you is the output of several commands that can provide some useful information on my case.

server# /usr/local/etc/rc.d/apcupsd start
Starting apcupsd.

server# tail /var/log/messages | grep apcupsd
Jun 17 22:30:00 server apcupsd[1520]: apcupsd FATAL ERROR in generic-usb.c at line 636
Cannot find UPS device -- For a link to detailed USB trouble shooting information, please
see .
Jun 17 22:30:00 server apcupsd[1520]: apcupsd error shutdown completed

server# cat /usr/local/etc/apcupsd/apcupsd.conf
## apcupsd.conf v1.1 ##
UPSCABLE usb
UPSTYPE usb
DEVICE /dev/ugen4.2
LOCKFILE /var/lock
UPSCLASS standalone
UPSMODE disable

server# dmesg | grep '^u'
uhci0:  port 0xa800-0xa81f irq 16 at device 26.0 on pci0
uhci0: [ITHREAD]
uhci0: LegSup = 0x0f00
usbus0:  on uhci0
uhci1:  port 0xa880-0xa89f irq 21 at device 26.1 on pci0
uhci1: [ITHREAD]
uhci1: LegSup = 0x0f00
usbus1:  on uhci1
uhci2:  port 0xac00-0xac1f irq 18 at device 26.2 on pci0
uhci2: [ITHREAD]
uhci2: LegSup = 0x0f00
usbus2:  on uhci2
usbus3: EHCI version 1.0
usbus3:  on ehci0
uhci3:  port 0xa080-0xa09f irq 23 at device 29.0 on pci0
uhci3: [ITHREAD]
uhci3: LegSup = 0x0f00
usbus4:  on uhci3
uhci4:  port 0xa400-0xa41f irq 19 at device 29.1 on pci0
uhci4: [ITHREAD]
uhci4: LegSup = 0x0f00
usbus5:  on uhci4
uhci5:  port 0xa480-0xa49f irq 18 at device 29.2 on pci0
uhci5: [ITHREAD]
uhci5: LegSup = 0x0f00
usbus6:  on uhci5
usbus7: EHCI version 1.0
usbus7:  on ehci1
uart0:  port 0x3f8-0x3ff irq 4 flags 0x10 on acpi0
uart0: [FILTER]
usbus0: 12Mbps Full Speed USB v1.0
usbus1: 12Mbps Full Speed USB v1.0
usbus2: 12Mbps Full Speed USB v1.0
usbus3: 480Mbps High Speed USB v2.0
usbus4: 12Mbps Full Speed USB v1.0
usbus5: 12Mbps Full Speed USB v1.0
usbus6: 12Mbps Full Speed USB v1.0
usbus7: 480Mbps High Speed USB v2.0
ugen0.1:  at usbus0
uhub0:  on usbus0
ugen1.1:  at usbus1
uhub1:  on usbus1
ugen2.1:  at usbus2
uhub2:  on usbus2
ugen3.1:  at usbus3
uhub3:  on usbus3
ugen4.1:  at usbus4
uhub4:  on usbus4
ugen5.1:  at usbus5
uhub5:  on usbus5
ugen6.1:  at usbus6
uhub6:  on usbus6
ugen7.1:  at usbus7
uhub7:  on usbus7
uhub0: 2 ports with 2 removable, self powered
uhub1: 2 ports with 2 removable, self powered
uhub2: 2 ports with 2 removable, self powered
uhub4: 2 ports with 2 removable, self powered
uhub5: 2 ports with 2 removable, self powered
uhub6: 2 ports with 2 removable, self powered
uhub3: 6 ports with 6 removable, self powered
uhub7: 6 ports with 6 removable, self powered
ugen4.2:  at usbus4
server#
Answer: You'll probably have better luck asking the APCUPSd guys. I've never configured it for anything but a serial APC UPS.
Answer: I had a very similar config on linux which also didn't work.
For me editing apcupsd.conf by changing the line
DEVICE /dev/ugen4.2
to simply
DEVICE
got it working. Seems if you're connecting over USB it can work it out and doesn't need to be told which device to use.
Comment: This should work. It's what the commented configuration file recommends on many platforms.


How to do path aliases for views like news/%?

Question: Let's suppose we have a view like news/%.
Where news is my content type, and % is tid of term id from vocabulary "categories".
Obviously that urls like news/3, news/5 etc. works great. But how to do the path aliases for this kind of urls, generated from this view?
I want like this:

news/% -> company-news/[term:name]
Example: news/3 -> company-news/accidents

(where [term:name] transliterated term name from original title, because my site not on english language)
P.s. the just using pathauto for taxonomy terms, and the view "taxonomy/term/%" does not suit, because one term is used by multiple content types, and therefore in multiple views.
Answer: That is quite a tricky one.
Two possible solutions:
1)
Use page manager, create a context for each content type, and then use this module to generate the aliases): https://www.drupal.org/project/page_manager_pathauto (note: no Drupal 8 version)
2) Add/remove/modify the aliases yourself with an update hook.  So when a node is updated, you create/update/delete the corresponding path aliases.
Comment: I'm used advice # 2
Comment: I'm used advice # 2.
I create a custom module for extra path alias creation, where I use hook_ENTITY_TYPE_insert to generate new alias for term, when it was saved. With
    \Drupal::service('path.alias_storage')->save($origin_path, $new_alias, $entity_language_id);


Simple calculator app for android

Question: I've got a strange issue with this simple calculator app.
Adding/subtracting/multiplying and dividing work, but:
1. When multiplying numbers with decimal value (everything is done in doubles) my result is multiplied by 10.
Example: 7*7 gives me 49.0
2. When multiplying numbers I sometimes get a nearly good result (just multiplied by 10, BUT it's followed by a lot of zeroes and 1 at the end)
Example: 1.1*1.1=12.100000000000001
package org.example.paweljezierski.calculator;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    //I'm declaring every button so I'm able to use it
    //I could probably do it in one line, but it's cleaner this way
    Button buttonplus;
    Button buttonminus;
    Button buttonmultiply;
    Button buttonpower;
    Button buttondivide;
    Button buttonequals;
    Button buttondot;
    Button buttonclear;
    Button button1;
    Button button2;
    Button button3;
    Button button4;
    Button button5;
    Button button6;
    Button button7;
    Button button8;
    Button button9;
    Button button0;

    //I'm declaring every TextView
    TextView textresult;
    TextView textinput;

    //value1, value2 are two values that we'll do math on
    double value1 = 0, value2 = 0, result = 0;
    //mathoperation will be set to [1;4] by operation button to know what math to do later
    int mathoperation = 0;
    //for holding information
    String a, a2, aa, n;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        // Initialize both text fields
        textresult = (TextView)findViewById(R.id.textresult);
        textinput = (TextView)findViewById(R.id.textinput);

        //I initialize every button
        buttonplus =(Button)findViewById(R.id.buttonplus);
        buttonminus =(Button)findViewById(R.id.buttonminus);
        buttonmultiply =(Button)findViewById(R.id.buttonmultiply);
        buttondivide =(Button)findViewById(R.id.buttondivide);
        buttonpower =(Button)findViewById(R.id.buttonpower);
        buttondivide =(Button)findViewById(R.id.buttondivide);
        buttonequals =(Button)findViewById(R.id.buttonequals);
        buttondot =(Button)findViewById(R.id.buttondot);
        buttonclear=(Button) findViewById(R.id.buttonclear);
        button1 =(Button)findViewById(R.id.button1);
        button2 =(Button)findViewById(R.id.button2);
        button3 =(Button)findViewById(R.id.button3);
        button4 =(Button)findViewById(R.id.button4);
        button5 =(Button)findViewById(R.id.button5);
        button6 =(Button)findViewById(R.id.button6);
        button7 =(Button)findViewById(R.id.button7);
        button8 =(Button)findViewById(R.id.button8);
        button9 =(Button)findViewById(R.id.button9);
        button0 =(Button)findViewById(R.id.button0);

        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                a=textinput.getText().toString();
                a=a+"1";
                a2=a2+"1";
                textinput.setText(a);
            }
        });

        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                a=textinput.getText().toString();
                a=a+"2";
                a2=a2+"2";
                textinput.setText(a);
            }
        });

        button3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                a=textinput.getText().toString();
                a=a+"3";
                a2=a2+"3";
                textinput.setText(a);
            }
        });

        button4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                a=textinput.getText().toString();
                a=a+"4";
                a2=a2+"4";
                textinput.setText(a);
            }
        });

        button5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                a=textinput.getText().toString();
                a=a+"5";
                a2=a2+"5";
                textinput.setText(a);
            }
        });
        button6.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                a=textinput.getText().toString();
                a=a+"6";
                a2=a2+"6";
                textinput.setText(a);
            }
        });

        button7.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                a=textinput.getText().toString();
                a=a+"7";
                a2=a2+"7";
                textinput.setText(a);
            }
        });

        button8.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                a=textinput.getText().toString();
                a=a+"8";
                a2=a2+"8";
                textinput.setText(a);
            }
        });

        button9.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                a=textinput.getText().toString();
                a=a+"9";
                a2=a2+"9";
                textinput.setText(a);
            }
        });

        button0.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                a=textinput.getText().toString();
                a=a+"0";
                a2=a2+"0";
                textinput.setText(a);
            }
        });

        buttondot.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                a=textinput.getText().toString();
                a=a+".";
                textinput.setText(a);
            }
        });

        buttonplus.setOnClickListener(new View.OnClickListener()
        {

            public void onClick(View v) {

                if (mathoperation == 0)
                {
                aa=a;
                mathoperation=1;
                a=a+" + ";
                textinput.setText(a);
                a2 = "0";
                }
            }
        });

        buttonminus.setOnClickListener(new View.OnClickListener()
        {

            public void onClick(View v) {

                if (mathoperation == 0)
                {
                    aa=a;
                    mathoperation=2;
                    a=a+" - ";
                    textinput.setText(a);
                    a2 = "0";
                }
            }
        });

        buttonmultiply.setOnClickListener(new View.OnClickListener()
        {

            public void onClick(View v) {

                if (mathoperation == 0)
                {
                    aa=a;
                    mathoperation=3;
                    a=a+" * ";
                    textinput.setText(a);
                    a2 = "0";
                }
            }
        });

        buttondivide.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {

                if (mathoperation == 0) {
                    aa = a;
                    mathoperation = 4;
                    a=a+" / ";
                    textinput.setText(a);
                    a2 = "0";
                }
            }
        });

        buttonclear.setOnClickListener(new View.OnClickListener()
        {

            public void onClick(View v) {
                aa = "";
                a = "0";
                mathoperation = 0;
                result = 0;
                textinput.setText("");
                textresult.setText("");
            }
        });

        buttonequals.setOnClickListener(new View.OnClickListener()
        {

            public void onClick(View v) {

                if(mathoperation==1){
                    value1=Double.parseDouble(aa);
                    value2=Double.parseDouble(a2);
                    result = value1 + value2;
                }
                else
                if(mathoperation==2){
                    value1=Double.parseDouble(aa);
                    value2=Double.parseDouble(a2);
                    result = value1 - value2;
                }else
                if(mathoperation==3){
                    value1=Double.parseDouble(aa);
                    value2=Double.parseDouble(a2);
                    result = value1 * value2;
                }
                else
                if(mathoperation==4){
                    value1=Double.parseDouble(aa);
                    value2=Double.parseDouble(a2);
                    result = value1 / value2;
                }
                n = Double.toString(result);
                textresult.setText(n);
                aa = "";
                a = "0";
                mathoperation = 0;
                result = 0;
            }
        });

//        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
//        fab.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
//                        .setAction("Action", null).show();
//            }
//        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

Edit: I would like to hide zeroes if there is no value diffrent from zero after them.
Let's say I calculate 7*0.7 and show only 6 values after .
It'll give me 4.900000
I want to hide the five zeroes.
How to do that?
Answer: Here is what you do :
click Button1
    a=1
    a2=1
click Button.
    a=1.
    // add "a2=1."
click Button1
    a=1.1
    a2=11 <---
click ButtonMultiply
    operation=3
    aa=1.1
    a=1.1*
    a2=0
click Button1
    a=1.1*1
    a2=1
click Button.
    a=1.1*1.
    // add "a2=1."
click Button1
    a=1.1*1.1
    a2=11 <-----
click Buttonresult
    value1 = 1.1
    value2 = 11
    // value2 = 1.1
    result = 12.10000000000000000000001
    // result = 1.210000000000000001

When you click buttondot you also need to do a2=a2+"."
In other words :
     buttondot.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            a=textinput.getText().toString();
            a=a+".";
            a2=a2+".";
            textinput.setText(a);
        }
    })

For formatting double after that : Round a double to 2 decimal places
PS : Welcome on Stackoverflow !!
Comment: `short` is not good enough for a calculator app where you only get 16 bits (–32,768 to 32,767 ). `Integer` is the least I would use, but recommend using `long`

Simple calculator app for android


My functions have return statements, so why am I getting this error? TypeError: can only concatenate str (not "NoneType") to str

Question: This method is part of a class that converts inputs from infix to postfix. An example input would be: "11.897/3.4+9.2-0.4*6.9/12.6-16.7="
I have some helper methods below the main method (getPostFix).
I can't understand why the code result += ipop is causing the error. I use the same code snippets later in the code, so maybe I will have to fix those instances as well. I read some other answers in which the answers seemed to ask the OP - "well what if this function returns False?" But which functions and why would they do that?
    def getPostFix(self):

        result = ""

        # stack used to create postfix string
        self.stack = MyStack()

        input_string = self.getInput()
        input_string_split = [x for x in re.split("(\d*\.?\d*)", input_string) if x != '']

        for i in input_string_split:

            if isOperand(i):
                result += i

            elif isOperator(i):
                while True:
                    topItem = self.stack.getTop()
                    if self.stack.size == 0 or topItem == '(':
                        self.stack.push(i)
                        break
                    else:
                        precedence_i = getPrecedence(i)
                        precedence_topItem = getPrecedence(topItem)

                        if precedence_i > precedence_topItem:
                            self.stack.push(i)
                            break
                        else:
                            ipop = self.stack.pop()
                            result += ipop
                            #result += self.stack.pop()

            elif i == '(':
                self.stack.push(i)

            elif i == ')':
                ipop = self.stack.pop()

                while ipop != '(':
                    result += ipop
                    ipop = self.stack.pop()

            elif i == '=':
                ipop = self.stack.pop()
                result += ipop
                #result += self.stack.pop()

        while not self.stack.size == 0:
            ipop = self.stack.pop()
            result += ipop

def isOperand(c):
    return c >= '0' and c <= '9'

operators = "+-*/^"

def isOperator(c):
    return c in operators

def getPrecedence(c):
    result = 0

    for i in operators:
        result += 1

        # because + - and */ have the same value
        # these if statements will set their value equal to each other
        # for, example when I get to -, the result count is 2, but I subtract 1 to get 1
        # which is the same result count as +.
        if i == c:
            if c in '-/':
                result -= 1
            break

    return result

Here is the error code:
Traceback (most recent call last):
  File " ", line 9, in <module>
    print(calc)
  File " ", line 23, in __str__
    theCalc += 'Postfix input is: ' + self.getPostFix() + '\n'
  File " ", line 71, in getPostFix
    result += ipop
TypeError: can only concatenate str (not "NoneType") to str

Comment: return statement in getPostFix is missing. Hence
    theCalc += 'Postfix input is: ' + self.getPostFix() + '\n'
throws error as self.getPostFix() returns None
Answer: Because sometimes you're popping at the end of the iterable and it returns None, try replacing all the lines of
result += ipop

with
result += ipop if ipop else ""  # Handles None cases and returns empty string.

Comment: You forgot to `return result` at the end of `getPostFix` function =)
Comment: I did that and get the same error: ```theCalc += 'Postfix input is: ' + self.getPostFix() + '\n'
TypeError: can only concatenate str (not "NoneType") to str```


How can I return javascript from a Ruby on Rails helper method?

Question: I have a Note model, which can contain have either an image link attachment (linktype = "image" or some text (linktype = "text). When I display the notes, the method of display changes depending on the linktype. An example is:
<% @notes.each do |q| %>

<%= q.name %>

    <% if q.linktype == "other"%>

    <% elsif q.linktype == "text"%>
        <%= q.text %>
    <% elsif q.linktype == "image"%>
       <img src="<%= q.link %>" />
    <% end %>
<% end %>

I have to display the notes in a few different views in my site, so rather than have to repeat the viewing code multiple times, I want to have it in one place and refer to it from different views.
My initial thought was to put the display code in a helper, something like this:
<% @notes.each do |q| %>
    note_display(q.linktype, q.link)
<% end %>

But some of the displaying involves javascript (line 4 in first code block). Can I still use a helper method, even though I would need it to return javascript? If so, how do I do it? Thanks for reading.
Answer: There's nothing special about javascript, you can return it from helpers as you would return other html content. The only thing I would suggest is to use helpers for tags like
image_tag(q.link)
javascript_tag("some javascript")
content_tag("h2", q.name, :class => "title")

Answer: As far as ERB is concerned, JavaScript is just string content like anything else rendered by a template. So your helper method can just construct and return a string:
def note_display(note)
  content = ''
  content << content_tag('h2', h(note.name), :class => 'title')
  if note.linktype == 'other'
    content << javascript_tag("some javascript")
  elsif note.linktype == 'text'
    content << h(note.text)
  elsif note.linktype == 'image'
    content << image_tag(note.link)
  end
  content
end

You can use this helper method using:
<% @notes.each do |n| %>
  <%= note_display(n) %>
<% end %>


Django Sites Framework on Localhost Based on Port (8001, 8002, 8003)

Question: I'm developing on localhost, assigning each port (8001, 8002, 8003) to correspond to each site (site1.com, site2.com, site3.com).
How do I get the Django sites framework to recognize these ports as sites, or cause them to correspond?
Comment: How are you running your Django code?  On a ngnix or apache web server or just executing `python manage.py runserver ...`?
Comment: This may help you: https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/gunicorn/
Comment: I'm running on Gunicorn nginx. I tried to differentiate them by simply appending the port to each domain name but it seems to default to the same example.com based on 127.0.0.1, ignoring the 8002, etc.
Answer: I ended up doing this (on Ubuntu)
/etc/hosts
127.0.11.1  site1.local
127.0.12.1  site2.local
127.0.13.1  site3.local

Then in Django Sites:
site1.local, site1.local
site2.local, site2.local
site3.local, site3.local

Then in nginx sites available/enabled
server {
    listen 127.0.11.1;
    server_name site1.com;

    location = /favicon.ico { access_log off; log_not_found off; }

    location /static/ {
        autoindex on;
        alias /home/.../static/;
    }
    location /media/ {
        autoindex on;
        alias /home/.../media/;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
    }
}

Then, KEY POINT, do NOT use SITE_ID variable in settings.
Then I isolate it with
get_current_site(request).domain


I want to subtract 30 minutes from a time

Question: Hello My question is simple, Please let me know how i can subtract 30 minutes from a time my code is :
$endDate = date("Y-m-d H:i:s", $futureDate);

        $d_newdate = strtotime($endDate);
        $d_newdate1 = $d_newdate - ('30 minutes');
        echo $d_newdate2 = date("Y-m-d H:i:s", $d_newdate1);die("workings");

This code is adding one hour in time its wrong.i want to subtract 30 minutes.
Comment: possible duplicate of [PHP, subtract minutes](http://stackoverflow.com/questions/17717911/php-subtract-minutes)
Comment: Man... Just google "how i can subtract 30 minutes from a time my code" and the first entry will take you to @Saty link. Google your own question.
Answer: $date = '2015-08-02 15:30:00';
echo $date."
";
echo date('Y-m-d H:i:s',strtotime("-30 minutes",strtotime($date)));

Answer: echo date("Y-m-d H:i:s")."
";
echo date("Y-m-d H:i:s",strtotime('-30 minutes'));

Answer: Try to use this
$d_newdate = strtotime($endDate);

$d_newdate1 = $d_newdate - (30 * 60);

$new_time = date("Y-m-d H:i:s", $d_newdate1);

Comment: Its working fine for me as I tested before posting here. What problem you are facing? are you getting right value in your variable `$endDate`
Comment: I resolve this .now my new query is how i can retrieve all the records from data base in between two date time my query is :

 SELECT * FROM `appointment` WHERE `ap_datetime` = '2015-09-08 01:30:00' AND (`cur_datetime` BETWEEN '2015-09-08 01:30:00' AND '2015-09-08 02:30:00')


Classical examples of a 'fifth voice' or 'ghost soprano'

Question: There is an interesting phenomenon in choral (and perhaps also instrumental?) singing in which typically four voices are arranges in such a way that a 'fifth voice' or 'ghost voice' can be heard. It is not terribly well documented, but Barbershop makes use of it fairly often (see here for some explanation and here for some audio example. I've also found some examples of traditional 4-part songs from Sardinia where this phenomenon is used, as thoroughly described here (only in French), including frequency analysis and all.
What examples of the same phenomenon in classical music. Most examples can probably be found in Renaissance music, but I am not sure of this. I found one very good example in a piece by Cipriano da Rore: Mia benigna fortuna (Audio example here). In this piece, at the end of the first phrase, you can clearly hear a voice that isn't actually sung. This is the score:

I would very much like to hear if people know different examples of the same phenomenon in classical music, perhaps in Renaissance music but maybe also in other styles. Also, is anyone aware of literature on this topic specifically?
Comment: I think it is important to clarify *exactly* what is being discussed - subharmonics, "ghost tones" or "implied harmony", combination tones, and just intonation are all different subjects and I think, are being mushed together here in a misguided albeit earnest thought. Alexander Troup - could you explain in specific detail how subharmonics may be in play? I currently do not see the correlation.  Also, I listened to the excerpted passage above about a dozen times and was unable to hear the phenomenon described.
Comment: This is a phenomena caused by subharmonics that naturally occurr when waveforms are combined.  It's not an answer but you might want to check out Throat singing.  Joe satriani uses it in http://www.youtube.com/watch?v=SINl5JY7LhI where the opening effect is created by moving the guitar around the room such that it resonates with a different harmonic, changing the sound.
Answer: Adding an example to jjmusicnotes' great answer: a ghost "tenor" (that is the third voice from the top) happens in many cases where two flutes or even a flute and a clarinet play a minor third apart in the range near the top of the treble clef staff and create a difference tone of 2*frequency(lower) - frequency(upper) which is also approximately minor third below the lower note, creating the impression of a diminished triad.  An acoustics textbook I once read mentioned this as taking place at the end of a flute duet in a symphony by Vaughn Williams.  I've heard it very strongly when playing a flute duet by Kuhlau (op. 81, no. 1) on flute and clarinet at m. 114 (1:28 at

 ; score: http://erato.uvt.nl/files/imglnks/usimg/c/cd/IMSLP15021-3_Brilliant_Duos__Op_81__2_Flutes_.pdf) -- it's noticeable on the recording but incredibly loud when played with flute and clarinet.  Of course the acoustics of the space have a lot to do with whether ghost voices emerge or not; hence why the Sardinians you mention sing very close to each other, facing inwards.  (In their music, the fifth voice is called La Quinta or La Quintina -- the little fifth; note the feminine)
Comment: If two pitches are a minor 3rd apart, the third pitch you mention is a major, not a minor, 3rd below the lower. The three pitches' frequencies are in the ratio 6:5:4. The difference pitch more likely to be heard, I think, is the one whose frequency is f(upper)-f(lower). This is 2 octaves below the pitch you describe.
Comment: The frequencies would be 6:5:1 -- the ghost being two octaves and a third below the lower note.
Answer: As you mentioned in your question, there is little documentation about this phenomenon.  Therefore I will preface my answer by saying that it (my answer) is speculation based from what knowledge I have of acoustics, historical performance practice, and literature.
I am not aware of any piece of music that was conceived with the intention of being constructed with or around the ghost-voice phenomenon.  Considering that it is most prominent using just intonation, we could then surmise that musicians during the Renaissance and early Baroque periods most likely experienced ghost-voices since secular musical material consisted dominantly of motets and chansons and Just Intonation was the primary tuning system.
That said, since the tuning system itself was different (and the notation stayed the same, generally speaking,) that would mean that even if Renaissance motets were sung in a contemporary setting, they would be sung and tuned in an Equal-Temperament system.  Therefore, to properly experience this phenomenon in the literature, you would have to time travel approximately 500-700 years in the past in order to hear the music in its proper (original) temperament.

Why is this important?  Why does it work best with Just Intonation?
The answer to this is two-fold: the overtone series, combination tones, and overtone singing.
Okay, maybe it's three-fold.
In Just Intonation, the emphasis is on tuning perfect octaves and fifths as they are the easiest interval to hear apart from the unison.  These intervals were tuned "perfectly" - regardless of their proximity to other, less important intervals.
Okay, so why does that matter?  The answer is: Organs.
For their lowest pitches, pipe organs actually make use of their own phenomenon called combination tones in which two pipes of equal length will vibrate at the same pitch adjacent to one another.  The additive combination of their frequencies / wavelengths produces a perceived sound an octave lower.
Singing a perfect fifth or a perfect octave in Just Intonation allows combination tones to flourish as they are tuned to small whole integers and not a fractional ratio like Equal Temperament.  If you follow the link on combination tones, you'll see that they can even produce multiple perceived pitches as the "sum" or the "difference" between the two pitches.
Therefore, when you experience a "ghost voice" in a piece of music, it is the result of combination tones highlighting upper partials in the overtone series - creating the illusion that more pitches are being produced than are physically being produced.
Other examples of this type of phenomenon may be found in Tuvan Throat / Overtone Singing in which individuals manipulate their vocal folds to reinforce particular harmonics - frequently often able to produce several pitches simultaneously.  These are quite a bit different than combination tones, but it is part of their performance practice.
From Tuva, cases may also be made for Tibetan throat singing and perhaps even Russian Orthodox singing technique as well.  So, while it is difficult to produce documentation or literature in the Western musical tradition concerning "ghost voices" examples of this phenomenon can be logically considered to have existed in historical practice and in Eastern cultures around the world.
Hope that helps.
Comment: Your description of combination tones for pipe organs is wrong -- it's two pipes at different pitches (usually a note and a fifth above), and thus different lengths, to produce the effect of a lower pitch.
Comment: @ Dave Thank you for the source - it was an interesting read.  Apparently, we are both mistaken, according to the article combination (or "resultant") tones **do not exist**.
Answer: I am not an authority on the subject of ghost/fifth voice -- but I do sing in choir and in a Barbershop Chorus / quartet. the latter of which intentionally seeks to produce the Fifth voice quite often in songs.
It is my understanding that the fifth Voice is achieved when the vibratory frequency of the 4 part vocalizations blend together in a precise way. You hear the phenomena mainly with voices like those heard in barbershop.
The equal temperament tuning of modern instruments (A-440), prevents the necessary original frequencies of vibrations from occurring.  However, the human voice is not restricted in the way that a piano keyboard is restricted.  The human voice can sing all the frequencies between the notes on the keyboard.
At one point in the past -- it was decided that  there were advantages to having more range /notes on the piano keyboard, but it wasn't as simple as just adding notes to the left and right of middle C. This was because the further you went out to the left or right the more the notes tended to become unpleasant when combined with other instruments.
To get the wider range of notes, it was decided it would be best to make ALL the notes "equally out of tune" (The notes at the extremes sounded better but it left the other notes slightly less pure). The difference between the new notes vs original notes was hardly perceptible to the average listener.
The human voice (and some instruments) can can shift frequency away from the standard modern tuning to achieve fifth /ghost voice.
This may be oversimplistic so I welcome corrections from others if they need to be made.
Answer: Interesting discussion. Apparently, if the root frequency is removed electronically from a note with only the overtones remaining, the human ear/brain actually "hears" the root tone as well. There seems to be many ways in which overtones are "used" by musicians to create additional melody lines. Anna-Maria Hefele can actually sing two melodies at the same time by controlling the overtones with the shape of her mouth. The fifth "ghost soprano" seems to be a different use of overtones where the quartet voices enhance and enlarge specific pitches producing the sound appearance of a fifth voice. I believe at one time in the religious communities they believed that if the quartet sang perfectly enough the Virgin Mary joined them. The study of overtones is very interesting, and is related to the study of how our brain processes music.
Comment: This does not provide an answer to the question. Once you have sufficient [reputation](https://music.stackexchange.com/help/whats-reputation) you will be able to [comment on any post](https://music.stackexchange.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/73459)


URL to open facebook app in android

Question:
Possible Duplicate:
Open Facebook page from Android app?

I have a webview in my android app, and I would like to put a link in that opens the facebook app to my fanpage. In iOS you can say fb://... and it will open the facebook app. Is there a way to do it in android?  I'm already overriding shouldOverrideUrlLoading, so I could intercept it and launch an intent if I need to.
Answer: You need to use Intents. Here's how to call the FB application (if it is installed):
Intent intent = new Intent();
intent.setClassName("com.facebook.katana","com.facebook.katana.ProxyAuth");
intent.putExtra("client_id", applicationId);
mAuthActivityCode = activityCode;
activity.startActivityForResult(intent, activityCode);

This code is taken from the Facebook API, which authorizes an action. Ajust to suit your needs. Code is Copyright 2010 Facebook, Inc., licensed under the Apache License, Version 2.0.
Comment: thanks, I've almost got it working. I'm not sure what the activity codes are though. and for application ID is that my fan page id? I can't seem to find very good documentation on this.
Comment: Try the code presented here: http://stackoverflow.com/questions/4810803/open-facebook-page-from-android-app/4814030#4814030
Answer: myWebView = (WebView) findViewById(R.id.webview); // Create an instance of WebView and set it to the layout component created with id webview in main.xml
        myWebView.getSettings().setJavaScriptEnabled(true);
        myWebView.loadUrl("http://m.facebook.com/pages/xxxxx-xxxxx-xxxxx/xxxxxxxxxx"); // Specify the URL to load when the application starts
        //myWebView.loadUrl("file://sdcard/"); // Specify a local file to load when the application starts. Will only load file types WebView supports
        myWebView.setWebViewClient(new WebViewKeep());
        myWebView.setInitialScale(1); // Set the initial zoom scale
        myWebView.getSettings().setBuiltInZoomControls(true); // Initialize zoom controls for your WebView component
        myWebView.getSettings().setUseWideViewPort(true); // Initializes double-tap zoom control

Check if this works for you.

URL to open facebook app in android


Apache how to create default host for https

Question: I have several sites on my server. For example: domain1.com and domain2.com.
If user requests a not existing sub-domain (For example: a.domain2.com) he will be redirected to domain1.com. I want to show 404 page if this situation happens. For http traffic I use such config for vhost:
<VirtualHost _default_:80>
    Redirect 404 /
    ErrorDocument 404 "Page Not Found"
</VirtualHost>

I also have https versions of my sites. I have tried to do something like this:
<VirtualHost _default_:433>
    Redirect 404 /
    ErrorDocument 404 "Page Not Found"
</VirtualHost>

But my https sites stop opening. How to achive http behavior for https?
Comment: What error do you get when trying HTTPS?
Comment: Chrome says that your connection is not private.
Comment: Rereading through your post, can you clarify: You have the several web sites working fine... but when you put this entry in your config file, all the HTTPS sites stop working. Is that correct?
Answer: My guess right now is one of two things:

You do not have an SSL certificate specified for the HTTPS virtual host
Your certificate is for domain1.com, but is not a wild card certificate and/or does not have a Subject Alternative Name for a.domain1.com configured.

If you want HTTPS to work for a.domain1.com and b.domain1.com and whatever.domain1.com, your best option is to get a wildcard certificate for *.domain1.com
Comment: I have correctly configured named vhosts for my https versions of sites. But when I'm trying to add default vhost for *:443 apache starts ignoring my named vhosts. Crome start saying that your connection is not private and doesn't show anything but error page. I have tried to use "SSLEngine on" but than I should configure correct ssl certificates. I don't know what ssl certificate to use. I want common solution for many domains.
Comment: Chrome will usually include in the error... something like "NET::ERR_CERT_COMMON_NAME_INVALID". Do you see anything like that? What does it say?


Shafarevich Exercise 1.10. Find all the automorphisms of the curve $y^2 = x^3 + x^2$

Question: I get stuck on finding all automorphisms of the curve $y^2 = x^3 + x^2$.
I tried to use homogeneous coordinates: $
\zeta \eta^2 = \xi^3 + \zeta \xi^2$, $x = \xi/\zeta, y=\eta/\zeta$.
There is one singular point $(0,0,1)$.
Could someone  help how to proceed?
Answer: Note: I made some silly errors originally, now corrected.
I hope you've drawn the picture.
I like to give this curve (but not this question) to Calculus students, when they learn about parametric description of curves. Here, you take a line passing through the origin, $y=tx$, and see that it intersects the curve in three points, as it must, namely the origin counted twice and $(t^2-1,t^3-t)$.
Find the automorphisms of the affine line (or projective line, if you're working projectively) that leave $\pm1$ fixed (or maybe exchange the two) and you've solved the problem.
Comment: you mean $(t^2-1,t^3-1)$?
Comment: No, since those do not satisfy $y^2=x^3+x^2$, and that $y$ is not $t$ times that $x$.
Comment: I do apologize for making a mess of this at first. You deserved better.
Comment: I just want to be sure that I solved it correct. As the birational automorphism of projective line is $x -> \frac{ax+b}{cx+d}$ (stated in Shafarevich), then the automorphisms on projective line has 2 fixed points (the roots of $x(cx+d)=ax+b$). So as we need to have  $\pm1$ fixed then for projective line it could be $x -> \frac{2x+3}{3x+2}$. Is it correct?
Comment: I think so. If you like, you may put the two fixed points at zero and infinity; then your automorphisms simply become  $x\mapsto\lambda x$ .  In other words there is a one-parameter family of such automorphisms.


Abstract algebra book suggestion

Question: I have been suggested Artin or Herstein's books. What do you think is more rigorous but at the same time clear and good to read?
Comment: For a clear, fun to read text, I highly recommend Pinter's "Book of Abstract Algebra". It is not rigorous, however. But it is absolutely loaded with exercises. I personally love it
Answer: Lang's Algebra is very nice, and van der Waerden (vol1, vol2) is the best I know of, together with Mac Lane & Birkhoff. I find the latter significantly harder to follow. There is also Dummit & Foote, at a level equivalent to Lang.
I don't own Artin's Algebra, but I'd say it's also at the level of Lang, and it has a very good reputation.
Edit: the other books I have are of Emil Artin. The Artin whose lectures the books by van der Waerden were originally based on (see here on Wikipedia). Michael Artin is actually his son, and is probably the author you are refering to.
Comment: Lang is terrible for a student. Go with Dummit and Foote.
Comment: @user62029 I edited the answer, since I didn't pay much attention: there are two Artin, both well known in algebra :-)
Comment: I think both Lang's and MacLane's books can be terrible for a beginner. Much better, imo, Dummit & Foote. Van der Waerden's already too old, imo again.
Comment: @Timbuc Agreed for MacLane & Birkhoff, which is quite hard, but I don't agree about Lang, I found it very clear, and I actually prefer it other Dummit & Foote. Matter of taste, since they are, I think, almost on the same level.
Comment: I think Lang is even worse than MacClane's for a beginner: it is way too dry, abstract and almost without examples...and it assumes already a lot as *it is a graduate text*. Perhaps you're thinking of Lang's *Undergraduate Algebra* ?
Comment: @Timbuc No, I had really *Algebra* in mind. Maybe I'm biased since I started with it after I finished my student life. However, having both today (and actually all I mentioned), I still don't agree. Just my humble opinion!
Comment: @Jean-ClaudeArbaut, anyway: Lang's "Algebra" ios for graduate level.
Comment: @Timbuc According to reviews, D&F is for advanced undergraduate or graduate, and I can only confirm they are more or less on the same level, IMO. I guess we could argue endlessly about it. Just an example: both Lang and D&F are used for graduate algebra at Stanford (see [here](http://math.stanford.edu/~vakil/10-210A/)) Maybe not the best example, since the prof. finds D&F a better text, and Lang for encyclopedic reference, but anyway...
Comment: Thanks for the answer and all the comments.

Abstract algebra book suggestion


I am getting a run time error '429'. Trying to get Excel macro to send a email

Question: Sub SendEmail()
'    SendEmail Macro
'
    Dim olApp As Outlook.Application
    Set olApp = CreateObject("Outlook.Application")

    Dim olMail As Outlook.MailItem
    Set olMail = olApp.CreateItem(olMailItem)

    olMail.To = ""
    olMail.CC = ""
    olMail.Subject = " There is a change to the EMR adjustment Form that Approval"
    olMail.Send
End Sub

Comment: @sous2817: Outlook must be installed otherwise the line `Dim olApp As Outlook.Application` would fail. And the code seems to fail at the line `Set olApp = CreateObject("Outlook.Application")`. Maybe [You receive run-time error 429 when you automate Office applications](https://support.microsoft.com/en-us/help/828550/you-receive-run-time-error-429-when-you-automate-office-applications) is helpful.
Comment: it says ActiveX component can't create object?
Comment: Do you have Outlook installed on the machine that's running the macro?
Answer: You are mixing up early and late binding,
Late binding uses either the Visual Basic GetObject function or the CreateObject function to initialize Outlook
Example

Dim olApp as Object
Set olApp = CreateObject("Outlook.Application")

To use early binding, you first need to set a reference to the Outlook object library, Microsoft Outlook xx.x Object Library
Example

Dim olApp as Outlook.Application
Set olApp = New Outlook.Application


MySQL Function retornando NULL

Question: Minha function não funciona por nada nesse mundo
O SQL está assim:
-- Function utilizada para retornar o espaço restante de uma pasta escolhida. --
DELIMITER $$
CREATE FUNCTION tamanhoRestante (_idPasta INT)
RETURNS INT
BEGIN

    DECLARE lpasTamanho INT;
    DECLARE lpasUsado INT;
    -- Aqui é verificado o tamanho TOTAL da pasta escolhida. --
    SELECT tamanho FROM pasta WHERE idPasta = _idPasta INTO lpasTamanho;
    -- E agora a verificação de todos os arquivos alocados nesta pasta. --
    IF(SELECT COUNT(*) FROM usuario JOIN usuario_has_pasta WHERE idUsuario = usuario_has_pasta.Usuario_idUsuario > 0) THEN
    SELECT SUM(arquivo.tamanho) FROM arquivo JOIN Pasta_has_Arquivo JOIN Pasta WHERE idArquivo = Arquivo_idArquivo AND Pasta_idPasta = _idPasta INTO lpasUsado;
    ELSE SET lpasUsado = 0;
    END IF;
    -- Agora faz-se o retorno do tamanho total da pasta subtraindo o total utilizado --
RETURN lpasTamanho - lpasUsado;

END
$$
DELIMITER ;

Neste teste, o lpasTotal = Tamanho total da pasta selecionada, e lpasUsado é a soma do tamanho de todos os arquivos linkado a esta pasta (através de uma ternária Pasta_has_Arquivo).
O lpasTamanho no teste tem tamanho 100, e o lpasTamanho fiz o teste com 0 e 50, mas em ambos retorna Null :/
Alguém pode me ajudar com isso? Não consigo encontrar o erro.
Comment: Adiciona na pergunta o resultado do select das tabelas fazendo o favor
Comment: O select esta bastante confuso. Mas para alimentar a variavel a partir do select faça algo assim: ´SELECT tamanho  INTO lpasTamanho FROM pasta WHERE idPasta = _idPasta;´
Comment: acredito que esse [link](http://stackoverflow.com/questions/3075147/select-into-variable-in-mysql-declare-causes-syntax-error) resolve seu problema, veja como é feito o INTO.
Comment: o que você pode fazer também é usar o SET no logar do INTO.
Comment: Obrigado pelas respostas pessoal! O problema não é o select, fiz o teste dele e está ok, o problema está na segunda parte, o SUM.. :/
Answer: Seu select tem alguns problemas:

A instrução INTO deve estar logo após a declaração do campo no select;
O campo idPasta está com _ no join;
Prefira usar inner join;

Ficaria mais ou menos assim após algumas correções:
-- Function utilizada para retornar o espaço restante de uma pasta escolhida. --
DELIMITER $$
CREATE FUNCTION tamanhoRestante (_idPasta INT)
RETURNS INT
BEGIN
  DECLARE lpasTamanho INT;
  DECLARE lpasUsado INT;

  -- Aqui é verificado o tamanho TOTAL da pasta escolhida. --
  SELECT tamanho
    INTO lpasTamanho
    FROM pasta
   WHERE idPasta = _idPasta;

  SET lpasUsado = 0;

  -- E agora a verificação de todos os arquivos alocados nesta pasta. --
  IF (EXISTS(SELECT 1 = 1
               FROM usuario u
               INNER JOIN usuario_has_pasta uhp ON u.idUsuario = uhp.Usuario_idUsuario)) THEN
  BEGIN
    SELECT SUM(COALESCE(arquivo.tamanho, 0))
      INTO lpasUsado
      FROM arquivo a
      LEFT JOIN Pasta_has_Arquivo pha ON a.idArquivo = pha.Arquivo_idArquivo
      LEFT JOIN Pasta p ON pha.Pasta_idPasta = p.idPasta;
  END;
  END IF;

  -- Agora faz-se o retorno do tamanho total da pasta subtraindo o total utilizado --
  RETURN lpasTamanho - lpasUsado;
END
$$
DELIMITER ;

A instrução EXISTS verifica se a referência retorna true, por isso é necessário colocar 1=1, que será executado apenas se o where for satisfeito.
Comment: Muito obrigado @Sorack!
Percebi alguns erros que tinha cometido com seu comentário, obrigado!

Porém ele ainda retorna NULL caso não existe nada no Pasta_has_Arquivo, caso eu adicione um arquivo lá e chame esta função, ele retorna o tamanho correto (Era para ele mostrar 100 caso não tivesse em um arquivo alocado, porém se eu alocar um arquivo com tamanho 5, ele mostra os exatos 95).
Comment: E perdão se estou sendo "folgado", mas poderia por gentileza me explicar oque seria este (SELECT 1 = 1 FROM usuario) ? Obrigado novamente amigo!
Comment: Vou alterar aqui então pra ficar mais usável e vc testa de novo por favor. Vou adicionar também a explicação do exists. Caso dê certo por favor aprove a resposta pra que alguém que tenha uma dúvida semelhante possa se beneficiar
Comment: Alterado e adicionada explicação do exists. Agora não deve retornar null mais
Comment: Obrigado novamente pelo seu tempo Sorack!
Infelizmente ele continua retornando NULL..

Se eu dou um SELECT * FROM pasta ele retorna os valores
id - tamanho
1 - 100
2 - 500
3 - 500

Porém se eu der um select tamanhorestante(1) ele retorna NULL (assim como utilizando as ids 2 e 3), porém se eu adicionar qualquer arquivo na pasta, ele retorna o valor certo, exemplo:
addArquivo(pasta1, arquivo1) (supondo que esse arquivo tenha 20 de tamanho)
tamanhorestante(pasta1) retorna 80..
Comment: Tenta trocar o "SELECT SUM(arquivo.tamanho)" por "SELECT SUM(COALESCE(arquivo.tamanho, 0))"
Comment: Também testei esse COALESCE e retorna NULL.. Acho que por enquanto irei desistir dele assim.. Estou a 2 horas tentando arrumar isso, já fiz alteração no banco inteiro, em todas as triggers, já testei sem nada no banco apenas esta function, e sempre o mesmo resultado, se não tiver nada alocado a pasta no pasta_has_arquivo, ele retorna null, se tiver mais de um arquivo, ele soma e retorna o valor exatamente como deveria, o unico problema é ele estar retornando null quando não se tem nada no pasta_has_arquivo com o id da pasta.. :/
Muitissimo obrigado Sorack, e desculpe o incomodo..
Comment: Ah sim, já sei qual o problema Kauan,  no segundo select mude os INNER para LEFT e mantenha o COALESCE

MySQL Function retornando NULL


Proof that $Γ'(1) = -γ$?

Question: I know that $Γ'(1) = -γ$, but how does one prove this?
Starting from the basics, we have that:
$$Γ(x) = \int_0^\infty  e^{-t} t^{x-1} dt$$
How do we differentiate this?  How do we then find that
$$Γ'(1) = \int_0^\infty  e^{-t} \log(t)  dt$$
and how would one solve this integral?
Comment: You can refer to [this posting](http://math.stackexchange.com/questions/112304/showing-that-gamma-int-0-infty-e-t-log-t-dt-where-gamma-is-t/112310#112310).
Answer: Taken from this answer:
By the recursive relation $\Gamma(x+1)=x\Gamma(x)$, we get
$$
\small{\log(\Gamma(x))=\log(\Gamma(n+x))-\log(x)-\log(x+1)-\log(x+2)-\dots-\log(x+n-1)}\tag{1}
$$
Differentiating $(1)$ with respect to $x$, evaluating at $x=1$, and letting $n\to\infty$ yields
$$
\begin{align}
\frac{\Gamma'(1)}{\Gamma(1)}&=\log(n)+O\left(\frac1n\right)-\frac11-\frac12-\frac13-\dots-\frac1n\\
&\to-\gamma\tag{2}
\end{align}
$$
A discussion of why $\frac{\mathrm{d}}{\mathrm{d}x}\log(\Gamma(x))=\log(x)+O\left(\frac1x\right)$, and a proof of the log-convexity of $\Gamma(x)$, is given in the answer cited above. It is easy to accept since $\log(\Gamma(n+1))=\log(\Gamma(n))+\log(n)$.

Another Approach
$$
\begin{align}
\int_0^\infty\log(t)\,e^{-t}\,\mathrm{d}t
&=\lim_{n\to\infty}\int_0^n\log(t)\,\left(1-\frac{t}{n}\right)^n\,\mathrm{d}t\tag{3a}\\
&=\lim_{n\to\infty}n\int_0^1(\log(t)+\log(n))\,(1-t)^n\,\mathrm{d}t\tag{3b}\\
&=\lim_{n\to\infty}\left(\frac{n}{n+1}\log(n)+n\int_0^1\log(1-t)\,t^n\,\mathrm{d}t\right)\tag{3c}\\
&=\lim_{n\to\infty}\left(\frac{n}{n+1}\log(n)-\frac{n}{n+1}H_{n+1}\right)\tag{3d}\\[6pt]
&=-\gamma\tag{3e}
\end{align}
$$
Explanation:
$\text{(3a)}$: Monotone Convergence and $e^{-t}=\lim\limits_{n\to\infty}\left(1-\frac tn\right)^n$
$\text{(3b)}$: substitute $t\mapsto nt$
$\text{(3c)}$: substitute $t\mapsto1-t$
$\text{(3d)}$: integrate by parts $\int_0^1\log(1-t)\,t^n\,\mathrm{d}t=-\frac1{n+1}\int_0^1\frac{1-t^{n+1}}{1-t}\,\mathrm{d}t$
$\text{(3e)}$: $\gamma=\lim\limits_{n\to\infty}H_n-\log(n)$
Answer: I think you can also use the following:
$\Gamma$ can also be expressed as
$$\Gamma(z) = \frac{\exp{(-\gamma z)}}{z}\prod\limits_{n=1}^\infty\frac{\exp \left({\frac z n}\right)}{1+\dfrac z n }$$
So that
$$\log \Gamma(z)=-\gamma z-\log z+\sum\limits_{n=1}^\infty\frac{z}{n}-
\sum\limits_{n=1}^\infty\log \left(1+\frac z n \right)$$
Now I'm not going to address convergence now (which you can look up in Landau's Calculus, on the chapter dedicated to the Gamma function), but differentiating gives
$$\frac{\Gamma '(z)}{\Gamma(z)}=-\gamma-\frac 1 z+\sum\limits_{n=1}^\infty \left(\frac 1 n-\frac{1}{n+z}\right) $$
$$\frac{\Gamma '(z)}{\Gamma(z)}=-\gamma-\frac 1 z+\sum\limits_{n=1}^\infty\frac{z}{n(n+z)} $$
Letting $z=1$ gives:
$$\frac{\Gamma '(1)}{\Gamma(1)}=\Gamma'(1)=-\gamma-1 +\sum\limits_{n=1}^\infty\frac{1}{n(n+1)} $$
But we know that
$$\sum\limits_{n=1}^\infty\frac{1}{n(n+1)}=1$$
so that
$$\frac{\Gamma '(1)}{\Gamma(1)}=\Gamma'(1)=-\gamma-1+1=-\gamma $$
Answer: Hint:

Differentiation under the integral sign $$\frac{\rm d}{\rm{d}x} \int f(x,t)\, dt = \int \frac{\partial}{\partial{x}} f(x,t)\, dt$$
Derivatives of exponential and logarithmic functions $$\frac{\partial}{\partial{x}} t^x = t^{x} \log t$$
You should be able to work out: $$\frac{\rm d}{\rm{d}x} \int_0^\infty  e^{-t} t^{x-1}\, dt = \int_0^\infty  e^{-t} t^{x-1}\log t\, dt$$

Proof that $Γ'(1) = -γ$?


How To Make UIPickerView components text to always fit?

Question: Let's say you have a UIPickerView and you want your text to always fit the given space its component gets (No "..." for misfitted text).
How to pull this off?
Comment: Can you provide sample code and include a list of solutions you've already tried?
Answer: Simple solution:
Implement
<code>- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
</code>
in your picker delegate like this:
<code>- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
    UILabel* tView = (UILabel*)view;
    if (!tView)
    {
        tView = [[UILabel alloc] init];

        tView.textAlignment = NSTextAlignmentCenter;

        tView.adjustsFontSizeToFitWidth = YES;
        // Setup label properties - frame, font, colors etc
    }

    tView.text = [self pickerView:pickerView titleForRow:row forComponent:component];
    //Add any logic you want here

    return tView;
}
</code>
This makes the labels to fit the text inside them perfectly.
Enjoy!


Office 365 - how to get a report of Office installs per user?

Question: I'm in need of auditing the number of Office installs each user has installed as well as the computer names where Office Pro Plus has been installed.
I had never noticed a place to run such a report in the past, but figured there might be one.  To my surprise I couldn't find anything in the admin portal.
Then I saw this blog post: Managing Office 365 ProPlus installations: activating, deactivating, and reactivating which confirms my frustrations:

Only the signed in user can see this information.  Even if you are the
  administrator for your organization's Office 365 subscription, you
  can't see this information in any of your Office 365 administrative
  views. This also means you can't deactivate a user's installation of
  Office on a specific computer.

I understand well enough how Office Pro Plus activation/expiration works on Office 365:

When a user installs Office on a computer from the Office 365 Portal,
  and if the user hasn't already installed and activated Office on five
  other computers, Office is automatically activated. Once the Office
  installation is activated, the software page in the Office 365 Portal
  is updated with the name of the computer on which Office was
  installed.
Every day or every time you launch an Office 365 ProPlus application,
  it will check whether the individual installation or account has been
  deactivated. The computer needs to be connected to the Internet at
  least once every 30 days so that this check can be made. If the
  computer isn't connected to the Internet within 30 days, Office will
  end up in reduced functionality mode. In reduced functionality mode,
  the user will only be able to open and view existing Office files, but
  will not be able to use most of the other features of the application.

However, I can't seem to find any way of reporting each user's Office installs/activations short of having them show me via their portal login.
So, I'm not hoping too much on this, but maybe one of the MS Office 365 partners/vendors out there has managed to create something to gather this information?
P.S. I'll open a ticket with O365 support as well to ask them...but this seems like something that should be documented here on ServerFault for others to reference.
Comment: This would be very useful we are trying to deploy office 365 in 30 countries and would love to see who as adopted. Is there report of users and last login time??
Answer: As of 09/11/2018, You can see it in the report section in admin center.
Use the link below,
https://portal.office.com/AdminPortal/Home#/reportsUsage/OfficeActivations
or go to
Admin Center-> Home -> Usage -> Microsoft Office activations
The chart didn't work when i tested it, but you can export detail in csv file where you will find activation details per user per type of devices (Mac, Win, iOS, Android).
Comment: reassigned answer here.  Thanks KuN.  This is a more concise report, however it doesn't give device name here. It would have been nice to have that in the detailed report.  Maybe in the future.
Comment: We have been able to create a report specific for this in our platform if still needed.
Answer: EDIT:  See Ian's answer...the portal as of 6/9/2016 allows for this now.
FYI, at the moment according to MS Support there isn't a way to create or pull such a report.  If this changes in the future I'll edit this answer...or if someone else finds that it became possible be sure and either edit my answer or post a new one.
Answer: They now offer a "Microsoft Office activations" report in the admin portal. It provides per-user data but still fails to list the names of activated hosts/devices. Device/host names with activated installs only appear in the user data area--admins can now see this. (No improvement in the "new" admin center either.)
Answer: As of 06/09/2016 the admin portal allows an admin to view the installations per user and the names of the devices. And deactivate them if required.
Comment: Yes. Where? MS UI traditionally bad.
Comment: Go to https://portal.office.com/adminportal/home#/users (or select `Users -> Active Users` from the main admin portal.)

Select a user and then scroll down to `Office activations -> View Office activations`.


Embedded Python 3 not creating .pyc files when using importlib

Question: I'm trying to embed a Python 3 interpreter in an Objective C Cocoa app on a Mac, following instructions in this answer (which extends this article) and building Python and PyObjC by hand.
I'd like to be able to run Python code as plugins.  I specifically don't want to rely on the stock Apple Python (v2.7).  I have most of it working but can't seem to reliably load the plugin scripts.  It looks like the embedded Python interpreter is unable to create the __pycache__/*.pyc files. This may be a symptom, or a cause.  If I import the plugin file manually from the Python3 REPL (via import or the imp or importlib modules) the .pyc is generated and the plugin then loads correctly.  If I don't do this manually the .pyc is not created and I receive a ValueError "Unmarshallable object".
I've tried loosening permissions on the script directory to no avail.  The cache_tag looks OK, both from the REPL and from within the bouncer script:
>>> sys.implementation.cache_tag
'cpython-35'

py_compile raises a Cocoa exception if I try and compile the plugin file manually (I'm still digging into that).
I'm using the following:

OS X 10.11.5 (El Capitan)
XCode 7.2.1
Python v3.5.2
PyObjC v3.11

I had to make a couple of necessary tweaks to the process outlined in the linked SO answer:
Compiling Python 3 required Homebrew versions of OpenSSL and zlib, and appropriate LDFLAGS and CPPFLAGS:
export CPPFLAGS="-I$(brew --prefix openssl)/include -I$(brew --prefix zlib)/include"
export LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix zlib)/lib"

I also ensure pip is installed OK when configuring Python to build:
./configure --prefix="/path/to/python/devbuild/python3.5.2" --with-ensurepip=install

There is a fork of the original article source (which uses the stock Python2) that works fine here, so I suspect I'm not too far off the mark.  Any idea what I've missed?  Do I need to sign, or otherwise give permission to, the embedded Python?  Are there complilation/configuration options I've neglected to set?
TIA
Answer: Typical.  It's always the last thing you try, isn't it?  Adding the directory containing the plugin scripts to sys.path seems to do the trick, although I'm not sure why importlib needs this (I thought the point was to allow you to circumvent the normal import mechanism).  Perhaps it's to do with the way the default importlib.machinery.SourceFileLoader is implemented?
Something like:
sys.path.append(os.path.abspath("/path/to/plugin/scripts"))

makes the "Unmarshallable object" problem go away.  The cache directory and .pyc files are created correctly.


How do I Send HTML Emails via Rules?

Question: The Rules module provides a value field for the "send mail" action. Since I also have the PHP filter module, I have the ability to add PHP code there. I want to add HTML formatting to my email. Is there a more "correct/Drupal way" of sending HTML based emails via rules other than pasting my code there?
The pet module looks like a decent candidate, but has low-ish usage numbers.
Answer: Mimemail or HTMLMail both look like they support Rules.

How do I Send HTML Emails via Rules?


How to get Sample code working? Error 1452

Question: I just started using mySQL workbench with MAMP two days ago and it's getting there. I keep getting an error about failing to update a child row and foreign constraint failure. I'm very sure the foreign constraint is needed to tie the tables together though.
<code>create schema TerryLight717;
use TerryLight717;
CREATE DATABASE UniversityDB;
Use UniversityDB; CREATE TABLE student ( sid INTEGER,
                       sname VARCHAR(25),
                       sex CHAR(1),
                       age INTEGER,
                       yeir INTEGER,
                       gpa REAL,
                       PRIMARY KEY (sid) );

CREATE TABLE dept ( dname VARCHAR(25),
                    numphds INTEGER,
                    PRIMARY KEY (dname) );

CREATE TABLE prof ( pname VARCHAR(25),
                    dname VARCHAR(25),
                    PRIMARY KEY (pname),
                    FOREIGN KEY (dname) REFERENCES dept(dname) );

CREATE TABLE course ( cno INTEGER,
                      cname VARCHAR(30),
                      dname VARCHAR(25),
                      PRIMARY KEY (cno, dname),
                      FOREIGN KEY (dname) REFERENCES dept (dname));

CREATE TABLE major ( dname VARCHAR(25),
                     sid INTEGER,
                     PRIMARY KEY (dname, sid),
                     FOREIGN KEY (dname) REFERENCES dept (dname),
                     FOREIGN KEY (sid) REFERENCES student (sid));

CREATE TABLE section ( dname VARCHAR(25),
                       cno INTEGER,
                       sectno INTEGER,
                       pname VARCHAR(25),
                       PRIMARY KEY (dname, cno, sectno),
                       FOREIGN KEY (dname) REFERENCES dept (dname),
                       FOREIGN KEY (cno, dname) REFERENCES course (cno,dname),
                       FOREIGN KEY (pname) REFERENCES prof (pname));

CREATE TABLE enroll ( sid INTEGER,
                      grade float,
                      dname VARCHAR(25),
                      cno INTEGER,
                      sectno INTEGER,
                      PRIMARY KEY (sid, dname, cno, sectno),
                      FOREIGN KEY (sid) REFERENCES student (sid),
                      FOREIGN KEY (dname) REFERENCES dept (dname),
                      FOREIGN KEY (cno, dname) REFERENCES course (cno,dname),
                      FOREIGN KEY (dname, cno, sectno) REFERENCES section (dname,cno,sectno));

INSERT INTO `student` VALUES
(1, 'Jacobs, T.', 'm', 29, 5, 3.60),
(2, 'Pierson, E.', 'm', 32, 5, 3.50),
(3, 'Zeene, Ben N.', 'm', 21, 5, 3.90),
(4, 'Sulfate, Barry M.', 'm', 19, 2, 2.80),
(5, 'Form, Clara O.', 'f', 18, 1, 3.30),
(6, 'Scott, Kim J.', 'm', 20, 1, 3.80),
(7, 'Sather, Roberto B.', 'm', 22, 4, 2.20),
(8, 'Stanley, Leotha T.', 'm', 21, 3, 3.60),
(9, 'Smith, Joyce A.', 'f', 21, 4, 2.00),
(10, 'Jones, David S.', 'm', 19, 2, 3.50),
(11, 'Paul, Mary W.', 'f', 23, 5, 3.60),
(12, 'Soong, V.', 'f', 24, 5, 3.50),
(13, 'Kellerman, S.', 'f', 21, 3, 2.90),
(14, 'Cheong, R.', 'm', 25, 4, 3.00),
(15, 'Borchart, Sandra L.', 'f', 26, 5, 3.90),
(16, 'Alsberg, David J.', 'm', 25, 5, 3.50),
(17, 'Thorton, James Q.', 'm', 28, 4, 2.70),
(18, 'Gooch', 'm', 26, 1, 1.40),
(19, 'Smith, L.', 'm', 43, 4, 0.70),
(20, 'Korpel, E.', 'f', 19, 3, 3.50),
(21, 'Surk, K.', 'm', 23, 2, 2.50),
(22, 'Emile, R.', 'm', 18, 1, 2.00),
(23, 'Bomber, C.', 'f', 22, 4, 3.20),
(24, 'Carter, Jimmy', 'm', 56, 5, 3.50),
(25, 'Kissinger, Henry', 'm', 58, 5, 3.40),
(26, 'Ford, Gerald', 'm', 60, 5, 3.50),
(27, 'Anderson, P.', 'f', 18, 1, 3.20),
(28, 'Austin, G.', 'm', 25, 5, 3.50),
(29, 'Hamilton, S.', 'm', 21, 3, 2.80),
(30, 'Baker, C.', 'f', 18, 1, 3.50),
(31, 'Andrews, R.', 'm', 19, 2, 2.80),
(32, 'Liu, Huihusan', 'm', 29, 5, 3.90),
(33, 'Chao, Tsechih', 'f', 23, 5, 3.60),
(34, 'Kasten, Norman L.', 'm', 23, 2, 2.50),
(35, 'Mathews, John W.', 'm', 29, 5, 3.60),
(36, 'Burroughs, Susan S.', 'f', 18, 1, 3.00),
(37, 'Dunbar, D.', 'm', 30, 5, 3.40),
(38, 'Auen, B.', 'm', 21, 3, 2.70),
(39, 'Shoemaker, A.', 'f', 22, 4, 3.50),
(40, 'Rosemeyer, S.', 'f', 21, 3, 2.90),
(41, 'Fisher, C.', 'f', 22, 4, 3.50),
(42, 'Trude, T.', 'm', 19, 2, 2.90),
(43, 'Ksar, J.', 'm', 20, 3, 3.40),
(44, 'Moeri, S.', 'f', 20, 4, 3.20),
(45, 'June, Granson', 'f', 18, 1, 3.10),
(46, 'Micheal, Zadicki T.', 'm', 22, 2, 2.70),
(47, 'Roger, Blotter N.', 'm', 21, 3, 1.90),
(48, 'Natividad, A.', 'f', 25, 5, 4.00),
(49, 'Villa-lobos, M.', 'm', 47, 5, 3.70),
(50, 'Moomchi, B.', 'm', 32, 5, 3.50),
(51, 'Jetplane, Leaving O.', 'm', 30, 1, 0.00),
(52, 'Fy, Clara I.', 'f', 18, 2, 2.00),
(53, 'Atny, Mary H.', 'f', 26, 5, 3.80),
(54, 'Maximillian', 'm', 98, 5, 3.00),
(55, 'Glitch, R.', 'm', 19, 1, 2.80),
(56, 'Starry, J.', 'f', 22, 4, 3.30),
(57, 'Hiemerschmitz, A.', 'f', 19, 1, 2.70),
(58, 'Marshmallton', 'm', 20, 3, 3.00),
(59, 'Ziebart, F.', 'm', 22, 4, 1.80),
(60, 'Calcmity, J.', 'f', 23, 3, 2.60),
(61, 'Kennedy, Ed', 'm', 55, 3, 2.30),
(62, 'Moses, A.', 'm', 18, 1, 3.20),
(63, 'Kool, Joseph F.', 'm', 35, 5, 3.70),
(64, 'Fred, Edwin B.', 'm', 80, 5, 4.00),
(65, 'Ripper, Jack T.', 'm', 18, 1, 0.50),
(66, 'Altenhaus, Stuart', 'm', 21, 4, 2.80),
(67, 'Altenhaus, Gloria', 'f', 22, 5, 4.00),
(68, 'Crist, J.', 'm', 23, 4, 3.00),
(69, 'Heilskov, G.', 'm', 23, 4, 2.50),
(70, 'Caucutt, B.', 'm', 24, 5, 3.00),
(71, 'Mark, B.', 'm', 24, 4, 3.60),
(72, 'Barnes, J.', 'm', 45, 5, 2.30),
(73, 'Quarnty, G.', 'f', 20, 2, 4.00),
(74, 'Andrus, J.', 'f', 21, 3, 3.70),
(75, 'Jones, A.', 'f', 23, 5, 3.20),
(76, 'Zorhoff, C.', 'm', 20, 3, 3.00),
(77, 'Paull, Thomas H.', 'm', 23, 4, 2.60),
(78, 'Cool, J.', 'm', 18, 2, 2.60),
(79, 'Evert, Chris', 'f', 21, 4, 3.90),
(80, 'Connors, Jimmy', 'm', 25, 1, 0.20),
(81, 'Smith, Ike Z.', 'm', 33, 1, 1.10),
(82, 'News, Nightly', 'm', 15, 1, 1.90),
(83, 'Jones, Ivan L.', 'm', 55, 5, 3.50),
(84, 'Smith, R.', 'm', 19, 3, 2.70),
(85, 'Mayer, N.', 'f', 21, 5, 3.50),
(86, 'Gonring, J.', 'm', 21, 4, 3.70),
(87, 'Mueller, D.', 'm', 20, 3, 3.30),
(88, 'Bates, M.', 'm', 22, 4, 3.30),
(89, 'Longlastname, A.', 'f', 99, 5, 4.00),
(90, 'Zappa, F.', 'm', 16, 4, 4.00),
(91, 'Ghandi, I.', 'f', 78, 1, 3.50),
(92, 'Kirk, J.', 'm', 34, 5, 2.20),
(93, 'Andermanthenol, K.', 'm', 26, 5, 3.70),
(94, 'Uoiea, Z.', 'f', 19, 2, 3.30),
(95, 'Grzlbltz, Q.', 'm', 43, 5, 2.50),
(96, 'Birch, M.', 'f', 23, 5, 3.50),
(97, 'Morgan, D.', 'm', 18, 1, 3.50),
(98, 'Taylor, R.', 'm', 20, 3, 2.80),
(99, 'Jones, J.', 'f', 21, 1, 1.10),
(100, 'Gringo, C.', 'm', 25, 5, 2.90),
(101, 'Davis, Scott P.', 'm', 19, 3, 3.70),
(102, 'Bates, Michael L.', 'm', 22, 4, 3.40),
(103, 'Kaisler, Janet M.', 'f', 21, 4, 3.50),
(104, 'Baskett, Wayse T.', 'm', 23, 3, 2.10);

INSERT INTO dept VALUES
('Chemical Engineering',32),
('Civil Engineering',   88),
('Computer Sciences',   47),
('Industrial Engineering',  41),
('Mathematics', 129),
('Sanitary Engineering' ,3);

Insert into Prof Values
("Brian, C.",   "Computer Sciences"),
("Brown, S.",   "Civil Engineering"),
("Bucket, T.",  "Sanitary Engineering"),
("Clark, E.",   "Civil Engineering"),
("Edison, L.",  "Chemical Engineering"),
("Jones, J.",   "Computer Sciences"),
("Randolph, B.", "Civil Engineering"),
("Robinson, T.", "Mathematics"),
("Smith, S.",   "Industrial Engineering"),
("Walter, A.",  "Industrial Engineering");

INSERT INTO course (cno, cname, dname) VALUES (302, "Intro to Programming","Computer Sciences");
INSERT INTO course (cno, cname, dname) VALUES (310, "Thermodynamics",   "Chemical Engineering");
INSERT INTO course (cno, cname, dname) VALUES (310, "Intro to Garbage", "Sanitary Engineering");
INSERT INTO course (cno, cname, dname) VALUES (365, "City Planning",    "Civil Engineering");
INSERT INTO course (cno, cname, dname) VALUES (375, "Highway Engineering",  "Civil Engineering");
INSERT INTO course (cno, cname, dname) VALUES (461, "College Geometry 1",   "Mathematics");
INSERT INTO course (cno, cname, dname) VALUES (462, "College Geometry 2",   "Mathematics");
INSERT INTO course (cno, cname, dname) VALUES (467, "Intro to Data Structures", "Computer Sciences");
INSERT INTO course (cno, cname, dname) VALUES (514, "Manpower Utilization", "Industrial Engineering");
INSERT INTO course (cno, cname, dname) VALUES (561, "Advanced City Planning",   "Civil Engineering");
INSERT INTO course (cno, cname, dname) VALUES (561, "Advanced Garbage Collection5", "Sanitary Engineering");
INSERT INTO course (cno, cname, dname) VALUES (701, "Compiler Construction",    "Computer Sciences");
INSERT INTO course (cno, cname, dname) VALUES (726, "Nonlinear Programming",    "Computer Sciences");

INSERT INTO section (dname, cno, sectno, pname) VALUES("Chemical Engineering",  310,    1,  "Edison, L.");

INSERT INTO section (dname, cno, sectno, pname) VALUES("Civil Engineering", 365,    1,  "Randolph, B.");
INSERT INTO section (dname, cno, sectno, pname) VALUES("Civil Engineering", 375,    1,  "Brown, S.");
INSERT INTO section (dname, cno, sectno, pname) VALUES("Civil Engineering", 561,    1,  "Randolph, B.");

INSERT INTO section (dname, cno, sectno, pname) VALUES("Computer Sciences", 302,    1,  "Jones, J.");
INSERT INTO section (dname, cno, sectno, pname) VALUES("Computer Sciences", 302,    2,  "Smith, S.");
INSERT INTO section (dname, cno, sectno, pname) VALUES("Computer Sciences", 467,    1,  "Jones, J.");
INSERT INTO section (dname, cno, sectno, pname) VALUES("Computer Sciences", 701,    1,  "Clark, E.");
INSERT INTO section (dname, cno, sectno, pname) VALUES("Computer Sciences", 726,    1,  "Brian, C.");

INSERT INTO section (dname, cno, sectno, pname) VALUES("Industrial Engineering",    514,    1,  "Walter, A.");

INSERT INTO section (dname, cno, sectno, pname) VALUES("Mathematics",   461,    1,  "Robinson, T.");
INSERT INTO section (dname, cno, sectno, pname) VALUES("Mathematics",   462,    1,  "Robinson, T.");

INSERT INTO section (dname, cno, sectno, pname) VALUES("Sanitary Engineering",  561,    1,  "Bucket, T.");

INSERT INTO major (dname, sid) VALUES("Mathematics", 0);

INSERT INTO major (dname, sid) VALUES("Mathematics", 1);
INSERT INTO major (dname, sid) VALUES("Computer Sciences",  1);
INSERT INTO enroll VALUES(1,    3.00,   "Chemical Engineering", 310,    1);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  2);
INSERT INTO major (dname, sid) VALUES("Mathematics",    2);
INSERT INTO enroll VALUES(2 ,3.00,  "Computer Sciences",    302,    1);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  3);
INSERT INTO major (dname, sid) VALUES("Mathematics",    3);
INSERT INTO enroll VALUES(3,    3.50,   "Civil Engineering",    375,    1);

INSERT INTO major (dname, sid) VALUES("Sanitary Engineering",   4);
INSERT INTO major (dname, sid) VALUES("Computer Sciences",  4);
INSERT INTO enroll VALUES(4,    4.00,   "Mathematics",  461,    1);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  5);
INSERT INTO enroll VALUES(5,    3.00,   "Industrial Engineering",   514,    1);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  6);
INSERT INTO enroll VALUES(6,    3.50,   "Computer Sciences",    302,    2);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  7);
INSERT INTO enroll VALUES(7,    4.00,   "Computer Sciences",    302,    1);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  8);
INSERT INTO enroll VALUES(8,    4.00,   "Computer Sciences",    302,    1);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  9);
INSERT INTO enroll VALUES(9,    3.00,   "Civil Engineering",    375,    1);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  10);
INSERT INTO major (dname, sid) VALUES("Computer Sciences",  10);
INSERT INTO enroll VALUES(10,   2.00,   "Computer Sciences",    302,    1);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  11);
INSERT INTO enroll VALUES(11,   3.00,   "Computer Sciences",    302,    2);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  12);
INSERT INTO enroll VALUES(12,   2.50,   "Computer Sciences",    302,    2);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  13);
INSERT INTO enroll VALUES(13,   2.50,   "Computer Sciences",    302,    2);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  14);
INSERT INTO enroll VALUES(14,   2.50,   "Mathematics",  462,    1);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  15);
INSERT INTO enroll VALUES(15,   3.00,   "Chemical Engineering", 310,    1);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  16);
INSERT INTO enroll VALUES(16,   3.00,   "Computer Sciences",    467,    1);
INSERT INTO enroll VALUES(16,   3.00,   "Computer Sciences",    701,    1);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  17);
INSERT INTO enroll VALUES(17,   3.00,   "Mathematics",  461,    1);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  18);
INSERT INTO enroll VALUES(18,   2.00,   "Civil Engineering",    375,    1);
INSERT INTO enroll VALUES(18,   3.50,   "Mathematics",  461,    1);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  19);
INSERT INTO enroll VALUES(19,   3.50,   "Mathematics",  461,    1);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  20);
INSERT INTO enroll VALUES(20,   2.50,   "Computer Sciences",    302,    1);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  21);
INSERT INTO enroll VALUES(21,   3.00,   "Computer Sciences",    467,    1);
INSERT INTO enroll VALUES(21,   3.50,   "Industrial Engineering",   514,    1);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  22);
INSERT INTO enroll VALUES(22,   3.00,   "Computer Sciences",    302,    1);
INSERT INTO enroll VALUES(22,   3.00,   "Computer Sciences",    467,    1);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  23);
INSERT INTO enroll VALUES(23,   4.00,   "Civil Engineering",    561,    1);

INSERT INTO major (dname, sid) VALUES("Computer Sciences",  24);
INSERT INTO enroll VALUES(24,   4.00,   "Computer Sciences",    302,    2);

INSERT INTO major (dname, sid) VALUES("Chemical Engineering",   25);
INSERT INTO enroll VALUES(25,   3.50,   "Computer Sciences",    302,    1);

INSERT INTO major (dname, sid) VALUES("Chemical Engineering",   26);
INSERT INTO enroll VALUES(26,   3.50,   "Mathematics",  462,    1);

INSERT INTO major (dname, sid) VALUES("Chemical Engineering",   27);
INSERT INTO enroll VALUES(27,   2.50,   "Industrial Engineering",   514,    1);

INSERT INTO major (dname, sid) VALUES("Chemical Engineering",   28);
INSERT INTO enroll VALUES(28,   3.00,   "Mathematics",  461,    1);

INSERT INTO major (dname, sid) VALUES("Chemical Engineering",   29);
INSERT INTO enroll VALUES(29,   3.00,   "Civil Engineering",    365,    1);
INSERT INTO enroll VALUES(29,   3.00,   "Civil Engineering",    375,    1);
INSERT INTO enroll VALUES(29,   3.00,   "Civil Engineering",    561,    1);

INSERT INTO major (dname, sid) VALUES("Chemical Engineering",   30);
INSERT INTO enroll VALUES(30,   4.00,   "Computer Sciences",    467,    1);

INSERT INTO major (dname, sid) VALUES("Chemical Engineering",   31);

INSERT INTO enroll VALUES(31,   3.50,   "Computer Sciences",    302,    1);

INSERT INTO major (dname, sid) VALUES("Chemical Engineering",   32);
INSERT INTO enroll VALUES(32,   2.00,   "Civil Engineering",    561,    1);

INSERT INTO major (dname, sid) VALUES("Chemical Engineering",   33);
INSERT INTO enroll VALUES(33,   2.00,   "Civil Engineering",    365,    1);
INSERT INTO enroll VALUES(33,   3.00,   "Computer Sciences",    726,    1);

INSERT INTO major (dname, sid) VALUES("Chemical Engineering",   34);
INSERT INTO enroll VALUES(34,   1.00,   "Civil Engineering",    561,    1);

INSERT INTO major (dname, sid) VALUES("Chemical Engineering",   35);
INSERT INTO enroll VALUES(35,   3.00,   "Mathematics",  461,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  36);
INSERT INTO enroll VALUES(36,   3.00,   "Civil Engineering",    375,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  37);
INSERT INTO enroll VALUES(37,   3.00,   "Mathematics",  462,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  38);
INSERT INTO enroll VALUES(38,   3.00,   "Computer Sciences",    302,    2);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  39);
INSERT INTO enroll VALUES(39,   3.00,   "Computer Sciences",    302,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  40);
INSERT INTO enroll VALUES(40,   3.50,   "Mathematics",  462,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  41);
INSERT INTO enroll VALUES(41,   3.00,   "Computer Sciences",    701,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  42);
INSERT INTO enroll VALUES(42,   3.50,   "Computer Sciences",    701,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  43);
INSERT INTO enroll VALUES(43,   2.50,   "Computer Sciences",    467,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  44);
INSERT INTO enroll VALUES(44,   4.00,   "Computer Sciences",    726,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  45);
INSERT INTO enroll VALUES(45,   3.00,   "Chemical Engineering", 310,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  46);
INSERT INTO enroll VALUES(46,   4.00,   "Computer Sciences",    726,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  47);
INSERT INTO enroll VALUES(47,   1.00,   "Civil Engineering",    365,    1);
INSERT INTO enroll VALUES(47,   0.00,   "Civil Engineering",    561,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  48);

INSERT INTO enroll VALUES(48,   1.50,   "Civil Engineering",    561,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  49);
INSERT INTO enroll VALUES(49,   3.50,   "Chemical Engineering", 310,    1);
INSERT INTO enroll VALUES(49,   3.50,   "Industrial Engineering",   514,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  50);
INSERT INTO enroll VALUES(50,   4.00,   "Industrial Engineering",   514,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  51);
INSERT INTO enroll VALUES(51,   3.00,   "Computer Sciences",    726,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  52);
INSERT INTO enroll VALUES(52,   1.00,   "Computer Sciences",    302,    1);
INSERT INTO enroll VALUES(52,   4.00,   "Computer Sciences",    467,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  53);
INSERT INTO enroll VALUES(53,   4.00,   "Mathematics",  462,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  54);
INSERT INTO enroll VALUES(54,   3.00,   "Civil Engineering",    375,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  55);
INSERT INTO enroll VALUES(55,   2.50,   "Mathematics",  461,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  56);
INSERT INTO enroll VALUES(56,   2.50,   "Chemical Engineering", 310,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  57);
INSERT INTO enroll VALUES(57,   3.50,   "Computer Sciences",    467,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  58);
INSERT INTO enroll VALUES(58,   2.00,   "Industrial Engineering",   514,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  59);
INSERT INTO enroll VALUES(59,   3.50,   "Mathematics",  462,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  60);
INSERT INTO enroll VALUES(60,   2.50,   "Civil Engineering",    561,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  61);
INSERT INTO enroll VALUES(61,   3.50,   "Civil Engineering",    561,    1);
INSERT INTO enroll VALUES(61,   2.00,   "Computer Sciences",    726,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  62);
INSERT INTO enroll VALUES(62,   2.50,   "Computer Sciences",    726,    1);

INSERT INTO major (dname, sid) VALUES("Civil Engineering",  63);
INSERT INTO enroll VALUES(63,   2.50,   "Computer Sciences",    701,    1);

INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 64);
INSERT INTO enroll VALUES(64,   4.00,   "Civil Engineering",    561,    1);
INSERT INTO enroll VALUES(64,   3.50,   "Computer Sciences",    726,    1);

INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 65);

INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 66);
INSERT INTO enroll VALUES(66,   1.50,   "Civil Engineering",    365,    1);
INSERT INTO enroll VALUES(66,   4.00,   "Civil Engineering",    375,    1);

INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 67);
INSERT INTO enroll VALUES(67,   3.50,   "Computer Sciences",    467,    1);
INSERT INTO enroll VALUES(67,   4.00,   "Computer Sciences",    701,    1);

INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 68);
INSERT INTO enroll VALUES(68,   3.50,   "Computer Sciences",    726,    1);

INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 69);
INSERT INTO enroll VALUES(69,   3.50,   "Computer Sciences",    302,    2);
INSERT INTO enroll VALUES(69,   2.00,   "Computer Sciences",    467,    1);

INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 70);
INSERT INTO enroll VALUES(70,   3.50,   "Civil Engineering",    561,    1);

INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 71);
INSERT INTO enroll VALUES(71,   2.50,   "Computer Sciences",    701,    1);

INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 72);
INSERT INTO enroll VALUES(72,   3.50,   "Computer Sciences",    726,    1);

INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 73);
INSERT INTO enroll VALUES(73,   3.00,   "Civil Engineering",    375,    1);

INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 74);
INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 75);
INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 76);
INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 77);
INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 78);
INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 79);
INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 80);
INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 81);
INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 82);
INSERT INTO major (dname, sid) VALUES("Industrial Engineering", 83);
INSERT INTO major (dname, sid) VALUES("Mathematics",    84);
INSERT INTO major (dname, sid) VALUES("Mathematics",    85);
INSERT INTO major (dname, sid) VALUES("Mathematics",    86);
INSERT INTO major (dname, sid) VALUES("Mathematics",    87);
INSERT INTO major (dname, sid) VALUES("Mathematics",    88);
INSERT INTO major (dname, sid) VALUES("Mathematics",    89);
INSERT INTO major (dname, sid) VALUES("Mathematics",    90);
INSERT INTO major (dname, sid) VALUES("Mathematics",    91);
INSERT INTO major (dname, sid) VALUES("Mathematics",    92);
INSERT INTO major (dname, sid) VALUES("Mathematics",    93);
INSERT INTO major (dname, sid) VALUES("Mathematics",    94);
INSERT INTO major (dname, sid) VALUES("Mathematics",    95);

INSERT INTO major (dname, sid) VALUES("Mathematics",    96);
INSERT INTO enroll VALUES(96,   4.00,   "Civil Engineering",    365,    1);
INSERT INTO enroll VALUES(96,   3.00,   "Civil Engineering",    561,    1);

INSERT INTO major (dname, sid) VALUES("Mathematics",    97);
INSERT INTO enroll VALUES(97,   3.00,   "Industrial Engineering",   514,    1);

INSERT INTO major (dname, sid) VALUES("Mathematics",    98);
INSERT INTO enroll VALUES(98,   4.00,   "Industrial Engineering",   514,    1);

INSERT INTO major (dname, sid) VALUES("Mathematics",    99);
INSERT INTO enroll VALUES(99,   3.50,   "Computer Sciences",    701,    1);

INSERT INTO enroll VALUES(100,  2.00,   "Computer Sciences",    726,    1);
INSERT INTO enroll VALUES(101,  4.00,   "Mathematics",  462, 1);
INSERT INTO enroll VALUES(102,  3.50,   "Mathematics",  461,    1);
INSERT INTO enroll VALUES(103,  4.00,   "Computer Sciences",    701,    1);
INSERT INTO enroll VALUES(104,  2.80,   "Computer Sciences",    302,    2);
INSERT INTO enroll VALUES(104,  2.60,   "Sanitary Engineering", 561,    1);
</code>
Comment: Pls specify exactly where you get this error. Actually, isolating the issue would even help you to find the cause yourself!
Comment: It's with the part that says INSERT INTO section VALUES. It fails to execute.
Comment: Even if section was all by itself, it still says the same thing. The datatypes are correct. The foreign keys make sense. But why doesn't it make sense?
Comment: Do all of your `INSERT INTO section` fail, or only certain ones?
Comment: Yes. All of the"INSERT INTO section"  fail no matter which is first.
Answer: I think I see the problem. Your values for <code>prof.pname</code> all have a leading space, while your values for <code>section.pname</code> don't.
For what it's worth, I was taught not to use <code>varchar</code> for key fields, nor to use names or any other data that might change due to act of bureaucracy (such as a name) for key values. Following that rule tends to reduce headaches substantially.
Comment: You were right. the space in the name made a big difference. But the error 1452 is still showing up, now for the INSERT INTO major. There's no more extra space characters. Weird.
Comment: Your first `INSERT INTO major` specifies `major.sid = 0`. There's no corresponding `student` record. Do the other `INSERTs INTO major` work?
Comment: No they don't. Is there a debugger you are using to see it's 0?
Comment: Actually, when I pressed the continuing despite error, the other majors and enrolls were included. But the first one didn't work. Still 1452. How do you tell major.sid=0?
Comment: Like I said, I just eyeballed the script you posted. It looks as though the foreign key constraints are doing their job of preventing you inserting inconsistent data.
Comment: Oh I see. It was the student sid = 0. I thought it was weird that the students started at 1. This has been helpful.
Comment: It's really the sort of instinct one develops through experience. Just keep working at it.


What is the correct format for hibernate parameter names

Question: I am using Hibernate Entity manager 5.1.8 Final
I have the following filter definitions annotating a class called Submission.
@FilterDefs({
    @FilterDef(name=Submission.BY_DATE_RANGE_FILTER,
            parameters={ @ParamDef( name=Submission.WITH_START_PARAM, type="java.util.Date" ),
                         @ParamDef( name=Submission.WITH_END_PARAM,   type="java.util.Date" )
    }),
    @FilterDef(name=Submission.BY_INSTID_SET_FILTER,
               parameters=@ParamDef( name=Submission.BY_INSTID_SET_PARAM, type="java.lang.String" ) ),
    })

@Filters({
    @Filter(name=Submission.BY_DATE_RANGE_FILTER, condition="added <= :lastDay and added > :firstDay"),
    @Filter(name=Submission.BY_INSTID_SET_FILTER, condition="instid in :byinstidsetparam"),
})

and the following static final definitions within the class
public static final String WITH_START_PARAM = "firstDay";
public static final String WITH_END_PARAM = "lastDay";
public static final String BY_INSTID_SET_PARAM = "byinstidsetparam";

When I attempt to activate either, or both, of these filters, Hibernate throws an Exception
java.lang.IllegalArgumentException: Invalid filter-parameter name format
    at org.hibernate.engine.spi.LoadQueryInfluencers.parseFilterParameterName(LoadQueryInfluencers.java:144)
   at org.hibernate.hql.internal.ast.util.JoinProcessor.processDynamicFilterParameters(JoinProcessor.java:232)
   at org.hibernate.hql.internal.ast.util.SyntheticAndFactory.addWhereFragment(SyntheticAndFactory.java:98)
... more ...

Googling for the source gave me this:
http://grepcode.com/file/repo1.maven.org/maven2/org.hibernate/hibernate-core/5.0.0.CR3/org/hibernate/engine/spi/LoadQueryInfluencers.java#LoadQueryInfluencers.parseFilterParameterName%28java.lang.String%29
which, sure enough, throws this exception if the parameter name does not contain a '.'.
Here's the mystery though.

If I rename my parameters to contain a '.' I get the very same exception thrown at the very same place.
No example that I can find on the net of the filter param feature (including the official Hibernate docs) has a '.' in the parameter name.

Its possible that this source code is a red herring.
Does anyone have any idea what is going on?  Any and all suggestions appreciated.
Answer: Probably you determine ' : '  in query without any parameter.
Comment: If `':'` is intentional, you can replace it with `CHR(58)`.
Answer: I wasn't looking in the relevant place.  Here's the definition of the filter name (not parameter) constants referenced above
public static final String BY_STUDENTID_FILTER = "with-studentid";
public static final String BY_DATE_RANGE_FILTER = "within-daterange";
public static final String BY_INSTID_SET_FILTER = "with-instructorset";

Removing the '-' from these names solved the problem.
Summary, Filter names cannot contain hyphens.  If they do, Hibernate will complain that the filter parameter definition has the wrong format.


Every prime ideal of a finitely generated $\mathbb{R}$-algebra is an intersection of maximal ideals?

Question:
Why must every prime ideal of a finitely generated $\mathbb{R}$-algebra (e.g. $\mathbb{R}[X_1,X_2]$) be the intersection of the maximal ideals containing it?

This doesn't follow from the version of the Nullstellensatz I've seen:

if $k$ is an algebraically closed field and $S$ is a finitely generated $k$-algebra and $P$ is a prime ideal of $S$, then $P$ is the intersection of all maximal ideals containing $P$

... since $\mathbb{R}$ isn't algebraically closed! But maybe the same method of proof could work?
Many thanks in advance for any help with this!
Comment: A finitely generated algebra over a Jacobson ring (e.g., a field) is a Jacobson ring, see the first theorem [here](https://www.math.uwaterloo.ca/~jpbell/nullstellensatz.pdf).
Answer: Let $k$ be a field and $\bar{k}$ its algebraic closure. An algebraic zero of a subset $\Phi$ of $k[x_1,\dots,x_n]$ is an element $(a_1,\dots,a_n) \in \bar{k}^n$ such that $f(a_1,\dots,a_n)=0, \, \forall f \in \Phi$. Then Hilbert's Nullstellensatz says that if $g \in k[x_1,\dots,x_n]$ vanishes at every algebraic zero of $\Phi$, then $g$ is inside the radical of the ideal generated by $\Phi$ (Matsumura, Theorem 5.4).
The next key thing to observe is that given an ideal $I$ of $k[x_1,\dots,x_n]$, there is a $1-1$ correspondence between algebraic zeros of $I$ and maximal ideals of $k[x_1,\dots,x_n]$ that contain $I$. To see that, note that if $m$ is a maximal ideal that contains $I$ and we define $a_i$ to be the class of $x_i$ mod $m$, then $(a_1,\dots,a_n)$ is an algebraic zero of $I$ by the Zariski Lemma. Conversely, if $(a_1,\dots,a_n)$ is an algebraic zero, then $k[a_1,\dots,a_n] = k(a_1,\dots,a_n)$ and the kernel of the $k$-algebra homomorphism $k[x_1,\dots,x_n] \rightarrow k[a_1,\dots,a_n]$ that sends $x_i$ to $a_i$ is a maximal ideal (Matsumura, Theorem 5.1).
Finally, we clearly have that $I \subset \cap_{m \supset I} m$. Conversely, let $f \in \cap_{m \supset I} m$. Then $f$ vanishes at every algebraic zero of $I$ and by Hilbert's Nullstellensatz $f \in \sqrt{I}$.