Relation between number of conjugated double bonds and absorbance?

Question: I observed the absorbance on Phenolphthalein in acidic and basic medium, and I know that the absorbances differ due to the number of conjugated double bonds, but I am not sure exactly why this happens. I believe it has something to do with the delocalised electrons, which causes lower energy differences, but I am unable to establish a solid link between the concepts. Why does this happen?
Answer: When 2 p orbitals mix, a pi and a pi* orbital is formed, and the electrons occupy the lower energy pi orbital.  The UV-absorbance is the energy difference between these two orbitals such that on electron may be 'promoted' to the p* orbital.
When 3 p orbitals mix, three pi-type orbitals are formed.  One is obviously bonding and one is obviously antibonding.  There is a third one 'in the middle', frequently called non-bonding.  Because of this third orbital, there is a smaller difference between any two states, and as such absorbing a photon to promote an electron requires less energy, redshifting the absorbance.
Add a fourth p orbital and the energy differences get smaller, but with two bonding orbitals and two anti-bonding orbitals.  Add a 5th p orbital and now you have two bonding orbitals and two anti-bonding orbitals and a non-bonding orbital, with even smaller differences.  Repeat ad nauseum.
Smaller energy differences means longer wavelengths.
Check out this picture for a graphical summary:


Buber's "It-world": original German?

Question: Does anyone know how what Kaufman renders as "It-world" (in "I and Thou") appears in the original German?
Comment: It seems to me that "the world of *It*" is the transaltion of the German : "der Es-Welt".
Answer: Probably Buber says "dingliche Welt (it-world)". The German term dinglich is the adjective to the noun Ding (thing).
But to be sure you must quote the precise passage from your English edition.
Comment: Searching briefly I got die dingliche Welt, dem "Es"  but I don't have either the German or the English with me at this point to confirm.

Buber's "It-world": original German?


Order By clause on an aggregated SQL request

Question: let's say my table schema is like bellow (it's only a simplified example):
MyTable (table name)
ID - int (unique, auto increment)
Message - string
Timestamp - Datetime

I want to select the number of ID, group them by message and order them by timestamp, so I'll do something like this:
SELECT count (ID), Message FROM MyTable
GROUP BY (Message)
ORDER BY Timestamp desc

However, SQL Server management studio throws me this error:
Column 'Timestamp ' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

The problem is that if I put Timestamp in the Group By statement with Message, it messes up my grouping. The other suggestion to put Timestamp in an aggregate function doesn't make sense (ordering by say, count(Timestamp) doesn't mean anything...)
Any idea on how to do this?
Thanks a lot!
Answer: Looking for something like this?
SELECT Message, count (ID), max(Timestamp) as maxDate FROM MyTable
GROUP BY (Message)
ORDER BY maxDate desc

Answer: When you do aggregation, you are GROUPing rows together based on certain criteria.  This mean that each row of your result set actually represents multiple rows in the raw data.
When you want to ORDER BY Timestamp, there will be MULTIPLE timestamp values for each row in the result set, since each one of those rows represents several rows of data.
So, you need to decide which timestamp you want for each set.  The MAX?  The MIN?  You will need to aggregate that field as well to get accurate or meaningful results.
Answer: If you want to order the messages based on the max timestamp within the Group then try:
SELECT count (ID), Message
  FROM MyTable
 GROUP BY (Message)
 ORDER BY MAX(Timestamp) DESC

Answer: Let's say the same message is in your table multiple times:
       1|the mackerel likes frying|1/1/1917
       2|at night all cats are grey|12/15/1956
       3|the mackerel likes frying|2/2/1918

And you want to group by the message-string, counting the number of times the message appears in the table:
      the mackerel likes frying|2
      at night all cats are grey|1

The timestamp column is NOT part of the aggregation aka the grouping, but is part of the detail row.  It CANNOT appear in the grouping, because timestamp is not "it" (singular) but timestamps, they, plural.  There are two different timestamps in the example above for the mackerel message.  Which one would you choose? How would the query know which one it was?  All you have at your disposal are the aggregate functions:
        min(timestamp)
        max(timestamp)
        count(timestamp)

and if it were other than a datetime, you'd also have AVG(timestamp).
Comment: To confirm if I understand your example well:
if I group your rows by max(timestamp) desc, will the results be:
2|at night all cats are grey|12/15/1956, 3|the mackerel likes frying|2/2/1918, 1|the mackerel likes frying|1/1/1917 ?
Comment: @Tigel - no, because rows 1 and 3 would be grouped together.
Comment: Yes of course, my bad. I get it now, thanks for your answers gentlemen! @JNK @Cybernate @ingo @Devin Garner
Answer: The problem here is that you probably have multiple messages that are the same, but with different timestamps, because you're grouping by message. If you have two messages 'hello' with different timestamps, which should it use for the order by?
This is one way. You could also do a trick with cross apply or row_number.
SELECT count(ID), Message FROM MyTable
GROUP BY (Message)
ORDER BY Max(Timestamp) desc


What does "Data Massage" mean?

Question: I am doing some reading, and came across avoiding an internalStore if my application does not need to massage the data before being sent to SQL.  What is a data massage?
Comment: This post seems to be off-topic, and the tags are entirely irrelevant. Please reconsider or revise.
Answer: Manipulate, process, alter, recalculate.  In short, if you are just moving the data in raw then no need to use internalStore, but if you're doing anything to it prior to storage, then you might want an internalStore.
Comment: No, one should never implicitly trust program input of any sort.  Simple checks, however, might not be considered massaging as you aren't touching the data - merely peeking at it.
Comment: That is true. My experience with massaging has almost always been to clean up the data already in a data store that was entered from another system that I have no control over.
Answer: Sometimes the whole process of moving data is referred to as "ETL" meaning "Extract, Transform, Load". Massaging the data is the "transform" step, but it implies ad-hoc fixes that you have to do to smooth out problems that you have encountered (like a massage does to your muscles) rather than transformations between well-known formats.
Thinks that you might do to "massage" data include:

Change formats from what the source system emits to what the target system expects, e.g. change date format from d/m/y to m/d/y.
replace missing values with defaults, e.g. Supply "0" when a quantity is not given.
Filter out records that not needed in the target system.
Check validity of records, and ignore or report on rows that would cause an error if you tried to insert them.
Normalise data to remove variations that should be the same, e.g. replace upper case with lower case, replace "01" with "1".
Answer: Clean up, normalization, filtering, ... Just changing the data somehow from the original input into a form that is better suited to your use.
Answer: And finally there is the less savory practice of massaging the data by throwing out data (or adjusting the numbers) when they don't give you the answer you want. Unfortunately people doing statistical analysis often massage the data to get rid of those pesky outliers which disprove their theory. Because of this practice referring to data cleaning as massaging the data is inappropriate. Cleaning the data to make it something that can go into your system (getting rid of meaningless dates like 02/30/2009 because someone else stored them in varchar instead of as dates, separating first and last names into separate fields, fixing all uppercase data, adding default values for fields that require data when the supplied data isn't given, etc.) is one thing  - massaging the data implies a practice of adjusting the data inappropriately.
Also to comment on the idea that it is bad to have an internal store if you are not changing any data, I strongly disagree with this (and I have have loaded thousands of files from hundreds of sources through the years. In the first place, there is virtually no data that doesn't need to at least be examined for for cleaning. And if it was ok in the first run doesn't guarantee that a year later it won't be putting garbage into your system. Loading any file without first putting it into a staging table and cleaning it is simply irresponsible.
Also we find it easier to research issues with data if we can see easily the contents of the file we loaded in a staging table. Then we can pinpoint exactly which file/source gave us the data in question and that resolves many  issues where the customer thinks we loading bad information that they actually sent us to load. In fact we always use two staging tables, one for the raw data as it came in from the file and one for the data after cleaning but before loading to the production tables. As a result I can resolve issues in seconds or minutes that would take hours if I had to go back and search through the original files.  Because one thing you can guarantee is that if you are importing data, there will be times when the content of that data will be questioned.

What does "Data Massage" mean?


Crash when I start Blender 2.83 on Windows 7 Pro

Question: I've just installed Blender 64Bits v2.83 (Os W7 Pro-64b) and when I try to launch it, I have a stealth window (kind for DOS command) which opens and closes immediately, and the program doesn't not open :-(!
Can you help me to solve this problem?
thank you in advance,
Best Regards,
G.
Answer: Something similar happened to me with  on a Win 8.1 laptop, but I was also getting an error message related to a sound setting. Strangely, I made it work by upgrading my graphics card driver to the latest version, so you can try that. If not, try to see if Win 7 is still supported. Hope this helps! Stay safe.


Recover an ext4 due to the super block flag

Question: My ubuntu 21 hanged and after rebooting, it was not able to boot up. The current message is this one.

Tried to use fsck with -y and -f and none of them fixes the partition.
It happened with the raspberry pi 4 100.
Comment: *Tried to use fsck with -y and -f* - how did you do this on a system that doesn't even boot?
Answer: In general, this is an indication of a dying sd card.
What happens is, that fsck tries to recover the journal, tries to write the superblock, but then finds that the superblock is not updated.
If you have important work on this Pi, you should dd the partition to a hard drive and try some forensics on it. The partition table seems OK, so there seems no need to dd the whole card.
It may be, that the card will boot after being let alone for a few hours, but even if that is the case, you should replace the card.
You may also have some luck with e2fsck -fccky, which means:
   -f    Force checking even if the file system seems clean.

   -c    This option causes e2fsck to use badblocks(8) program to do
         a read-only scan of the device in order to find any bad blocks.
         If any bad blocks are found, they are added to the bad block
         inode to prevent them from being allocated to a file or direc‐
         tory.  If this option is specified twice, then the bad block scan
         will be done using a non-destructive read-write test.

   -k    When combined with the -c option, any existing bad blocks in the
         bad blocks list are preserved, and any new bad blocks found by
         running badblocks(8) will be added to the existing bad blocks
         list.

   -y    Assume an answer of `yes' to all questions; allows e2fsck to be
         used non-interactively. This option may not be specified at the
         same time as the -n or -p options.

But I would buy a new sd card.
Comment: I would not use `-c` on an SD card -- it can take a long time, and it's ineffective because SD card addresses are virtual and dynamic, meaning "block 1234" will not always refer to the same physical block; unlike old spinning disks, the physical layout is completely opaque to the OS even if various tools don't recognize this.  Fsck can still fix errors in place though.  Also note: If the card is new (hence should not be "dying"), they can be defective such that they die young.
Comment: @goldilocks If you do a non-destructive read-write test, and if there is sufficient spare on the sd-card, the sd card *might* re-allocate the bad blocks (no guarantee!). The `-cc` works for the sd-card, sometimes.  I agree that it will take a long time. I also agree that a single `-c` is useless.
Comment: Lemme try this again:  *The operating system does not have access to actual physical block addresses on the SD card*.  But `badblocks` requires such in order to work to re-allocate or blacklist addresses. The SD card controller (an MC in the card) maps physical addresses to virtual ones, again **dynamically**, meaning they are subject to change *and the OS has no insight into this*.
Comment: Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackexchange.com/rooms/128025/discussion-on-answer-by-ljm-dullaart-recover-an-ext4-due-to-the-super-block-flag).


How to config user_prefs (SpamAssassin) individually per user in Redis DB?

Question: I'm going to implement mail gateway with FreeBSD 10.1.
So, I installed Postfix, Amavisd, Clamav, Spamassassin, Procmail (for filtering spam from maildir to spam folder), Bayes with Redis database. I have config them to work together. It can work well as root user.
My point is how to config user_prefs individually per user, so that Spamassassin can learn based on different users. (e.g. different whitelist). And also storing those user preferences in Redis database.
p.s. So far, I haven't  found a tutorial on Redis other than official documentation (which doesn't help so much). And I'm not clear on sa-learn per user very well. I really appreciate good tutorial of explanation in this.
Thank you in advance.
Answer: I have worked around so many things and I finally found that RedisDB isn't quite suitable like this. Even though RedisDB is fast, this scenario is best fit with relational database.
There are a few of alternative ways. So I go with traditional MySQL.
I found great tutorial for FreeBSD here http://www.purplehat.org/?page_id=4 . This link is very helpful in introducing my to Maia Mailguard. Despite the fact that I need to use Amavisd-new, I followed the explicit steps in that link. It can be applied to Amavisd-new well because Maia Mailguard was once a part of Amavisd package. Its configuration goes in similar way.
By the way, thank you for interesting and upvoting this question.


Featured image upload finished hook

Question: I'm looking for a way to hook into the process of uploading a featured image. Ideally I would want to be able to do some stuff right when the upload has finished, before the thumbnails are generated.
What I wanna do is when the image is finished uploading, the user will be presented with the possibility to resize and crop their image before it's actually set as the featured image.
Is this possible, or should I rather be thinking of a custom uploader that I use to later set the finished image as the featured image?
Answer: There is a deault feature available on WP to crop image once you upload. You can edit the image you upload and can crop image with
you preferences.
How to crop rotate scale and flip images in wordpress
WordPress by default is designed to generate 3 types of cropping of any uploaded images (Media) automatically to ensure site speed with different sizes where necessary. So, with uploading the Original image there would be at least 4 files-
<code>The Original File (not-cropped),
 => the_post_thumbnail('full');            // Original image resolution (unmodified)
Large,
 => the_post_thumbnail('large');           // Large resolution (default 640px x 640px max)
Medium, and
 => the_post_thumbnail('medium');          // Medium resolution (default 300px x 300px max)
Thumbnail.
 => the_post_thumbnail('thumbnail');       // Thumbnail (default 150px x 150px max)

Custom size
the_post_thumbnail( array(100,100) );  // Other resolutions
</code>
You can add other custom size with your preference as:
 => add_image_size() //will automatically create the versions of the images suitable for positioning in your website theme.
Using add_image_size() function with your desired parameter allows you to add new size for your site. Use the function into your functions.php to add your desired image size:
Hope that helps!!

Featured image upload finished hook


UK/US dual citizenship a bar to holding a stock and shares ISA

Question: I am married to my wife who has dual UK and US citizenship.  She has been told that because of her affiliations to the US (her US citizenship) she must close her stocks and shares ISA as the UK bank who is her broker is closing all accounts of people with any US connection.  I have sole UK citizenship.  Is there any tax reason why my wife could not gift me her capital and I pay it into my stocks and shares ISA and manage her investments for her. This obviously requires a great degree of trust, but apart from that is there any tax reason why I could/should not do this. I have spoken to my broker (same bank, same broker) who say they would not have a problem with that because as far as they are concerned the money would be coming from me.  I obviously don't want to get into any legal hot water with either the US or UK tax authorities!
Answer: There is a warning flag I see on reading this - "I could... manage her investments for her". This implies that the mutual understanding between you two would be that she bears the 'beneficial interest' in the account, which is ultimately the same impact in terms of US reporting requirements that it seems your broker is trying to protect itself against. In general, a spouse making a gift to another individual may be allowed depending on the amount, but this wouldn't be a gift if she ultimately remains the beneficial holder.
As a side note, I will add that it is not clear from your answer whether your wife is currently meeting all reporting / filing requirements for US liabilities as a US citizen. You may want to research that issue further if you feel there is any risk she is not fully compliant.
Answer: I can't speak to the US tax liability, but holding someone else's investments in your ISA is a form of tax evasion - sheltering someone else's assets under your personal ISA allowance.
Of course if these are jointly owned assets, rather than transfering your wife's assets into your name, as your broker said there will be no UK problems.


How to customise Shoreditch?

Question: When I do a contact search with the default layout my screen shows 13 contacts - I then have to scroll to see the rest.  When using Shoreditch, I can see only 4 contacts before scrolling because so much of the screen is taken up with title,  header and other areas that are generous in size & perhaps not optimally located.  This is on a newish laptop with a 15.4" HD screen (1920px x 1080), which must be a pretty common device.  This is using Firefox, full screen.  With Chrome, full screen, only 2 contacts are visible before you have to scroll!  My guess is that the developers of Shoreditch have 26" screens on which the layout probably looks great!!   But it really doesn't suit a smaller screen and for that reason I wouldn't change my clients to Shoreditch.  Is there a way it can be customised to fix this problem ? - apart from tinkering with the CSS, that is. With Coleman's wonderful summary screen layout extension depending on Shoreditch, Civi may be unwittingly going down a route of excluding itself from smaller screens, like my laptop - and my client's laptops. That would be a bad mistake.
By the way, in case you're thinking, 'make the font smaller' when I do this to the point where I can still just read the screen, I now can see only 7 contacts!
Comment: Note that the Contact Summary Editor no longer requires Shoreditch. But it does still work well with it.
Answer: Your question appears to be:

When using Shoreditch, I can see only 4 contacts before scrolling. Is there a way it can be customised - apart from tinkering with the CSS, that is?

Shoreditch does nothing but modify the look of CiviCRM via CSS. So, if you're unhappy with the out-of-the-box layout, CSS is what you'll have to use to modify it.
FWIW, my opinion is that http://thereisnopagefold.com/ but I agree that Shoreditch still needs to implement some responsive design for smaller screens. I'm guessing that one of the issues holding this back is that core templates need to be modified to achieve this.
Comment: IMO, different layout options seems like a different issue to the need for responsive design. Good to hear there's some thinking around this issue however.
Comment: I don't have CSS skills & neither will a lot of Civi clients so that's not always a workable solution.  But I had an email from one of the Shoreditch developers who said they were thinking about a project to have a 'compact', 'regular' etc layouts (similar to gmail). A 'make it happen' would be opened to fund it, so I'm keeping an eye out for that, as that sounds like a good direction.

How to customise Shoreditch?


What era and/or genre do these classical pieces recorded by violinist André Rieu belong to?

Question: What era do these pieces belong to? Links are to orchestral recordings by André Rieu.
The Second Waltz
Bolero
Amazing Grace
They are neither classic nor baroque, but are they romance ?
Comment: This is the link for Amazing Grace, (http://www.last.fm/music/Andr%C3%A9+Rieu/_/Amazing+Grace) I couldn't update my question because they said I'm a new fish and I can't post more than two links.
Comment: Have you tried googling the names and composers to see when they were written? Also, the question would be better if you include the pieces' full names and composers in the question so people can understand it without going through links.
Comment: @Karen yes I did a google search, but the thing is not if you are a composer in 1855 then you are a romance one, it is about type(kind) of music, not a specific year where in the next day, bom no romance anymore
Comment: Musical **period** is mostly objective but musical **style or genre** is very subjective, so it is not always possible to answer these kinds of questions. For example, regarding the second piece: "[Maurice Ravel] is often **associated with impressionism** along with his elder contemporary Claude Debussy, although **both composers rejected the term**." [Source](https://en.wikipedia.org/wiki/Maurice_Ravel) So what style is *Bolero* written in? Who can say? And in the end, does it even matter?
Answer: The "Second Waltz" is an arrangement of "Waltz No. 2" (from the Jazz-Suite), composed by Dmitri Shostakovich (1906-1975). It is a very non-typical piece (light in tone) of him. He was a 20th century composer but this piece may be considered a pastiche on the works of Johan Strauss Jr. (1825-1899) (not to be confused with Johann Strauss (1804-1849)!) who mostly composed light classical dance music (as opposed to more serious music meant to listen to). The genre/era of these kind of waltzes is romantic.
Comment: dev1001, thank you for this clarification and identification of the track. I was not able to find any liner notes from the André Rieu albums reproduced online which listed the names of composers for any of the tracks. I have edited my own answer to reflect your correction.
Answer: The André Rieu recording entitled "Second Waltz" that you have linked to is from an album called Forever Vienna. It is a waltz, composed by Russian composer Dmitri Shostakovich (1906-1975). It may be considered a pastiche on the works of the famous Austrian composer Johan Strauss II (1825-1899), so you could consider this a more recent piece meant to sound like something from the Romantic style period. However, as with the other pieces you are asking about, André Rieu has created his own contemporary orchestral arrangements in his own style.
"Amazing Grace" is a sacred Christian hymn which is sung by the congregation in church. It was written in 1779 by John Newton, who was English. It has become tremendously popular all over the world ever since the that time. There have been so many different arrangements and recordings in so many different musical styles that it would be impossible to list them.
A bolero, generally speaking, is a particular type of dance, and dance music. It first appeared in the late 1700s in Spain, and was also popular in Cuba. In 1928, French composer Maurice Ravel (1875-1937) wrote a long, slow orchestral piece called Bolero to accompany a ballet. The original version is about 15 minutes long. This would be considered to be in the style period referred to by some as "Post-Romantic" or "Modern" or simply "early 20th-century". On the link you have provided, André Rieu performs a much shorter arrangement of Ravel's original.


Restrict SSH access to whitelist IP - what is stopping someone pretending to be from my IP?

Question: I know I can whitelist a client IP for connecting to SSH on server and then Deny All other IPs. However, seeing as how the packet arriving at the server network interface must include the IP, what is stopping someone just pretending to be the whitelisted IP?
Answer: To be clear: the packets that return from your server will go to the IP address that the packets claim to be from, and not to where they actually came from.
IP traffic flows are not "pipes". :)
If the imposter sends a packet which says "My source address is x.x.x.x", your server will send its reply to x.x.x.x, and not to the imposter. So even if they controlled one router along the path, that wouldn't be enough to ensure the return packets arrive.
Comment: ...but there could be a theoretical chance that, by controlling one router on one of the many paths they could see the reply? And if they got physically close enough to the server they would likely increase their chance as the number of routers connecting to the server decreases. So then just try and connect over and over until they get lucky and catch the handshake? I can't see how this is not possible?
Comment: There's no luck involved, and no "catching the handshake". Each router along the path either knows a route to the remote IP (x.x.x.x) or it doesn't (and uses its default route). I don't know what you mean by getting "physically close enough to the server". If there is one router between them and the target and they control that router, great, they win. If there are two, they need to control both. If there are ten... you get the picture. If you don't see how this is possible, I recommend you read up a bit on IP fundamentals.
Answer: The fact that they won't receive the reply and thus can't complete the three-way handshake.
Comment: how can one be sure that they won't receive the reply? Is there not a chance that they could control a router which is on the return path the response/reply would take?
Comment: @user3231690 Only if they're the NSA. And if the NSA wants you, you've got more serious problems than this...
Comment: Why would it need to be the NSA? Surely all it needs to be is someone who has access to one of the closer routers to the Server?
Comment: See my comment below, but you're missing a fundamental notion of routing. *Each* router along the path will try to route the packet to the *real* destination, and not to the attacker. In the "bad old days" of the Internet, things like source routing were possible (the source could specify the return path) but that's practically impossible these days.


Prove that $z|z|$ is not holomorphic at any point

Question: I'm trying to prove that the complex-valued function $f(z)=z|z|$ is not holomorphic at any point. I know $f_2(z)=|z|$ fails to be holomorphic at any point of $\mathbb C$. Then, the basic fact about product of holomorphic functions is not a good avenue. I mean, since $f_1(z)=z$ is holomorphic at $\mathbb C$, if $f_2$ was not holomorphic at only one point $a$, then this point could give us the answer, by a direct test. But it is not the case. So, I guess I have to find a point where $f$ is not holomorphic. But I could not get it. For example, using Cauchy-Riemann equations, I found out that $f$ is differentiable at $z=(0;0)$. I wonder if I'm ignoring some good result for it... I'm sorry if it is a trivial question, but I'd be glad if someone could give me a hint, please. Thanks in advance!
Answer: Consider the holomorphicity of $\frac{f}{f_1}$. That solves your problem everywhere except $z = 0$.
Answer: Use the Cauchy-Riemann criteria. Let $ f(z)=f(x+iy) $. Now let
$u(x,y)=Re(f(x+iy))$ and $v(x,y)=Im(f(x+iy))$.
Now check if the partial derivatives satisfy $u_x=v_y$ and $u_y=-v_x$. If this holds, and the partials are continuous, then the original function $f(z)$ is holomorphic everywhere except where the Cauchy-Riemann criteria is not satisfied. Note the condition holds nowhere so the function is not holomorphic at any point.
Answer: Another way is to check complex differentiability : $f$ is $\mathbb C$-differentiable at $0$, because
$$\frac{h|h|-0}{h}=|h| \xrightarrow[h\to0]{}0$$
but if $z\ne0$,
$$\frac{f(z+h)-f(z)}{h} = |z+h|+z\frac{|z+h|-|z|}{h}$$
First term has limit $|z|$, OK. For second term, it can be shown that it doesn't have limit. For example, if $h=\alpha z$, with $\alpha\in\mathbb R$ sufficiently small,
$$\frac{|z+h|-|z|}{h} = \frac{|z|}{z}$$
but for $h=z(e^{i\theta}-1)$, with $\theta\in\mathbb R$ tending to $0$,
$$\frac{|z+h|-|z|}{h} = 0$$
which gives us two very different limits.


Can I add an outside switch to exterior floodlights?

Question: I have an exterior floodlight that is switched from inside the house. I want to be able to switch it on at its outside location, as well. I don't want a motion detector light. I hope I can avoid additional wiring work. The floodlight is well protected from weather, mounted under an overhang on the outside of the house. Location is southwest USA.
Comment: You'll have to change to 3-way switches, which will likely require you to install an additional conductor. Not likely you'll be able to do this without pulling cable.
Comment: You can use 2 switches in series without pulling cable -- in operation you just leave the inside switch on all the time.
Answer: You can get a remotely controlled wall switch. This comes in 2 parts.  One is a switch that replaces your current indoor switch.  The other is a remote control unit that wirelessly controls the switch.  This approach does not require any additional wiring indoors or out.  Just google "remote controlled wall switch" to see the various options available.
Comment: there are several options for this. X10 is the old standard I do this for a Tenant that has shared space access. Luton and Leviton also make Remote switches that are battery operated. they are surface mount and you stick them anywhere.
Comment: Yep this was my thought as well -- but *do not use X10*, it is really, really awful. Use Insteon or something Z-wave-based (Lutron and Leviton are increasingly using Z-wave), if you're going to go that route. Nice thing with these types of systems is you can later add motion detectors (multiples, if you want), as well as controllers that can do simple time-based schedules or complex actions based on time/motion/switches.


Example of reduction such that it is not many-one reduction while it is not turing reduction

Question: I am reviewing things I learned, and I can't suddenly come up with an example of reduction that is not many-one, but Turing reduction. Can anyone present such an example?
Comment: Your title asks for a reduction that is not many-one and *not* Turing, but the question asks for something that is not many-one and *is* Turing. Which do you want?
Answer: A simple example would be a reduction from e.g. $SAT$ to it's complement $\overline{SAT}$, which works as follows: given a formula $\varphi$, you can decide whether $\varphi$ is satisfiable by deciding whether $\varphi\in \overline{SAT}$, and then negating the answer. This is a Turing reduction, since you use an oracle for $\overline{SAT}$ to solve $SAT$.
A similar example can be constructed for HALT and it's complement, if you want decidability, rather than complexity.


Do you have to get access to the developer's code in order to work on creating selenium tests?

Question: I am able to create selenium tests to test a web app or website without having access to the developers' code. Is this the correct way to do selenium testing?
Do you have to get access to the developer's code in order to create selenium tests? If so, how does that work and why?
Comment: no in selenium automation only front end required HTML, CSS
Answer: No. You do not need to access developers' codes in order to work on selenium tests.
All you need is to access HTML codes to create selenium tests.
Answer: That is not required. As selenium can interact with web application from browser without needing any code or development team's permissions.
So in short, You don't need code access.
In some cases, you may need access of database, for example- email verification, if you need to pick some id from database to access a page etc.


Plotting bode plot of the transfer function

Question:
two poles p1=1 and p2=25
two zeros are z1=100 and z2=origin
and the DC gain is 20log10(10)=20dB
I know that that the Dc gain Is 20dB which is a straight line with slope of 0 ,
The zeroes have 20dB slope, but I don't know how to find amplitude of poles ( vertical positions) and and at what vertical position does the graph start ?
Comment: It is very easy plotting bode plot on Matlab. In my humble opinion, it can help you, maybe.
Comment: I cannot use MATLAB in this course.
Answer: First, cancel out the pole and zero:
\$H(s) = 250s/(s+25)\$
Next, determine the pole location:
\$H(s) = 10s/(1+s/25)\$
The break frequency is 25 rad/s.
Since there is a zero at origin, the slope until 25 rad/s is +20 dB and the slope after 25 rad/s is 0 dB.
We can start the graph at 1/10th of the lowest break frequency: 2.5 rad/s but that's quite an odd number.  Let's select 1 rad/s instead.
The gain at 1 rad/s is:
\$H(1) = 10*1/(1)\ = 10 = 20 \textbf{dB}\$
This does not directly tell us the gain at and beyond the 25 rad/s break frequency.  We know that the gain difference between the gains at the break frequency and at 1/10th of the break frequency is 20 dB.
Thus, let's determine the gain at 2.5 rad/s:
\$H(2.5) = 10*2.5/(1)\ = 25 = 28 \textbf{dB}\$
Gain at 1/10th of the break frequency is 28 dB.  One can draw vertical line from 20 dB at 1 rad/s through 28 dB at 2.5 rad/s to 48 dB at 25 rad/s.  At 25 rad/s, the gain slope becomes zero and hence one can draw a horizontal line at 48 dB to ~1,000 rad/s.
Also, notice that the DC gain is 0, which is a number that cannot be represented on a logarithmic scale.
\$H(0) = 10*0/(1)\ = 0\$
MatLab:
Comment: can you share the MATLAB command ?
Comment: s = tf('s'); H = 250*s*(s+100)/(s+100)/(s+25); bode(H)


Is it yet possible to blueprint Concrete?

Question: I'd like to know if it is somehow possible to include Concrete in a blueprint. When I select an area with my blueprint, the ground is ignored. Do i need to hold a special key, or is it just not possible (yet)?
Answer: You need to ghost the concrete. Then they will be included.
When you make a blueprint for you can select "include tiles" and exclude everything else. That will make a blueprint for only the concrete tiles.
Comment: @Roman hold shift while placing, Then you will place a ghost image for construction bots to finish laying down. It's handy for extending your inventory while expanding your base.
Comment: What do you mean by "ghost the concrete" ?  Thanks
Comment: Note to Googlers, make sure you also tick **Include tiles** in the blueprint screen if you have selected tiles **and** any other sort of item in the blue print. e.g. walls, gun turrets.
Answer: Yes, you need to concrete some empty piece of land (with no buildings on it) and then blueprint it.
Next use it as a regular blueprint (even under already built factories et al)
Comment: Ah, thanks. That should help. So there is no way to **include** it?
Comment: @O.Vollbrecht No, there is not. Frustratingly, it *used* to be included in blueprints, but an update (not sure which one) changed that.
Answer: In 0.13 You can have blueprint containing both terrain and machines, you can just select whether you want to include only terrain, machines or both by the checkboxes.


How old is Ned Flanders' Grandmother?

Question: Grandma Flanders must be pretty old (and possibly dead?) but considering Ned's own advanced age (possibly) she must be very old indeed. I can't find any direct evidence for anyone's age, except for Ned saying he's 60 and having living parents.
Comment: The characters on The Simpson's do not age. Take for example Bart and Lisa who are known to be 10 and 8 years old respectively and have been for the entire run of the series. Therefore, if Ned is 60, he has always been and will always be 60 and his parents are more than likely in their 80s. My own parents are in their 60's and my grandparents are in their 80s.
Comment: I'm too lazy to do the maths but the Simpsons is on right now -- a 'back in the day' episode in which Bart and Lisa are around but younger, Ned's grandmother dies. The same day she says she's 100. There are issues to work out with that what with the timeline and such but I hope its a springboard for someone who does have the effort and resources at hand to turn it into a fully worked out answer :P edit: same episode states Bart is 4 and Lisa is 2. Enough there that it wouldn't be too hard -- In that case I'll do up a real answer when I get home unless someone beats me to it hehe
Comment: I assume the title is wrong and you're asking about Ned's **mother**?
Comment: https://simpsons.fandom.com/wiki/Grandma_Flanders
Answer: Apparently 100
As seen in the clip below, she states she has just turned 100.

NED: Now, sir, don't you waffle on that brunch. Grandma Flanders can watch the kids.
GRANDMA FLANDERS: Hello, Joe.
HOMER: Doesn't know who I am... has trouble moving... I'd say we have ourselves babysitter.
GRANDMA FLANDERS: I just turned a hundred.

Although she uses the wrong name, Ned doesn't correct this or the age she gives. It's possible that the age is wrong but, unless the character appears again with a definitive birth and/or death date, we may not know for certain.

How old is Ned Flanders' Grandmother?


OS X Snow Leopard: Finder automator item for creating a new text file

Question: how can I create a Finder automaton item that appears in 'Services' for creating a new text file inside a file folder? I use TextMate, so better if the solution is editor-agnostic (rather than using TextEdit).
Comment: Such a useful operation in Windows, and in MacOS it's completely missing
Comment: Not an automator service, but a new button in the toolbar - see ling's answer here: https://apple.stackexchange.com/questions/84309/how-to-create-a-text-file-in-a-folder
Answer: This is not an automator action, but resolved the problem of creating a new file where i wanted: http://ignorethecode.net/blog/2009/05/31/creating-new-documents/. Look at the solution called "An Even Better Solution" (bottom of the page).
Answer: This should work:
do shell script "echo '[text for the text file]' > [path to folder & file].txt"

If you just want an empty text file, try this:
do shell script " > [path to folder and file].txt"

Edit: I read your question again... this is an AppleScript. I have more experience with plain Terminal than with Automator and AppleScript, but I assume you can call an AppleScript from Automator?
Comment: I would rather have this actions to open TextMate (or TextEdit, or any other text editor) with an empty file. Also, I would like the step as to how to add this in Automator so it shows in the Finder menu included in the answer.
Answer: Okay, I cheated but you still get an Automator service. You will need to have TextMate setup to use the shell (it usually does this when you first install it, so you can use mate from the CLI).
Open Automator and create a new Service
From Utilities drag over a Run Shell Script window.
Drop in the following script:
cd ~/Desktop;
touch newfile.txt;
mate newfile.txt

What this basically does is create a file on your desktop named newfile.txt and then open in TextMate.

Requested update:

Open Automater and create a new service
Drag over a 'Run Applescript' window
Paste in the following Applescript that was authored by Olivier Fabré:
on run {input, parameters}

    tell application "Finder"
        set currentPath to insertion location as text
        set filePath to POSIX path of currentPath & input
    end tell

    tell application "TextMate"
        activate
        open filePath
    end tell

    return input
end run

Save the service

What this does:
If you select text in an application it will open a blank TextMate file with the name of the selected text, in the frontmost Finder window.
What you are probably trying to do:
Other people have written tutorials on creating a TextMate button that sits in the Finder toolbar that will open blank document in that window, or open a selected file in TextMate. Which is what it sounds like what you want to do and doesn't require Automator.
Comment: This is helpful, but I have several concerns here.

a) Touch is not necessary, as mate creates a file if it is not found.
b) How can I parametrize the name of the filename?

Another issue is that,  I want this automator task to work automatically to the folder finder it is showing, not the selected folder.
Comment: then you may want to spend some time here http://snippets.dzone.com/posts/show/1037
Comment: Nice link, although a little convoluted.

Provide a simpler step-by-step process for creating the service I need (service asks for a text file name, creates it in the current finder folder -not the selected folder-, and opens it in TextMate) and you get the correct-answer reputation. ;-)
Comment: Your update is very explanatory, thank you. It's a shame I can't mark two answers as correct. :-(
Comment: Thank you for a nice explanation. However, I wanted the name of the filename to be asked rather than to have to select a text on Finder. It's a shame two different answers can be marked as correct. Thanks for your efforts though!
Answer: The way I do it:
I create a dummy text file, and store it in some folder in my documents (this is used as a template for each time the service runs). I then create a workflow (service) as follows:

All you have to do now, is right click the folder you want the new file to be placed in, and select the service created by saving this workflow.
To open the newly created file, you can add an "open Finder items" action in which you would obviously select TextMate rather then TextEdit. To make it editor agnostic, you can tell it to open with its default application, and it will do so.
If asking for the name at runtime is very important to you, you can add a get text action, and assign it to a second variable, then add a rename action after the copy action and say replace text, replacing the name of your template file with the text variable. By default, you can't use text variables in the way I described, but the following post provides a work around of doing so. I know it works under 10.6, and may or may not work under earlier version of OSX.
see here for instructions
Comment: segfault, it seems that the image link of your answer is no longer working. Could you have a look at that? Cheers.
Comment: That sounds like the right answer to me.
Comment: Nice and informative answer!

I would need one last clarification: is there a way for creating an Automator action that affects the folder you are currently viewing in Finder (rather than the folder you select via right clicking on it)?
Comment: Not that I know of. That's the only downside. I've been trying to com up with some sort of alternative so I don't need to go up a directory. However, I use the column view, so it's not such a huge deal for me. I'll let you know if I think of something. Keep me posted. I use this same method for creating new C++ classes in certain directories as well. Works like a charm.
Answer: try
    tell application "Finder"
        set ans to text returned of (display dialog "" default answer "")

        set opn to 0
        set fn to "new.txt"
        if ans is "," then
            set opn to 1
        else if ans is "/" then
            set opn to 2
        else if character -1 of ans is "," then
            set fn to text 1 thru -2 of ans
            set opn to 1
        else if character -1 of ans is "/" then
            set fn to text 1 thru -2 of ans
            set opn to 2
        end if

        if character -1 of fn is "." then
            set fn to fn & "txt"
        end if

        try
            set p to target of window 1
        on error
            set p to desktop as alias
        end try
        set f to make new file at p with properties {name:fn}
        set selection to f
        if opn is 1 then
            open f
        else if opn is 2 then
            open f using (path to application "TextMate")
        end if
    end tell
end try
I'm using this via FastScripts, but it should also work as an Automator service. And yes, this script is ugly even by AppleScript standards.
Answer: A modification of finiteloop's answer that's a little cleaner.

Create a new service in Automator
Change 'Service receives selected" to "folders"
Give it the "Set Value of Variable" action, change "Storage 1" to a variable called "dest"
Add the "New Text File" action, and drag the variable "dest" from the Variable pane at the bottom of the screen onto the "Where" field. This is simpler than copying a template file.
Save with a reasonable name.

Now when you click on a  folder, you can go to the Services menu at the bottom and find your function.
The function will also appear in the Services settings page; Settings -> Keyboard -> Shortcuts --> Services (left hand side). You can enable and disable it here. You can also assign it a keyboard shortcut. Finally, if you deselect enough items from the Folder submenu (so that there are four or fewer), your function will appear at the bottom of the Context Menu.


VirtualBox error when trying to run Ubuntu "Failed to open a session"

Question: Im trying to run Ubuntu in a virtual machine on virtual box. So far I have reinstalled virtualbox once to see if it was the cause, then I redownloaded the .iso, but when I try to run the machine it says it still won't run.
Failed to open a session for the virtual machine ubuntu.
The virtual machine 'ubuntu' has terminated unexpectedly during startup with exit code 1.
Result Code: E_FAIL (0x80004005)
Component: Machine
Interface: IMachine {480cf695-2d8d-4256-9c7c-cce4184fa048}
Comment: I had this problem tonight and I fixed it. I've been searching Stackoverflow for people who may have similar problems. Check out my answer about the [vboxdrv](https://stackoverflow.com/a/27718480/1116861) and see if that helps.
Answer: If you didn't power off the vm after last run, try right-click on VirtualBox Manager >> Discard Saved State. This will start the vm from (virtual) power off state. Current state of vm will be lost.
Answer: Are you using VirtualBox 4.3.14? There's a known bug which could be related: https://www.virtualbox.org/ticket/13187
I was having this problem, downgrading "solved" it.
Answer: Here's what I did and it worked properly:
(1) Move/copy your hard disk image (my_old_vm.vdi) to a
    convenient folder, e.g. C:\my\VMS\my_new_vm\
(2) Create a new virtual machine (click the new button).
(2.b) At some point in time you are asked about the disk
      to be used; choose 'existing disk image' and browse
      to where you moved my_old_vm.vdi and select that.
(3) Start the VM and reconfigure the machine settings.
(4) Possibly delete the old machine. If you did not move the
    .vdi file, then do not delete all files related to the
    old machine.
This saved my day.
Answer: For me "Detachable Start" works, can you try it out?
Answer: I just went through exactly the same problem on a Windows VM. Uninstalling the Norton Internet Security and restarting my computer solved the problem. Credit to this article that I found here: https://forums.virtualbox.org/viewtopic.php?f=6&t=62615


Having a lot of trouble deploying a java applet

Question: I'm new to Java. I'm simply trying to build a .jar file of my applet so I can run it from my browser. This is what my directory structure looks like:
C:\java\pacman\src

contains all of the .java class files.
C:\java\pacman\assets

contains about 4-5 images and audio files.
If I try to use the following code:
Image someFile=getCodeBase().toString() + "file.png";

The result of getCodeBase() is
file:/C:/java/pacman/bin/

However the following code fails to load:
   img=new ImgHelper(getCodeBase().toString() + "assets/");
   ImageIO.read(new File(img.getPath("pacman.png")));

Moving my 'assets' folder to the 'bin' folder didn't fix this either. It tries loading:
file:/C:/java/pacman/bin/assets/pacman.png

saying:
Can't read input file!

But the url it gave opens fine if I paste it into run and hit enter:
So to avoid myself a lot of headache i commented out the code in my ImgHelper class and did this:
public ImgHelper(String dir)
{
    //this.imgDir=dir;
    imgDir="C:\\java\\pacman\\assets\\";
}

Which works perfectly. But I want to put this on a web server, and I have no idea how/what I should do to make all the images and sounds work. Any ideas?
Thanks...
Comment: So did you get the game working?
Answer: Why not put it all in a JAR file and then call Class.getResourceAsStream?
A JAR file is better as it is a single HTTP connection rather than one HTTP connection per file.  It is also much more flexible to use a Stream than a File.
getResourceAsStream will work when the files are not in a JAR as well, they need to be relative to the class file.
EDIT:
Another thing, the File method won't work if the applet is on a server as it will be trying to open the file from the local machine (I think, I haven't tried it) rather then from the server.  Even if it tried to create a file path to the server that won't work.
Answer: I agree with tofubeer about the JAR, but if you want to put the image on your server, see the tutorial on Applet images here.  The codebase will be whatever location your applet is on the server, and you can put images relative to that on the server as well.  Use a media tracker along with the Applet.getImage() method to retrive the url.  From the example:
 my_gif = getImage(getDocumentBase(),"imageExample.gif");

Answer: There are two possible solutions that would work:

The images could be present outside the applet JAR. The applet could then be initialized with the location of the directory where the images are present. Once you have that information you could then load images from the server. The Sun Java tutorial provides an example usage of the applet parameter to pass the image source directory.
The applet class loader could be utilized to load the images from the applet's JAR, using the getResourceAsStream() method.

PS: It would be helpful if you referred to the section in the Java tutorials to load icons for your application. The same section discusses a lot of the points brought forth by TofuBeer and John.
EDIT : The usage of the File API is not recommended because it ends up reading off the local file system. That is unacceptable for most users on the internet.


Sugar Minting Multiple?

Question: I have deployed my collection using Sugar.  I am able to use sugar mint, to mint one. In the old CM2 CLI you could do mint multiple # Is this no longer possible using the new interface ?
Comment: please elaborate the question with a description of how you used to be able to do this with the old interface, what you've tried with the new one and why you think the feature is not available
Answer: sugar mint has the following flag:
    -n, --number <NUMBER>
            Amount of NFTs to be minted in bulk

So you can still mint multiple:
sugar mint --candy-machine ... --number 10

Btw, just run commands with --help to see the available options.

Sugar Minting Multiple?


viewing the contents of a file as decimal numbers format using vi

Question: I am saving audio input in a file called sound.raw by using alsa api. I think that the sound amplitudes are being saved (it is a guess, i am not sure). The format i use is signed 16 bit number little endian (S16_LE). Now if the amplitudes are being saved, how do i see the amplitudes in decimal number format because as of now i only see a collection of @s and ^s and various other symbols which aren't making sense when i open the sound.raw file with vi.
Answer: What you are seeing is the binary representation of the sound data as interpreted by vi (probably as ASCII). However, it is not meant to be human-readable, or a lot of storage would be wasted.
See Using vi as a hex editor for a way to show the data in hexadecimal format, which is the closest you're going to get to an answer to your question without (writing your own) specific software for displaying ALSA-formatted sound data in a human-readable fashion.


Is learning LISP useful at all these days?

Question: I picked up a LISP book at a garage sale the other day and was just wondering if it was worth spending some time on.
Comment: The best thing I ever did was stumble across LISP.  It opened my eyes in a 'riding a bike' kind of way and it's influence is there in everything I've programmed since.  Happy reading!
Comment: A lot of related answers are here: http://programmers.stackexchange.com/q/55284/15028
Answer: Yes. I'll stick to Common Lisp, here, though Scheme is also a superb language that has a lot to recommend it.
In Common Lisp, you have a largish multi-paradigm language that provides some things that either don't exist widely outside the Lisp family of languages, or are limited to CL and even more obscure/niche languages.
The first feature, which you can get in one way or another from CL, Scheme and quite a few other dialects, is a real macro system.
I say "real" because the system is much more complete, flexible and reliable than, say, C preprocessor macros. It's extremely difficult to get CPP macros to do even simple things (like swapping the values of two variables, or making a foreach construct) in a reliable fashion, but these are trivial with Lisp macros. This turns out to be a very powerful tool for introducing new abstractions and dispensing with "boilerplate" code.
The second feature, which is effectively limited to Common Lisp, is CLOS, the Common Lisp Object System. Despite the name, it's not a conventional OO system like that of Java with methods being part of a class's definition. Instead, it provides polymorphism through "generic functions" which are what methods are attached to, and by default allow you to do multiple dispatch.
I vastly prefer CLOS to the more usual approach to object orientation, as it makes a number of "patterns" (like the Visitor pattern) completely unneccessary and because extension of existing generic functions is so easy; others loathe it because it takes an extremely cavalier approach to encapsulation and because extension of generic functions becomes arguably too easy. Either way, CLOS is different enough that I think it's worth learning just for the different perspective it provides.
The third feature, which is available outside of Lisp but still fantastic if you've never experienced it before is dynamic, interactive programming. CL debuggers tend to be extremely powerful tools, and CL provides for dynamic definition and redefinition of functions, classes and methods, all of which dramatically improves one's ability to explore a problem, test solutions of that problem and its subproblems, and finally put together a program that works correctly and efficiently.
Lastly, for a lot of classes of problems, Lisp is a great practical language. It provides good performance (usually not as fast as C, but dramatically faster than most "scripting languages"), safety, automatic memory management, a decent "standard library" of functions and tremendous opportnities for easy extension.
Comment: grettke: no, "Lisp" is the shorthand.
Comment: It's the interactive nature of programming Lisp which I enjoy most.  I take advantage of this every day.
Comment: I've been reading the SICP book on-line, I believed that Scheme was just an implementation of LISP
Comment: Technically Common Lisp and Scheme are both dialects of McCarthy's LISP. Today though, "LISP" is shorthand for the former.
Answer: It is worth learning for "mind-expansion" purposes but not so popular for building apps these days.
However, it is powerful, and mature, and there are fast and free compilers out there. So there is no reason not to choose it for a program if you like.
The way in which Lisp treats data structures and program structures the same offers amazing power which is worth understanding.
Its history is fascinating and it has shaped the world of computer science.
Be sure to check out Ableson and Sussman's Structure and Interpretation of Computer Programs at MIT OpenCourseware
Clojure: a Lisp on .NET and Java VMs
GNU CLISP.
CMU Common Lisp
Comment: CMUCL isn't updated as much any more.  I'd stick with SBCL, unless there's a reason to use the older one.
Comment: That's not really true. SBCL is more active than CMUCL, but CMUCL is actively maintained. Just three weeks ago had with CMUCL 20a a new major release. CMUCL also has monthly snapshot releases.
Comment: What exactly is the difference between "CMUCL isn't updated as much" and "SBCL is more active"?  :-)  You say, ( b a)...
Answer: Depends on the book. Which book?
Common Lisp is worth learning today because it's one of the few languages that pretty much "does everything". If there's some mainstream or obscure programming idiom or technique, odds are Common Lisp has it already in some form. About the only thing CL lacks is continuations (many argue it doesn't need them, but that's not helpful if you want to explore them).
Anyone spending any serious time writing in Common Lisp will come out Changed in some way, typically for the better, IMHO.
Even if you can't carry all of the Lispy concepts you learn and use in to other environments, knowing about them and how they work is still useful.
Comment: Well, CL _has_ delimited continuations. There are even web-frameworks built around them.
Answer: Good programmers expose themselves to as many different programming paradigms as they can - not as many programming languages as they can.
The LISP family (there are several variants) is very worth while getting to know. Your objective should be getting your head wraped around functional programming and the lambda calculus - the paradigm that LISP is based on. Focus less on becomming an "ace" LISP programmer (that could take years).
If you find functional programming "flips your switch", try having a look at PROLOG too - here the paradigm is based on evaluation of Horn Clauses (predicate logic).
I may have spent the last 20 years earning a living as a COBOL programmer (OMG - they still have those!), but I think I am a better programmer because of the time spent learning what LISP, and a number of other programming languages were really all about.
Have a blast...
Answer: Here's a Google Tech talk worth watching about a company currently producing large, complex software for the airline industry in Common Lisp:
Lisp for High-Performance Transaction Processing (The video is now unavailable. Here's some note by Zach Beane.)
Other topics are mentioned in that video, including Clojure, a new variant of Lisp for the JVM (some work is now being done to develop Clojure for the CLR too, but that is not as far along), which is worth checking out for the way it addresses concurrency issues.  See the Clojure site at:
http://clojure.org/
and, in particular at first, check out the link in the upper right on that page to some excellent Screencasts with overviews of the concurrency issues and Clojure features.
If you get interested in Lisp, and the book you found is not that great (I have an old one myself that didn't do much for me), Paul Graham's book On Lisp is available free at http://www.paulgraham.com/onlisp.html and is very good.  The general Lisp idea is the same for Common Lisp or Scheme or Emacs Lisp or Clojure, but the specifics will be different - so keep that in mind if reading Graham's book, which focuses mostly on Common Lisp (with some mentions of Scheme specifics.)  On Lisp is probably not the best beginner book, but it's worth going through it and just skimming over specifics you're not ready to follow in detail yet to see what is there, particularly with regard to macros, which On Lisp really explores.
Answer: One benefit of Lisp is that you develop an appreciation for prefix and wonder why everyone else in the world doesn't us it too (like with Latex or vim)
+ 1 2 3 4 5 6 7 8 9

is much easier to code/edit/paste than
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9

Comment: efficient copy-paste is actually an aspect I never thought of ;-)

But how about "(1 to:9) sum"
Comment: @blabla999 I was thinking more in practical terms, like a calculator. I don't understand why humanity didn't go "wait a minute, wouldn't it make sense to make the plus operator somehow apply to everything that follows?"
Answer: See this question, and especially the third answer, the one that explains that Lisp is good for solving complicated problems, those problems that are hard to decompose into more manageable modules if you were to try to solve them in another language. In other words, if you are keen on exploring ways to solve convoluted problems, that involve, let's say Natural Language Processing, or Knowledge Aggregation... then, yes, Lisp might just be useful to you.
Answer: Learn lisp to learn about macros, and that code is data, and to learn that you can reach enlightenment w/o the self-flagellation of C++.
Learn Common Lisp to learn about reader macros and compiler macros.  I don't know any other language that has them.
Learn scheme for continuations.
Learn Clojure because it's going to make Java obsolete :-)
Comment: 2016 now and Java is still going strong while Clojure remains obscure... will revist this again in 7 years
Answer: It (Common Lisp) is still heavily used by academics working in Artificial Intelligence. Scheme is a Lisp-like language used by many (most?) CS departments as well. Personally I think learning Lisp is worthwhile whether or not you end up using it. It's a classic language that we've learned a great deal from over time.
Comment: Can you give some examples for Common Lisp? The only people I know are the ones working with Kevin Knight at USC/Information Sciences Institute.
Comment: Gordon Novak at UT uses Lisp in all but the two entry level classes he teaches (which the curriculum specifies Java for): http://www.cs.utexas.edu/~novak/
Answer: Learning LISP is a good way to learn functional programming effectively, and is often used as an introductory language for undergraduate students.  Many people feel that Structure and Interpretation of Computer Programs, which uses the Scheme dialect of Lisp, is a book that should be on every programmers shelf.
Paul Graham has been a big proponent of Lisp, and in his book, Hackers and Painters, he describes how he used the power of Lisp to dominate the competition in creating ViaWeb for Yahoo Stores.
Elsewhere, I've seen Lisp dialects used prominently in the aerospace industry, as scripting tools for integration frameworks like Comet, and AML.  Lisp will always be tied to the early AI experiments in the 1950's.
Answer: As other have alluded to, Lisp isn't that popular anymore for general programming, and it definitely (IMO) has some major problems for writing real systems in, but of course others disagree (for instance much of ITA's software is written in Lisp, and they make crazy bank).
Even if you never write a 'real' program in Lisp, it is absolutely worth learning. There are many programming techniques originally pioneered in Lisp that, knowing them, will help you write better code in Python, Perl, Ruby, ML, Haskell, and even C++. For instance, check out Higher Order Perl, which shows how to do all kinds of amazing tricks in Perl; to quote the introduction "Instead of telling you how wonderful Lisp is, I will tell you how wonderful Perl is, and in the end you will not have to know any Lisp, but you will know a lot more about Perl. [...] Then you can stop writing C programs in Perl. I think you will find it to be a nice change. Perl is much better at being Perl than it is at being a slow version of C."
And there are some great books out there that use Lisp, and it will be easier to understand them if you know the language - SICP, Norvig's Paradigms of Artificial Intelligence Programming, and The Reasoned Schemer all come to mind as must-reads.
Answer: Some people here are recommending Clojure. While I would say that Lisp in general is good, I would caution against Clojure, at least for beginners. This is not out of any difficulty using Clojure, just in the fact that Clojure is gratuitously inconsistent with Common Lisp and Scheme. If you want JVM integration, use Armed Bear Common Lisp: https://common-lisp.net/project/armedbear/ , though for general use, I would recommend Steel Bank Common Lisp: http://www.sbcl.org/
Comment: Why does it matter if it's gratuitously inconsistent?
Answer: This is like questioning if "it's worth to learn C these days of web programming?". Only you can decide if it's worth. What you have to ask yourself is: what am I trying to achieve reading the book?
Learning new languages sometimes aren't useful in the practical sense of things (maybe you're aren't going to use LISP ever in your life), but in the long term it's going to be useful because of the knowledge acquired by different paradigms you aren't too familiar with - and you could use some of you learned in what you already use today.
Comment: I'd emphasize the "sometimes" in your second paragraph.  Learning new languages *sometimes* isn't useful in the practical sense of things, but sometimes it *is* quite useful.  I find that when I learn a new language I frequently start to see potential uses for it in places I wouldn't have expected.  Acquiring knowledge of different paradigms and gaining skill in using different tools (including different languages) is fundamentally a very **practical** skill for a modern software engineer.
Comment: What I said about practical is that sometimes people want to learn other languages as "silver bullets" to a lot of problems we have in development, like "I'm going to learn this language in all projects I have and it's going to solve everything", and maybe LISP isn't going to be this way, maybe he's not ever going to write a single line in it. But what he learned while reading LISP could help him solving problems in other areas in his career... the same POV as yours. Sorry if I haven't been more clear, I'm trying to suck less every day with my english skills. :)
Answer: It's been awhile since university, but after I took a 3rd year CS course that required learning Lisp and writing Lisp programs, writing and thinking recursively was a snap. Not that I had problems with recursion before the course, but afterwards, it was 2nd nature. I also used CLOS in the course (University of Toronto), but it was so long ago, I barely remember what I did.
Comment: The AI course at York had a logic programming course as a prerequisite, and that course was LISP and Prolog (The AI course ended up being Java and Prolog, but other semesters had been LISP). That was not soooo long ago (about 6 years).


How to wire a digital LED voltmeter in line with an illuminated rocker switch so the switch light is on and the meter displays the actual voltage

Question: 12v power supply to put output signal on a 7 way trailor connecter.How to wire the LED voltmeter in series with an illuminated rocker switch,so when the switch is turned on,and the light is lit,the volt meter shows read out of the actual measured voltage.
Comment: Put the positive terminal of the meter on the positive output terminal of the switch.  Put the negative terminal of the meter on the negative output terminal of the switch.
Comment: Thankyou very much!
Answer: You don't wire a voltmeter in series with the load. Instead you wire it in parallel with the load because you're trying to measure the voltage across the load.

simulate this circuit – Schematic created using CircuitLab
Figure 1. A voltmeter is wired across the load. An ammeter is wired in series with the load.


LIBOR Reform creates Winners and Losers

Question: One phrase I heard of the reform to move away from LIBOR is that it would create winners and losers.  Can someone explain how this might happen?
Answer: The reason that LIBOR is going away is because it was susceptible to manipulation by its member banks. So whether you're a "winner" or a "loser" depends on what the banks actually did and how it affected you.
If the banks artificially kept LIBOR rates low, then borrowers won (because they paid less interest) and lenders/investors lost (because they received less return on their investments). So the shift would be a "win" for investors/lenders (higher returns) and a "loss" for borrowers (higher interest rates).
The opposite would be true if banks artificially inflated rates.
It's hard to say if either actually happened, since there's not a good way to know what rates should have been to know if they were being manipulated.
Comment: @PeteB. The "something else" that is currently proposed is based off of market transactions (repos) versus a "committee" of 16 banks. So yes, there may be some room for manipulation, but I would argue that the market (in theory) will make that much harder (or expensive).
Comment: Good answer, but it seems a bit silly as they can still manipulate rates.  LIBOR was just the conduit that will just be something else from now go forward.

LIBOR Reform creates Winners and Losers


process.nextTick: Cannot read properties of undefined (reading 'indexOf')

Question: I have a angular project. Thus when I hit npm start I get the error:

> email@example.com build
> ng build

Node.js version v21.0.0 detected.
Odd numbered Node.js versions will not enter LTS status and should not be used for production. For more information, please see https://nodejs.org/en/about/releases/.
⠼ Generating browser application bundles (phase: building)...
node:internal/event_target:1084
  process.nextTick(() => { throw err; });
                           ^
TypeError [Error]: Cannot read properties of undefined (reading 'indexOf')
    at /home/user_name/project_path/node_modules/@angular-devkit/build-angular/node_modules/sass/sass.dart.js:104395:12

This is the project's dependencies
  "dependencies": {
    "@angular/animations": "^16.2.0",
    "@angular/common": "^16.2.0",
    "@angular/compiler": "^16.2.0",
    "@angular/core": "^16.2.0",
    "@angular/forms": "^16.2.0",
    "@angular/platform-browser": "^16.2.0",
    "@angular/platform-browser-dynamic": "^16.2.0",
    "@angular/router": "^16.2.0",
    "rxjs": "~7.8.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.13.0"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~16.2.6",
    "@angular/cli": "^16.2.6",
    "@angular/compiler-cli": "^16.2.0",
    "@types/jasmine": "~4.3.0",
    "jasmine-core": "~4.6.0",
    "karma": "~6.4.0",
    "karma-chrome-launcher": "~3.2.0",
    "karma-coverage": "~2.2.0",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "~2.1.0",
    "sass": "^1.69.4",
    "typescript": "~5.1.3"
  }

I deleted node_module folder, run npm i, then npm start and the error persists.
I hope someone would figure it out what is causing the problem.
Answer: Angular doesn't support odd versions of Node and Node20 support hasn't landed yet.
You should downgrade to node 18/use nvm to set the node version to 18.
You can track the Node20 support on this issue.
Comment: Thanks! that worked for me! Now I'm using node 18
Answer: I have had a very similar error message when I didn't add my scss correctly.
I did come across this post regarding what causes the error
SOLUTION:
'Make sure you do not have trailing or dangling Saas operators like &. in your stylesheets
Post where I found my problem/solution


Significant interaction but non-significant simple slopes

Question: I conducted a multiple regression analyses that included an interaction term (continuous x continuous). The interaction term was significant, but none of the simple slopes (1 SD above the mean, at the mean, 1 SD below the mean) were significant. How should I interpret this?
Comment: none significant main effect can still have significant interaction term. It's called cross-over interaction.
Comment: Was the first order term significant before adding in the interactions?
Comment: Possible duplicate of http://stats.stackexchange.com/questions/156070/significant-interaction-but-non-significant-slopes?rq=1
Comment: There was a significant main effect of one of the predictors (what I'm considering to be the moderator) when the interaction term is not in the model. The other predictor (the independent variable) is not significant.
Comment: Looked through the other questions/answers - they don't quite apply! Thanks!
Comment: I would not include any terms in the model unless the first order term was significant.  As a general rule, it makes little sense to include interactions if the variable by itself was not significant.
Answer: The interaction term is specifying that variable $X$ is being moderated by variable $Z$. A significant p-value suggests that the slope (or regression weight) for variable $X$ is significantly different for different values of $Z$ (e.g., -1 SD, M, and +1 SD).1 Said differently, the interaction "can be interpreted as the amount of change in the slope of the regression of $Y$ on $X$ when $Z$ changes by one unit" (source).
When evaluating the simple slopes of $X$, different values of your moderator variable $Z$ can be used to probe where the slopes might be different (as is common for continuous variables and used in your example: -1 SD, M, and +1 SD). Not finding that the slope of $X$ is significant for any of these values does not invalidate your interaction.
With simple slopes, you are testing whether the slope (or regression weight) of $X$ is different from zero at the value of $Z$. Therefore, you can have slopes of $X$ that are significantly different from one another but not be significantly different from zero.
Let's say that you have a significant interaction and the slope of $X$ at -1 SD for $Z$ is -0.100 and the slope of $X$ at +1 SD for $Z$ is +0.100. The slopes of $X$ can be significantly different from one another and they would indeed "cross paths" forming your interaction but the values of $\pm$0.100 themselves may not be significantly different from zero.
We often see that at least one slope in our simple slopes is different from zero, which provides an indication that that value of $Z$ is having the specific effect in the interaction (because that slope is more perpendicular to a horizontal line, which is a slope of zero). With non-significant simple slopes, the effect is less obviously one value of $Z$ or another and rather reflects the general moderation of $X$.
1 You can use any values for continuous variables but -1 SD, M, and +1 SD are most common. If you have theoretically important values, then it would be better to use those instead of this arbitrary standard.
Edit: To provide more information about what @Alexandre Gareau and @Pere said about cross-over interactions, which applies to this circumstance, here's a nice descriptive example: https://www.theanalysisfactor.com/interactions-main-effects-not-significant/
Answer: It could happen that you found an instance of cross-over interaction or a close related phenomenon, since the cross-over interaction concept is usually used in relation to ANOVA instead of linear regression. That's what  @Alexandre Gareau said and agrees with the model proposed by @not_least_squares.
Anyway, since you said in comments that one main factor is significant when non taking interaction in account, I think your problem is multicollinearity. When you take in account main effects and interaction, you have three predictor variables ($X_1, X_2$ and $X_1 \times X_2$) and I suspect multicollinearity arises because $X_1 \times X_2$ is highly correlated with  $X_1$ or $X_2$. Therefore, coefficient estimates may change erratically without changing the predictive power of the model nor the dependent variable estimates.
I'll give an example where I would expect to happen the same issues you have found. Let's imagine we have a sample of offers of apartments for sale in a given area, and we want to predict selling price from the following variables:

$X_1$: usable floor area (in m2).
$X_2$: floor to ceiling height (in m).

If we run a regression analysis with those variables, we are likely to find that usable floor area is highly significant while height isn't.
If we take in account an interaction, we will just be adding another predictor variable $X_1 \times X_2$, that is, inner volume of the apartments, and, since height is nearly constant, volume will be highly correlated with apartment usable floor area. The same predictions that can be made using floor area can be made using inner volume, there is nearly no advantage in using one or the other, and definitively no advantage on using both.
Therefore, if I were you, I would compare models with just the significant main effect against models with just the interaction and models with both. If there is not a big improvement in using one of the last two, I would just use the model with the significant main effect.
And just as a closing note: interactions are very useful when performing ANOVA and analysing planned experiments, but beware of interactions when using regression to analyse observational data.
Comment: @Antoni Parellada The more information he shares, the more our answers will fit his problem - that is, to tell him what is happening instead of what could be happening. Anyway, I would suggest him to post regression summaries (with correlations, coeficients, significance and so) for simplicity and completeness.
Answer: You interpret it exactly as you'd think. Imagine the true model is
$$ Y = \beta_0 + \beta_1 X_1 X_2 + \varepsilon  $$
So, the slope of $X_1$ depends on the value of $X_2$ and vica versa, and when one variable is zero, the other has no slope. Note that if you shifted the variables (e.g. mean-centering) in this model, the main effects would reappear.


Android and .mov files

Question: How can I play .mov files on Android 2.2+ without converting them?
EDIT:
I am looking for a way to install Codecs rather than find a video player on the market if possible.
Thank you.
Answer: Rockplayer supports .mov files (at least the ones that I've attempted to view). The GUI isn't fantastic, it's basically just a file manager look, but I don't find myself watching video on my phone much. There could be additional options as well.
Answer: According to this forum post, there are a few media players on the Android Market that will play them (possibly with a little chop and jitter?) natively on the phone.

Android and .mov files


What is the name of this pool or irrigation part?

Question:
Currently in a swimming pool shed. A distributor?
This device takes water in the top, and outputs it alternately to one of five pipes at the bottom. When working it makes a clockwork sound. There are plastic gears inside.
When I know what it is called then I can get parts for a replacement.
Answer: It is a zone indexing valve. They are commonly found on sprinkler systems to route the water to different areas. the design changes a lot so if you can find a brand name, it will help getting parts. Worse case scenario, you will have to replace the valve with a new one. good luck and stay safe out there.
Comment: @PolypipeWrangler if junk keeps getting in then fit a filter before that device...
Comment: Thank you, junk keeps getting in this one..
Comment: Have done, but haven't finished training the guy who takes it off to "vacuum" the pool. He uses this inlet because it sucks the hardest. Outlets go to five pairs of jets on pool base.


Need to use Seagate hard drive on MacBook, Mac desktop and PC?

Question: I have a Seagate hard drive and need to use it on PC for work and MacBook and Mac Desktop. The hard drive works on both the PC and Mac desktop but on my MacBook it only comes up as read only. How do I fix this?
Answer: You will need to format the drive with a filesystem that OS X and Windows are able to understand.
You haven't stated the size of the drive, but my suggestions would be exFAT, as it can read/write on both operating systems, and don't have the file-size limitations of FAT32, though you need to be using OS X 10.6 (Snow Leopard) or above.
Answer: Another possible solution is to purchase one of the two major NTFS drivers for Mac, thus giving your OS support for writing to NTFS drives without the need to format the drive.
http://www.paragon-software.com/home/ntfs-mac/
http://www.tuxera.com/products/tuxera-ntfs-for-mac/
Personally, I have gone with Tuxera's one as it allows installs on any macs you own and hasn't so far changed the version number (i.e. forced an upgrade cost) on me since I bought it back in around '09. I believe Paragon's one has been through 2 versions since then...


Drop rows in data frame only if values in two columns are reversed and all other values identical

Question: I am working with the iris dataset, and manipulating it as follows to get a species, feature1, feature2, value data frame:
gatherpairs <- function(data, ...,
                        xkey = '.xkey', xvalue = '.xvalue',
                        ykey = '.ykey', yvalue = '.yvalue',
                        na.rm = FALSE, convert = FALSE, factor_key = FALSE) {
  vars <- quos(...)
  xkey <- enquo(xkey)
  xvalue <- enquo(xvalue)
  ykey <- enquo(ykey)
  yvalue <- enquo(yvalue)

  data %>% {
    cbind(gather(., key = !!xkey, value = !!xvalue, !!!vars,
                 na.rm = na.rm, convert = convert, factor_key = factor_key),
          select(., !!!vars))
  } %>% gather(., key = !!ykey, value = !!yvalue, !!!vars,
               na.rm = na.rm, convert = convert, factor_key = factor_key)%>%
    filter(!(.xkey == .ykey)) %>%
    mutate(var = apply(.[, c(".xkey", ".ykey")], 1, function(x) paste(sort(x), collapse = ""))) %>%
    arrange(var)
}

test = iris %>%
         gatherpairs(sapply(colnames(iris[, -ncol(iris)]), eval))

This was taken from https://stackoverflow.com/a/47731111/8315659
What this does is give me that data frame with all combinations of feature1 and feature2, but I want to remove duplicates where it is just the reverse being shown. For example, Petal.Length vs Petal.Width is the same as Petal.Width vs Petal.Length. But if there are two rows with identical values for Petal.Length vs Petal.Width, I do not want to drop that row. Therefore, just dropping rows where all values are identical except that .xkey and .ykey are reversed is what I would want to do. Essentially, this is just to recreate the bottom triangle of the ggplot matrix shown in the above linked answer.
How can this be done?
Jack
Answer: I think this could be accomplished using the first part of the source code, which performs a single gathering operation. Using the iris example, this will produce 600 rows of output, one for each of the 150 rows x 4 columns in iris.
gatherpairs <- function(data, ...,
                        xkey = '.xkey', xvalue = '.xvalue',
                        ykey = '.ykey', yvalue = '.yvalue',
                        na.rm = FALSE, convert = FALSE, factor_key = FALSE) {
  vars <- quos(...)
  xkey <- enquo(xkey)
  xvalue <- enquo(xvalue)
  ykey <- enquo(ykey)
  yvalue <- enquo(yvalue)

  data %>% {
    cbind(gather(., key = !!xkey, value = !!xvalue, !!!vars,
                 na.rm = na.rm, convert = convert, factor_key = factor_key),
          select(., !!!vars))
  } # %>% gather(., key = !!ykey, value = !!yvalue, !!!vars,
    #            na.rm = na.rm, convert = convert, factor_key = factor_key)%>%
    # filter(!(.xkey == .ykey)) %>%
    # mutate(var = apply(.[, c(".xkey", ".ykey")], 1, function(x) paste(sort(x), collapse = ""))) %>%
    # arrange(var)
}


Why does my iPod Touch automatically turn the volume all the way down?

Question: I have an 8GB iPod Touch, 4th generation.  Recently it has been automatically turning the volume all the way down, and it often won't let me turn it back up again.  This happens both when I'm using headphones and when I'm not.  It has also been restarting itself automatically.  It hasn't always done this--I've had it since December 2010, and it started doing it in May 2011.  Any suggestions?
Comment: Do you notice this when switching between headphones in and out? There are at least three distinct volume settings on the device: no headphones (internal speaker), regular headphones, and headphones with remote and mic. Are you noticing settings changes that this is affecting?
Answer: Three things can cause this:

The down button is now physically pressed (or the electrical contact has shorted/failed)
The headphone jack is sensing a volume button press (much less likely)
software is corrupt (very very unlikely, but still possible)
bluetooth remote (also very very unlikely)

You can restore the device to rule out #3. Turning off bluetooth nixes #4. You might be able to rule out #2 by trying some different headphones, but I've seen that fail in ways that headphones in or out won't help. You'll need a repair / exchange to fix the first two issues if it's not caused by a temporary piece of debris or light cleaning with clean, dry lightly compressed air.
Answer: I have the exact same problem with my iPod. I've found a temporary but helpful fix is to physically depress the down volume button with quite a bit of pressure a few times. If the volume button is stuck, depressing it a few times seems to jolt it loose.
Answer: I fixed this by just doing a reset on all settings, no need to erase data.  Was sticking on no volume
Answer: Try a squirt of WD-40 in the volume down button. Worked for me.
Comment: Might be dangerous to put oil into your phone though...


Singular Value Decomposition of a Real Unit Matrix

Question: Given a real matrix $A \in \mathbb{R}^{m \times n}$ whose entries are all ones, what is the reduced/short/economy singular value decomposition $A = U\Sigma V^T$? I can see that we have a single singular value for $A$, namely $\sqrt{mn}$, but I'm having trouble coming up with general formulas for the orthogonal matrices $U$ and $V$ in terms of $m$ and $n$.
Comment: If you already know that there's a single singular value, then you also know that there's a single left singular vector and a single right singular vector, both of which are very easy to compute. Isn't that all the information you need for a reduced SVD?
Comment: I thought for SVD of any given $m \times n$ matrix there will be $m$ left singular vectors and $n$ right singular vectors? I've been trying to determine some kind of pattern by generating various unit matrices and using the svd function in MATLAB, but I can't discern anything reasonable.
Comment: Yes, that's true of SVD, which is non-unique. But only the singular vectors associated to the nonzero singular values matter; that's the point of the reduced SVD.
Answer: Suppose $A$ has $k$ nonzero singular values (i.e. $\sigma_k>\sigma_{k+1}=0$). Partition $U$ as $\pmatrix{U_1&U_2}$ and $V$ as $\pmatrix{V_1&V_2}$, where each of $U_1$ and $V_1$ has $k$ columns. The so-called reduced/economic SVD is given by $U_1\operatorname{diag}(\sigma_1,\ldots,\sigma_k)V_1^T$. Note that the result of this matrix product is precisely equal to $A=USV^T$. The terms "reduced" or "economic" refer not to the matrix product, but to the sizes of multiplicands: since $U_1,\operatorname{diag}(\sigma_1,\ldots,\sigma_k)$ and $V_1$ have smaller sizes than $U,\Sigma$ and $V$, it is more economical to store them than to store a full SVD.


Why is the knapsack problem pseudo-polynomial?

Question: I know that Knapsack is NP-complete while it can be solved by DP. They say that the DP solution is pseudo-polynomial, since it is exponential in the "length of input" (i.e. the numbers of bits required to encode the input). Unfortunately I did not get it. Can anybody explain that pseudo-polynomial thing to me slowly ?
Comment: Possible duplicate of [How to understand the knapsack problem is NP-complete?](https://stackoverflow.com/questions/3907545/how-to-understand-the-knapsack-problem-is-np-complete)
Answer: The running time is O(NW) for an unbounded knapsack problem with N items and knapsack of size W. W is not polynomial in the length of the input though, which is what makes it pseudo-polynomial.
Consider W = 1,000,000,000,000. It only takes 40 bits to represent this number, so input size = 40, but the computational runtime uses the factor 1,000,000,000,000 which is O(240).
So the runtime is more accurately said to be O(N.2bits in W), which is exponential.
Also see:

How to understand the knapsack problem is NP-complete?
The NP-Completeness of Knapsack
Complexity of dynamic programming algorithm for the 0-1 knapsack problem
Pseudo-polynomial time
Comment: @LushaLi This helped me: https://www.youtube.com/watch?v=9oI7fg-MIpE. If N is an array where each element has a fixed max size input (say each element in the array is no more than 32 bits), and you run a for loop on this array once, then it is a polynomial time algorithm in the input size N of the array. However, if N is an integer and you run a loop over N, then N is unbounded and grows exponentially in the number of bits it takes to represent it. So a simple for loop on N is, actually, exponential. Note that in the case of the array, the size of each element in the array was upper-bounded.
Comment: Sorry, I didn't get it.  Let's say if we have an algorithm with time complexity O(N), then we have O(2^(bits in N)), which is exponential?  Thanks~
Comment: I wasn't convinced. There are a lot of algorithms with the same properties that are not "pseudo-polynomial". Say, what is the complexity of Sieve of Eratosthenes (or any other prime numbers finder)?
Comment: It is a really weird way to describe the running time of an algorithm indeed. If you have an outer-loop with N iterations and an inner-loop with W iterations, then the running time of your algorithm is O(NW)... no? The fact that the input to your program will consist of N integers and an integer W seems to be a separate issue - your algorithm will still make N * W iterations.
Comment: Link #3 referring to "Complexity of dynamic programming for the 0-1 knapsack problem" is dead.
Answer: In most of our problems, we're dealing with large lists of numbers which fit comfortably inside standard int/float data types. Because of the way most processors are built to handle 4-8 byte numbers at a time at no additional cost (relative to numbers than fit in, say, 1 byte), we rarely encounter a change in running time from scaling our numbers up or down within ranges we encounter in real problems - so the dominant factor remains just the sheer quantity of data points, the n or m factors that we're used to.
(You can imagine that the Big-O notation is hiding a constant factor that divides-out 32 or 64 bits-per-datum, leaving only the number-of-data-points whenever each of our numbers fit in that many bits or less)
But try reworking with other algorithms to act on data sets involving big ints - numbers that require more than 8 bytes to represent - and see what that does to the runtime. The magnitude of the numbers involved always makes a difference, even in the other algorithms like binary sort, once you expand beyond the buffer of safety conventional processors give us "for-free" by handling 4-8 byte batches.
The trick with the Knapsack algorithm that we discussed is that it's unusually sensitive (relative to other algorithms ) to the magnitude of a particular parameter, W. Add one bit to W and you double the running time of the algorithm. We haven't seen that kind of dramatic response to changes in value in other algorithms before this one, which is why it might seem like we're treating Knapsack differently - but that's a genuine analysis of how it responds in a non-polynomial fashion to changes in input size.
Comment: This is the best response I have read so far.
Answer: The way I understand this is that the capacity would've been O(W) if the capacity input were an array of [1,2,...,W], which has a size of W. But the capacity input is not an array of numbers, it's instead a single integer. The time complexity is about the relationship to the size of input. The size of an integer is NOT the value of the integer, but the number of bits representing it. We do later convert this integer W into an array [1,2,...,W] in the algorithm, leading people into mistakenly thinking W is the size, but this array is not the input, the integer itself is.
Think of input as "an array of stuff", and the size as "how many stuff in the array". The item input is actually an array of n items in the array so size=n. The capacity input is NOT an array of W numbers in it, but a single integer, represented by an array of log(W) bits. Increase the size of it by 1 (adding 1 meaningful bit), W doubles so run time doubles, hence the exponential time complexity.
Comment: This clears it up a whole lot, thank you.
Comment: This makes no sense. By this logic, a for loop that sums the first n natural numbers is pseudo-polynomial?
Answer: The Knapsack algorithm's run-time is bound not only on the size of the input (n - the number of items) but also on the magnitude of the input (W - the knapsack capacity) O(nW) which is exponential in how it is represented in computer in binary (2^n) .The computational complexity (i.e how processing is done inside a computer through bits) is only concerned with the size of the inputs, not their magnitudes/values.
Disregard the value/weight list for a moment. Let's say we have an instance with knapsack capacity 2. W would take two bits in the input data. Now we shall increase the knapsack capacity to 4, keeping the rest of the input. Our input has only grown by one bit, but the computational complexity has increased twofold. If we increase the capacity to 1024, we would have just 10 bits of the input for W instead of 2, but the complexity has increased by a factor of 512. Time complexity grows exponentially in the size of W in binary (or decimal) representation.
Another simple example that helped me understand the pseudo-polynomial concept is the naive primality testing algorithm. For a given number n we are checking if it's divided evenly by each integer number in range 2..√n, so the algorithm takes √(n−1) steps. But here, n is the magnitude of the input, not it's size.
                     Now The regular O(n) case

By contrast, searching an array for a given element runs in polynomial time: O(n). It takes at most n steps and here n is the size of the input (the length of the array).
[ see here  ]
Calculating bits required to store decimal number
Comment: So for your last searching example, why don't consider n as binary too? if n=1024, it also only takes 10bits, so shouldn't it be pseudo-polynomial?
Answer: Complexity is based on input. In knapsack problem, Inputs are size, max Capacity, and profit, weight arrays. We construct dp table as size * W so we feel as its of polynomial time complexity. But, input W is an integer, not an array. So, it will be O(size*(no Of bits required to store given W)). If no of bits increase by 1, then running time doubles. Thus it is exponential, thereby pseudo-polynomial.
Answer: Time complexity is defined as the function of input size (not the input)
Knapsack has complexity of O(nW), here n = size of the coins array.
To represent W, we need log2W bits. This gives us O(n * 2^log2W) = O(n * 2^input_size), Hence exponential.
With the same logic, coin change (nW) is also exponential. However greedy algorithm with canonical coins is polynomial.
// assumed the coins are sorted in ascending order.
int CoinChange(const vector<int>& coins, int amount) {
    int coinsUsed = 0;
    for(int i = n-1; i >= 0; i --) {
        coinsUsed += amount / coins[i];
        amount %= coins[i];
    }
    return coinsUsed;
 }


What's a general rule for this little lambda calculus identity?

Question: I've been fiddling around with a project that does some normalization of lambda calculus(-like) expressions and I stumbled upon that
<code>(λ λ ... λ n (n-1) ... 2 1)
</code>
(De Brujin notation) is just the identity. I've generalized this a little to realize I can do stuff like
<code>(λ λ λ λ 4 2 1) = (λ λ 2)
</code>
So basically if you can identify some character in your expression which is just the variable index n, and all variable indices to the left of that point are greater than n, and to the right is just descending down the variable indices one at a time to index 1 then you can eliminate all the indices to the right of that character (including that character) and then eliminate the _λ_s from the head of the expression and decrease the remaining indices appropriately.
This feels too haphazard to be the simplest form of this identity though. There must be a cleaner way to express this, and possibly a more general rule.
Answer: Turns out this is just eta-reduction