Events from iCal Feed URL Display as "Busy" in Google Calendar

Question: I am attempting to view a ical formatted calendar feed generated by my system in Google Calendar. I am doing this via Google Calendar's "Add by URL" function in the "Other Calendars" drop down menu, and supplying the URL to the dynamically generated ics ical file.
Google Calendar does successfully read the events from the feed and creates the calendar, however all the events are just shown as "Busy" with no details (summary, description, ect) other than the time of the event. The events also have a "Private" lock icon on them in the google calendar view.
I've looked over the generated iCal file's contents and I don't see any reason why Google Calendar would render the events as Private. Each VEVENT has its CLASS property set to "PUBLIC". I have also subscribed to the same URL in OSX's iCal application and the events display perfectly, with all details shown.
Below is a the generated ical file (with sensitive info removed):
BEGIN:VCALENDAR
PRODID:-//My Calendar//iCal Class MIMEDIR//EN
VERSION:2.0
METHOD:REQUEST
X-WR-CALNAME:Joe Smith
BEGIN:VEVENT
DTSTART:20111124T050000Z
DTEND:20111124T050000Z
TRANSP:OPAQUE
SEQUENCE:0
UID:ToDos_82
DTSTAMP:20111108T143800Z
DESCRIPTION;LANGUAGE=en;ENCODING=QUOTED-PRINTABLE:Quisque convallis elementum dui at tristique.
SUMMARY;LANGUAGE=en;ENCODING=QUOTED-PRINTABLE:Test Event
PRIORITY:0
CLASS:PUBLIC
STATUS:CONFIRMED
END:VEVENT
BEGIN:VEVENT
DTSTART:20111124T050000Z
DTEND:20111124T050000Z
TRANSP:OPAQUE
SEQUENCE:0
UID:ToDos_83
DTSTAMP:20111108T143800Z
DESCRIPTION;LANGUAGE=en;ENCODING=QUOTED-PRINTABLE:Proin venenatis ullamcorper dui quis porttitor.
SUMMARY;LANGUAGE=en;ENCODING=QUOTED-PRINTABLE:Another Test Event
PRIORITY:0
CLASS:PUBLIC
STATUS:CONFIRMED
END:VEVENT
BEGIN:VEVENT
DTSTART:20111108T050000Z
DTEND:20111111T050000Z
LOCATION;LANGUAGE=en;ENCODING=QUOTED-PRINTABLE:CLS HQ
TRANSP:OPAQUE
SEQUENCE:0
UID:Events_10
DTSTAMP:20111108T143800Z
DESCRIPTION;LANGUAGE=en;ENCODING=QUOTED-PRINTABLE:Doing some more testing here
SUMMARY;LANGUAGE=en;ENCODING=QUOTED-PRINTABLE:Yet Another Test Event
PRIORITY:0
CLASS:PUBLIC
STATUS:CONFIRMED
END:VEVENT
END:VCALENDAR

Answer: Well it appears that I have fixed the issue. The calendar's URL that I provided GCal did not end in a filename (I use a PHP framework with URL rewriting). I updated the URL, appending "/calendar.ics" to it and subscribed to the URL in GCal, and now all events seem to display fine, showing all details.
Comment: Same issue for me as well.. thnx
Answer: The VEVENTS are marked as TRANSP:OPAQUE. According to the RCF 5545 this means they are blocking elements for a time search.
To make them non blocking change it to TRANSP:TRANSPARENT.
Answer: I've tested the same content and it seems to show up fine in my Google Calendar. I added it using the "Add By URL" option under "Other Calendars". All the details are visible, no locks or other weirdness shown for me.
It sounds like you are dynamically generating the content on-demand. Have you tried just dumping it to a static file and adding it that way - not as a permanent solution, just to see if that makes a difference to GCal?
It may be that the dynamic generation of calendar data takes into account the requester and changes event visibility on that basis. This could easily be the case if, for example, the calendar server is on your intranet.
Comment: The ical data I posted above is definitely the same as what GCal is receiving when it requests it from my server, as the URL its hitting is a PHP script I wrote, which generates the content the same no matter where it was requested from. I guess it couldnt hurt to just setup a static file with the same data on my server somewhere though, and see if that makes a difference


Regular immersion and canonical exact sequences between conormal sheaves

Question: Let $f:X \rightarrow Y$, $g:Y \rightarrow Z$ be regular immersion of locally noetherian . One can then show that $g \circ f$ is a regular immersion. In the book I am reading it is stated that we have a canonical exact sequence
$$0  \rightarrow f^\ast \mathcal{C}_{Y/Z} \rightarrow \mathcal{C}_{X/Z} \rightarrow \mathcal{C}_{X/Y} \rightarrow 0$$
Where $\mathcal{C}$ is the conormal sheaf of the regular immersion. I am curious - how is the first map in this exact sequence defined? I know that The Stacks Project has a proof of it, but it seems very overkill and messy, so I wonder whether there nice ways to define this map locally.
Answer: Vakil has an explanation (with pictures!) of the affine version which I think is very nice: http://math.stanford.edu/~vakil/0708-216/216class50.pdf
Comment: Thank you for your answer, but it is not what I wanted at all unfortunately. I was looking to see how the maps were defined here in a more general setting.
Comment: I see, in your question it says locally, so I assumed you meant the affine setting.


Probability distribution of random variables

Question: The SAT is used as an aid in determining college admissions. This test is a multiple choice test. To discourage random guessing, points are subtracted for wrong answers. Each question has 5 possible answers, and the test taker must pick one answer or choose not to answer the question. One point is awarded for each correct answer, and for each wrong answer 1/4 point is subtracted. Construct a table of probability distribution of the random variable x, which represents the point for each answer. Then calculate the expected point value of a random guess.
Comment: I think you need the self-study tag.
Answer: So, If I understand correctly, you are asking for the probability distribution of the number of points for a single question.
The use of a Bernoulli (0 or 1) random variable can help here. Let $Y \sim Bern(p)$, where $p$ is the probability of getting a question correct. Then the number of points earned or lost on a single question is:
\begin{equation}
X = Y - \frac{1}{4}(1-Y)
\end{equation}
So in order to answer your question, first figure out what $p$ is in the case where we are just guessing. Then you must calculate the expected value of $X$. It's a linear function of $Y$, and $\mathbb{E}(Y) = p$.


How can I set a Title on the Config Page in Joomla Component?

Question: if I add the string:
COM_OHANAH_CONFIGURATION="Ohanah Konfiguration"

to the Language File it still doesnt get changed. Where can I set this?
I looked into the Files of different Joomla Components and all just use the String in the Language file... But in this Component it just doesnt work.
The String is located in the Config page of the component.

It would be great if someone could help me with this :)
Answer: The Solution was to add the String into /language/thefileineeded and not /administrator/language/thefileineeded


Prove that this function is onto and one-to-one

Question: $f:Z \rightarrow Z$
$f(x) = x-5$ , when $x$ is odd
$f(x) = x+3$ ,  when $x$ is even
It seems that it is not onto, because not all integers are covered, but how do you show this?
Comment: Following on mathguy's comment:  if X is odd, what is $f^{-1}(X)?$  and if X is even, what is $f^{-1}(X)$>
Comment: But it is onto! look at the individual y-sets for each of those functions. You see that the first function produceds a y-set of all even numbers, and the second function produces a y-set of all odd numbers. Combining them makes all the integers.
Answer: This is indeed onto,
Pick any $a\in\mathbb{Z}$.
if $a$ is odd we know that $a - 3$ is even (since $a - 2$ is clearly odd) so $f(a - 3) = a$.
if $a$ is even we know that $a + 5$ is odd (since $a + 4$ is clearly even) so $f(a + 5) = a$.
This function is also one to one, and I leave this partially to you, to see this note that for odd $x$, $f(x)$ only hits even numbers and never hits the same number twice. And for even $x$ this only hits odd numbers.


Client Router Causing Wireless Bridge Connectivity Issues

Question: I have an issue that I can't seem to figure out on my own. Whenever I power on a client router, it causes connectivity issues with another router, which functions as a wireless bridge. The connectivity issues manifest as extreme internet slowness, or a complete loss of internet connectivity on the PCs I have connected to the wireless bridge. My network topology is as follows:
<code>-> Cisco DOCSIS 3.0 Modem
---> Netgear R6300v1 (stock firmware) DHCP/NAT
-----> Netgear WNDR3700v1 (10/100/1000 ethernet) *
-----> Windows 7 PC (10/100/1000 ethernet)
-----> Buffalo NAS 2TB (10/100/1000 ethernet)
-----> Wireless Clients (802.11n 2.4Ghz & 5Ghz)
-----> Netgear WNDR4000 (802.11n 5Ghz bridged-client) *
-------> Windows 7 PC (10/100/1000 ethernet)
-------> Windows 7 PC (10/100/1000 ethernet)

* Netgear WNDR3700v1
  OS: OpenWrt Barrier Breaker
* Netgear WNDR4000
  OS: DD-WRT v24-sp2 (07/24/13) mini
</code>
It is worth noting, that I have disabled DNS masquerading, iptables, SPI firewall, and DHCP servers on both affected routers. Both routers also have static IP addresses 192.168.1.3 for the WNDR4000 and 192.168.1.4 for the WNDR3700, and they both share the same gateway 192.168.1.1, subnet, and netmask. I have used ifconfig to check for collisions, but there aren't any on any interface on both routers. I have checked ARP tables on both routers to see if it is getting messed up, but I can't find anything out of the ordinary. I have checked dmesg, syslogd, logread, etc..., and I can't figure out why my wireless bridge has no connectivity when I turn on my other router. When I try and ping, or access the DD-WRT web interface for my wireless bridge from a PC connected directly to my R6300v1 router, the destination host 192.168.1.3 cannot be reached. As soon as I turn off my WNDR3700v1 router, my wireless bridge starts to work again. I appreciate any help I can get to resolve this.
Comment: Apparently, I posted this under the wrong site in error; however, the comment regarding "the best advice we can give you is to hire a professional to help you out" is unnecessary. Another professional, MikeAWood, was kind enough to provide an answer. Although, I use my routers at home, I also work from home as an IT professional, and as such it was important to determine the cause of my issue. I understand now why you would flag my post as off-topic; however, the response I received is not one of constructive criticism, but rather arrogance. I will not be using Server Fault again. Thank you.
Answer: .Are they right next to each other?  Because this has bit me the butt before, make sure they aren't anywhere near each other (they'll likely conflict or one might even shut down the wifi radio and or cause the router to reboot), they aren't using the same channel on wifi.
Comment: hi, thank you for your response :) the client router (the one that causes my wifi bridge to have connectivity issues) doesn't have the radios enabled. I use this router for learning about openwrt, and it's only accessible through ethernet.
Comment: I didn't answer your question: yes, they next to one another. Now, I kept in mind what you mentioned about how you had issues yourself with wifi routers being too close to one another; however, I had turned off all radios on the router, so I didn't think that was cause; that is until I discovered my Android phone is losing connectivity to my 5Ghz SSID whenever the WNDR3700v1 = on. WNDR3700v1 = off, and phone connects again to 5Ghz SSID. I need to give routers some distance from one another, even though radio is off. Radio interference makes me want to pull my hair out sometimes! :P
Comment: yeah, they are fussy about that... you could probably go in an change the channels and set the at least 4-5 channels apart... and that will likely help as well even if they are on...


How to implement one click upload?

Question: Drupal 8 supports multiple file upload, however the native interface requires three steps:

Select one or more files
Click Upload
Click Save

Ideally this could be simplified to a single step i.e. select one of more files, once done it uploads them. The user can delete a file later if they wish, but no point showing them the list of which they just select, just to make them change their mind.
How should one click upload for multiple files be implement in Drupal?
In pure PHP this can be done easily as follows (but Drupal 8 adds too many constraints for this to work):

<?php

$upload_dir = '/tmp/upload_test';
if ( ! is_dir( $upload_dir ) )
{
    mkdir( $upload_dir, 0777, true );
}

/** Rearrange the "parallel" _FILES array into consolidated file items. */
function rearrange( $arr )
{
    foreach( $arr as $key => $all )
    {
        foreach( $all as $i => $val )
        {
            $new[$i][$key] = $val;
        }
    }
    return $new;
}

if ( ! empty( $_FILES['data_fs_uploads'] ) )
{
    $files = rearrange( $_FILES['data_fs_uploads'] );
    print '
Copying uploaded files...
';
    foreach ( $files as &$file )
    {
        // File has 'name', mime 'type', 'tmp_name' path, 'error', and 'size'.
        $file['ext'] = pathinfo( $file['name'], PATHINFO_EXTENSION );
        $target_file = $upload_dir . '/' . $file['name'];
        if ( move_uploaded_file( $file["tmp_name"], $target_file ) )
        {
            print '
Copied ' . $file['name'] . '
';
        }
        else
        {
            print '
FAILED to copy ' . $file['name'] . '
';
        }
    }
}
?>

<form action="upload.php" method="post" enctype="multipart/form-data">
    <input id="data_fs_uploads" type="file" name="data_fs_uploads[]" multiple="multiple" onchange="javascript:this.form.submit();" />
</form>

<?php
foreach ( glob("$upload_dir/*") as $file )
{
    print '
' . $file . '
';
}
?>

Comment: Not sure if I understood your Q correctly, seems to me that you're asking this **[How can I automatically upload images on file selection rather than pressing the upload button?](http://drupal.stackexchange.com/questions/31121/how-can-i-automatically-upload-images-on-file-selection-rather-than-pressing-the/31453)** if true, as you can see, you can easily solve this with a little jQuery "[magic](http://i.imgur.com/vPtZp3G.gif)".
Comment: Yes you got the Q right. The drupal 7 tricks you pointed no longer apply to drupal 8. So we need a Drupal 8 solution. Moreover in Drupal 7 files were always tied to nodes which eventually required saving the node with another click, this is no longer the case with Drupal 8 as the files can be independent of nodes, so with Drupal 8 we are interested in combining all three steps into one.
Answer: Here is how you would create an auto save after selecting an upload file(s) in D8.
upload_autosave.libraries.yml
auto:
  version: 1.0
  js:
    js/auto.js: {}
  dependencies:
      - core/jquery

upload_autosave.module
/**
 * Implements hook_form_alter().
 * Adds JS file to all forms
 */
function upload_autosave_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
    $form['#attached']['library'][] = 'upload_autosave/auto';
}

/js/auto.js
(function ($) {
  Drupal.behaviors.upload_autosave = {
    attach: function (context, settings) {
    if ($('.image-widget-data').length || $('.field--type-file').length){
      $('.js-hide.button.js-form-submit.form-submit').remove();
      $('form', context).on('change', 'input.form-file', function() {
        $('#edit-actions .button.js-form-submit.form-submit')[0].click();
        $(".details-wrapper").html("");
        $('#edit-actions').fadeOut(1000);
      });
     }
    }
  };
})(jQuery);

Comment: Thanks for the module, it works for new content, but fails (goes into infinite loop) when editing and adding more files. Specifically it fails when there are existing files and then trying to add more files via edit.
Comment: @amit ugh... that was unexpected, I'll look into it.
Comment: @amit ok fixed.
Comment: Fantastic, that works. I highly recommend and encourage you to submit this as contributed module to Drupal. If I may offer a suggestion, replace gif with built in progress bar.
Comment: link is dead @NoSssweat
Comment: @NiteshMishra thx for letting me know. If you are interested, I guess you'll have to create the files and copy paste.
Comment: Actually i want to upload files to s3 using jquery uploader here is my question http://drupal.stackexchange.com/questions/231750/direct-image-upload-to-amazon-s3-using-drupal-8 please guide me so that i can achieve it

How to implement one click upload?


Java Stream Map Filter, Remove and Collect

Question: I have a Map with 1000 items and I want to generate a List from the first 500 items of this Map and remove the items that was collected from the Map.
In other words, I want to filter, collect to a List and remove items from a Map.
I'm trying something like that:
final int i = 0;
int max = 5;
Map<String, Object> map = new HashMap<>();
map.put("ads", "123");
map.put("qwe", "123");
map.put("cvb", "123");
map.put("asd", "123");
map.put("iop", "123");
map.put("jkl", "123");
map.put("yui", "123");

List list = map.entrySet().stream().filter(y -> i++ < max).collect(Collectors.toList());

Expected output:
Map with 2 Values
List with 5 Values
Comment: Also, _do_ notice that an `entrySet()` makes no guarantees about the order of its elements. They are not necessarily the first five you added, _unless_ you're using a `LinkedHashMap`. But in general, the idea of taking "the first n elements" from a map doesn't make sense, if the order is important perhaps you should use a different data structure.
Comment: It's not clear what you want to do, and the posted code doesn't compile to begin with. Please provide a sample input and expected output of what you want to do, for example with just 10 elements.
Comment: Note that you cannot use the Stream any more after executing a terminal operation like `.collect` or `.forEach`.
Comment: @ÓscarLópez thanks for you feedback, i made some changes to the question and add an input and output.
Comment: And final means `i` can't be changed once assigned.  So you can't do this `filter(y -> i++ < max).`  And even if you didn't declare `i` final, local variables must be effectively final in lambdas.
Comment: @naman the duplicate does not answer the question
Comment: @YassinHajaj the duplicate gives the way to solve the question for sure as it states the approach of identifying "first N elements" from a map.. anyway, it's kind of an opinion that individuals have and there is nothing more than that in the question according to me. (i.e. `removeIf` is just *not even clearly* a part of the question.)
Comment: @Naman look at the example he's giving, it clearly states that the map should have less items in the end
Answer: Stream API intended to create a new collection, but not to change existing collection, from which a stream created.
It's better use iterator feature in this situation. Like this:
final int MAX = 500;

Map<String, String> map = new HashMap<>();
map.put("Item1", "Item 1 value");
map.put("Item2", "Item 2 value");
// ...
map.put("Item1000", "Item 1000 value");

List<String> list = new ArrayList<>();

var iterator = map.entrySet().iterator();
for (int i = 0; i< MAX; i++) {
  if (iterator.hasNext()) {
    var item = iterator.next();
    list.add(item.getValue());
    iterator.remove();
  }
}

Comment: Works fine with `LinkedHashMap` for getting the first `MAX` items. See comment about this question of Óscar López.
Comment: yes you are right about the `Iterator`, and `LinkedHashMap` garantee removing the first 500 inserted items from the map.
Comment: There is no need to iterate over the `entrySet()` to call `getValue()` on each entry. You can simply use `values()` in the first place, `var iterator = map.values().iterator(); for(int i = 0; i < MAX && iterator.hasNext(); i++) { list.add(iterator.next()); iterator.remove(); }`
Comment: Using iterator garantee removing exactly same entries that added to list. No matters LinkedHashMap or HashMap.
Comment: Underlying mechanisms for the both iterators backed by the same map. So there is no performance benefit of values().iterator() over entrySet().iterator. But entrySet().iterator() also allows you get access to the entry key.
Answer: As pointed out in other answer and comments you cannot alter the map during the streaming operations. So this requires two steps.
var list = map.keySet().stream().limit(500).toList();
map.keySet().removeAll(list);

I've used Java 16 API here but previous versions are minor variations.
Note, however, that is is a pretty meaningless thing to do given the map's order is not defined. It would be more meaningful if you were using a filter with some predicate. Though in that case a more readable alternative might be:
var list = map.keySet().stream().filter(predicate).toList();
map.keySet().removeIf(predicate);

Comment: Or `var list = new ArrayList(); map.keySet().removeIf(predicate.and(list::add));`
Answer: The easiest way to achieve this with A SINGLE STREAM is to use Stream#limit, Collectors#collectingAndThen and perform the removeAll inside of the second downstream Collector
This is possible because the first Collectors.toList will get rid of the map's iteration, the second operation can then delete without getting an exception
List<Map.Entry<String, Object>> list = map.entrySet()
        .stream()
        .limit(max)
        .collect(Collectors.collectingAndThen(
                Collectors.toList(),
                l -> {
                    map.entrySet().removeAll(l);
                    return l;
                }
        ));

System.out.println("map = " + map); // map = {qwe=123, cvb=123}
System.out.println("list = " + list); // list = [ads=123, asd=123, jkl=123, iop=123, yui=123]

Comment: Instead of `removeIf(l::contains)` you can use the good old `removeAll(l)`
Comment: one of the reasons why I marked it duplicate was `.entrySet().stream().limit(max)` doesn't guarantee the "first `max` elements". would like to point you to [Oscar's comment](https://stackoverflow.com/questions/67452611/java-stream-map-filter-remove-and-collect#comment119224194_67452611).
Comment: Is there any advantage in doing the `removeAll` as the collector finisher rather than as a separate statement afterwards? Seems unnecessarily verbose to use a lambda block here (and has the risks associated with lambda operations having side effects).
Comment: Having a one liner is the idea here. What kind of side effects would you imagine sprinter ?


Setting php values in php-fpm confs instead of php.ini

Question: I'd like to set values in php-fpm conf files what are normally set in php.ini. I'm using nginx.
I've created the following setting, but I'm not sure if this would work.
php_value[memory_limit] = 96M
php_value[max_execution_time] = 120
php_value[max_input_time] = 300
php_value[php_post_max_size] = 25M
php_value[upload_max_filesize] = 25M

Do you think if this is OK like this?
What happens when a value is both set in php.ini and in php-fpm conf files? The php-fpm overrides the ini one?
Finally, isn't it a problem that this way I can set different values for all virtual hosts? I mean php.ini seems like a global setting, while this is host dependent. Can different hosts run with different memory-limits, etc?
Answer: Yes, you're right - If you specify these values in php-fpm pool config file, it will override "default" values in php.ini config file - but only for this FPM pool.
In addition to this, remember that some of php directives could be defined as php_admin_value and php_admin_flag as described in PHP Documentation (see the bottom of page).


selecting partially matching data

Question: I was wondering if there was a way to select partially matching data in SQL.
 For example, if I had:
name
----
Index
Index.jpg
Index.html
Foot
foot.jpg
Hand
head.jpg

And wanted to show(all names with matching strings):
name
----
Index
Index.jpg
Index.html
Foot
foot.jpg

Could I use a regex match for this?
Comment: Could you elaborate a bit more on the logic for the selection?  I would just use `where name < 'hand'`, which would work assuming the collation is case insensitive.
Comment: I would like to select and return all of the data that matches. I am building a report that finds all of the asset information that has associated files with it(so Index and Index.jpg). So if an asset did not have any matching information(like Hand and head.jpg) it wouldn't show up.
Comment: Do you mean you're looking for `File.*` matches?
Comment: yes that is exactly what I am trying to do.
Answer: Check out this example I made in SQL Fiddle.
SELECT *
FROM
(
SELECT name AS 'Asset' FROM Table1 WHERE name NOT LIKE '%.%'
) AS A
JOIN
(
SELECT name AS 'Files' FROM Table1 WHERE name LIKE '%.%'
) AS B
ON A.Asset = SUBSTRING(B.Files, 1, INSTR(B.Files, '.') - 1)

selecting partially matching data


What happened to Jazz in 1980?

Question: In this great interview by Rick Beato (around 01:13h) Pat Metheny says that in 1980 something happened - "we all know what it was" - and young musicians suddenly started to play for their parents and not so much for their friends anymore.
Since I'm not super deep into Jazz history I actually don't know what that event was.
My guess would be the expressed criticism of at that time recent developments in Jazz (Rock/Pop influences etc) by Wynton Marsalis perceived by many as a kind of 'jazz police'. But that's just a shot in the dark after a little bit of research.
I actually hope that this kind of music history question fits in here. If not, feel free to tell me.
Comment: Reading you post, my thoughts also went first to Wynton, who was a highly divisive figure at the time and whose father was himself a jazz musician ("play[ing] for their parents").
Comment: I didn't know that his father was also a Jazz musician - I think that's enough evidence for me :)
Comment: My first thought seeing the question was //Mister Roger's Neighborhood//, a show which would have introduced a lot of young children to jazz in the 1970s, and resulted in their desire to play that kind of music once they stated playing musical instruments.  I find the level of musical sophistication on that show to be really mind blowing, especially compared with a lot of children's entertainment today.
Answer: It's a reasonable thought that Metheny was referring to Wynton Marsalis. Marsalis was highly controversial — "polarizing" might be a better word — in the early 1980s. In particular, Marsalis advocated for earlier styles of jazz rather than the more progressive leanings of Metheny and others.
In 1980, while studying at Julliard for a career in classical music, Wynton began gigging with Art Blakey. This led him to shift directions and focus his career on jazz. However, he brought something of a classical aesthetic and practice to the art. His bands often read charts off of stands, wore suits, and played music, or music based on, styles of jazz prominent before around 1965 when more experimental styles came to the fore.
Wynton was particularly outspoken about electronic and rock-influenced jazz. That's probably a big part of what irks Metheny, since he was and is very much at the forefront of those movements. He and others, like Miles Davis most notably, were critical of Marsalis for taking jazz backwards, while Marsalis criticized them for betraying jazz and moving into other forms of music.
Further, Marsalis's father, Ellis, was a jazz pianist who played primarily earlier styles of jazz. It's easy to interpret Metheny as taking a swipe at Wynton for "playing for his parents" in both the literal sense of trying to please his father and also in the sense of playing for an older generation audience that preferred more traditional jazz music.
Comment: That is certainly the case based on what he says, especially when he elaborates and says (paraphrasing) "let's put suits and ties on and play some new original music that was built on the shoulders of people who were in fact playing for their friends". The implication is in 1980 they were recycling music that at one time was fresh and innovative.
Comment: Kenny G "happened". https://en.wikipedia.org/wiki/1980s_in_jazz "In the 1980s in jazz, the jazz community shrank dramatically and split. A mainly older audience retained an interest in traditional and straight-ahead jazz styles. Wynton Marsalis strove to create music within what he believed was the tradition, creating extensions of small and large forms initially pioneered by such artists as Louis Armstrong and Duke Ellington. In the early 1980s, a commercial form of jazz fusion called pop fusion or "smooth jazz" became successful and garnered significant radio airplay."
Comment: @Mazura That's a great reminder that more than Wynton was going on. Both the return to straight-ahead jazz and the rise of smooth jazz moved away from the free jazz of the 60s and fusion of the 70s. Another major change that came soon afterward was the significant entry of jazz into music schools and the standardization of jazz education.
Comment: Having lived through the music eras from the 1960s... I have to say that Pat Metheny's music, regardless of whether people liked it, was not "jazz". It was "smoothed-out jazz", maybe. Like some of the earlier "west-coast jazz", or... ahem... "French jazz"... that made noisier and/or elevator muzak... in my opinion. I know that there are other viewpoints. :)

What happened to Jazz in 1980?


Thick guitar cable

Question: I just bought a few 1/4'' plugs from Switchcraft - I want to assemble my custom short cables in order to connect the effects on my pedalboard.
The hole in the plug handle has a diameter of 0.297'' (about 7.5 mm). My problem is that I have been unable to locate a screened cable with such a big (outer) diameter.
Any suggestions?
Answer: Find a piece of plastic tubing, cut it longitudinally,if needed, and put it over the cable coming out of the plug, About 25mm will do. The plugs are better for pedals if they're right-angled. Also, you can't pull them out by the wire, a favourite trick guitarists seem to have.
Answer: Screened cable comes in various sizes.  But it doesn't HAVE to fill the exit hole.  The strain is taken at the clamp inside the plug.
Not that there should BE much strain between items on a pedalboard.  Maybe you chose unnecessarily robust plugs.
Comment: Typo or do you actually think there _should_ be much strain on the patch cables? I do not think so; nevertheless it is certainly a good idea to err on the sturdy side for connectors, since a pedalboard is seldom a static affair...
Comment: No typo.  What I wrote means 'there shouldn't BE much strain...'  Connectors shouldn't be unnecessarily heavy or bulky.  There's a danger of making the socket on the pedal the weakest point.  You don't want THAT failing.
Answer: I have a suggestion for a potentially easier way to solve your dilemma and accomplish your goal. It's probably less expensive as well. Perhaps you have already explored this solution and found it lacking = but I will post the information just in case you or a future reader of your question might benefit from it.
Why not order the fully assembled patch cables made specifically for pedalboards from some place such as Sweetwater Music where you can get the entire assembly already put together for less than $4.00 (US) per cable if purchased in packs of 3 or more.  Most are 6 inch long but they have varying configurations, and gauges.  Two examples are pictured below.  The link above will take you to the right page on the Sweetwater Music Website.  Good luck with your pedal project!

Thick guitar cable


nginx proxy fail2ban on 401

Question: In the setup I've right now I've NGINX that works as proxy for (serveral) internal VMs. Now, I would like to protect these VMs from bruteforce, such that, if there's a huge amount of 401 the IP should be blocked.
I've google around on how to use fail2ban, but I can't figure out how it can work in my case.
The access.log of nginx looks like this (i've hidden some sensitive infos)
148.XXX.XXX.XXX - 92....396 [09/Jan/2017:13:43:32 +0100] "POST /v1/schemas/7...b8/documents HTTP/1.1" 200 364 "-" "python-requests/2.10.0"
148.XXX.XXX.XXX - 92....396 [09/Jan/2017:13:43:32 +0100] "DELETE /v1/documents/fd7...09e1?force=true HTTP/1.1" 200 83 "-" "python-requests/2.10.0"
148.XXX.XXX.XXX - 92....396 [09/Jan/2017:13:43:32 +0100] "GET /v1/schemas/713e4ee8-...b8/documents HTTP/1.1" 200 6689 "-" "python-requests/2.10.0"
47.XXX.XXX.XXX - - [09/Jan/2017:13:43:33 +0100] "GET /wp-login.php HTTP/1.1" 301 178 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1"
47.XXX.XXX.XXX - - [09/Jan/2017:13:43:39 +0100] "GET /wp-login.php HTTP/1.1" 301 178 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1"
47.XXX.XXX.XXX - - [09/Jan/2017:13:43:44 +0100] "GET / HTTP/1.1" 301 178 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1"
148.XXX.XXX.XXX - 92....396 [09/Jan/2017:13:44:33 +0100] "GET /v1/schemas/713e4e...d649b8/documents HTTP/1.1" 200 6689 "-" "python-requests/2.10.0"
148.XXX.XXX.XXX - 92....396 [09/Jan/2017:13:44:33 +0100] "POST /v1/schemas/713e4..fd649b8/documents HTTP/1.1" 200 364 "-" "python-requests/2.10.0"
148.XXX.XXX.XXX - 92....396 [09/Jan/2017:13:44:33 +0100] "DELETE /v1/documents/9f5....cadf29031c?force=true HTTP/1.1" 200 83 "-" "python-requests/2.10.0"
148.XXX.XXX.XXX - 92....396 [09/Jan/2017:13:44:33 +0100] "GET /v1/schemas/713e...649b8/documents HTTP/1.1" 200 6689 "-" "python-requests/2.10.0"
87.XXX.XXX.XXX - {{customerId [09/Jan/2017:13:45:08 +0100] "GET /v1/repositories HTTP/1.1" 401 101 "-" "PostmanRuntime/3.0.9"
87.XXX.XXX.XXX - {{customerId [09/Jan/2017:13:45:09 +0100] "GET /v1/repositories HTTP/1.1" 401 101 "-" "PostmanRuntime/3.0.9"
87.XXX.XXX.XXX - test [09/Jan/2017:13:45:20 +0100] "GET /v1/repositories HTTP/1.1" 401 101 "-" "PostmanRuntime/3.0.9"

As you can see, NGINX works as proxy for the service and for the website and other services. What i would like to prevent are the last 3 lines, where the return code is 401.
As far I understood (mostly from here) I could make a regexp to intercept that lines that contains a 401, setting a burstime of 3600 (60 mins lock) and retries of 100. So that 100 errors per hours are permitted.
Note: I've to figure out this value (any idea?), it may happen that someone gets 401 every now and then.
Yet, I know the thoery but not yet the practice. Can someone help me in setting this up especially on how to write the regexp for that condition.
I came up with ^<HOST>.* 401 but don't know if it's enough and I would like to avoid to block everybody by mistake.
After finding the regexp, I should add this rule to a file (let's call it nginx-401.conf under /etc/fail2ban/filter.d/ that will look like
[Definition]
failregex = ^<HOST> -.* 401
ignoreregex =

and in jail.conf
[nginx-401]
enabled = true
action = iptables-multiport[name=NoProxy, port="http,https"] # no idea of this, copied from somewhere else. what should I put here?
filter = nginx-401 # should be the file name
logpath = /var/log/nginx*/*access*.log
maxretry = 100 # my limit
bantime  = 3600 # 1 hour

Here I don't really have idea of what action should be and if the rest is set up correctly.
Answer: Login dialog page itself is returned with 401 code.
Failed logins are logged with syntax:
<host> - <user> [06/Jun/2018:11:18:55 +0300] "GET / HTTP/1.1" 401 ...

...where given username is in '<user>' and return code is 401
[Definition]
failregex = ^<HOST> - [^-[ ]+.+HTTP/1.[0-9]" 401
ignoreregex =

This regex will not match login attempts with empty username. In that case the username would be '-' which is inseparable from the login dialog page.
Comment: How would I match a path like /api/1/login
Answer: In the end it seems to work, this is my conf just for reference:
/etc/fail2ban/filter.d/wrongauth.conf
[Definition]
failregex = ^<HOST> -.* 401
ignoreregex =

in /etc/fail2ban/jail.con
[wrongauth]
enabled = true
filter = wrongauth
action = shorewall
    %(mta)s-whois-lines[name=%(__name__)s, dest="%(destemail)s", logpath=%(logpath)s, chain="%(chain)s", sendername="%(sendername)s"]
logpath = /var/log/nginx*/*access*.log
banTime = 600 # 10 minutes
findTime = 60
maxretry = 60

As action I use shorewall, and to send email when the ban occurs I had to modifiy the action accordingly to the setting that you see.
Comment: just noticed that the regexp takes anything that has `401` in one of the fields.. so not the rule i was looking for

nginx proxy fail2ban on 401


Updating "Quantity" value from program to the database

Question: i have a problem here.
Here is my case:
I want to update the Quantity value from program based on the value given from program and minus it to the database. For example: i have 100 in Quantity in the database, once i run the program and update the Quantity to 50, the Quantity in the database should be 50.
Here is my problem:
I already can update Quantity value from program to the database, but no matter what's the value that i gave to Quantity in the program, the Quantity value in the database always updating to 0.
Here is the code:
private void UpdateQuantity()
        {
            int index = 0;
            int codeValue = 0;

            List<int> integers = new List<int>();

            foreach (var tb in textBoxCodeContainer)
            {
                if (int.TryParse(tb.Text, out codeValue))
                {
                    integers.Add(codeValue);
                }
            }

            string command = "UPDATE [Seranne] SET [Quantity]= " + newVal + " WHERE [Code] IN(" + string.Join(", ", integers) + ")";

            OleDbConnection conn = new OleDbConnection(connectionString);

            OleDbDataReader dReader;

            OleDbCommand cmd = new OleDbCommand(command, conn);

            conn.Open();

            cmd.Parameters.Add("Quantity", System.Data.OleDb.OleDbType.Integer);

            dReader = cmd.ExecuteReader();

            while(dReader.Read())
            {
                if (textBoxQuantityContainer[index].Value != 0 && textBoxQuantityContainer[index].Value >= Convert.ToDecimal(dReader["Quantity"].ToString()))
                {
                    newVal = Convert.ToDecimal(dReader["Quantity"].ToString()) - textBoxQuantityContainer[index].Value;
                    cmd.ExecuteNonQuery();
                }

                index += 1;
            }

            if (newVal == 0)
            {
                System.Media.SoundPlayer sounds = new System.Media.SoundPlayer(@"C:\Windows\Media\Windows Notify.wav");
                sounds.Play();
                MessageBox.Show("Cannot Update", "Error");
            }

            else
            {
                System.Media.SoundPlayer sound = new System.Media.SoundPlayer(@"C:\Windows\Media\Windows Notify.wav");
                sound.Play();
                MessageBox.Show("Was Updated Successfully", "Success");
            }

            dReader.Close();
            conn.Close();
        }

The newVal value keep appear 0. Because the newVal keep 0, the program show this when i click "Update" button in the program:
if (newVal == 0)
                {
                    System.Media.SoundPlayer sounds = new System.Media.SoundPlayer(@"C:\Windows\Media\Windows Notify.wav");
                    sounds.Play();
                    MessageBox.Show("Cannot Update", "Error");
                }

But when i check in the database, the Quantity value is changed to 0, no matter what is the value that i was given in the program and the newVal keep 0. So, i think the because of newVal is keep appear 0, then the database recognized it and update it based on the newVal, and this code seems not working:
if (textBoxQuantityContainer[index].Value != 0 && textBoxQuantityContainer[index].Value >= Convert.ToDecimal(dReader["Quantity"].ToString()))
                    {
                        newVal = Convert.ToDecimal(dReader["Quantity"].ToString()) - textBoxQuantityContainer[index].Value;
                        cmd.ExecuteNonQuery();
                    }

Could you guys help me out? Thanks in advance!
EDIT Code:
private void UpdateQuantity()
    {
        int index = 0;
        int codeValue = 0;
        string command;

        List<int> integers = new List<int>();

        foreach (var tb in textBoxCodeContainer)
        {
            if (int.TryParse(tb.Text, out codeValue))
            {
                integers.Add(codeValue);
            }
        }

        OleDbConnection conn = new OleDbConnection(connectionString);

        OleDbDataReader dReader;

        OleDbCommand cmd = new OleDbCommand(command, conn); // error: use of unassigned local variable, if i put "string command = '' ", the program will run, but the command not recognized by system, and the error will be: Command text was not set for the command object.

        conn.Open();

        cmd.Parameters.Add("Quantity", System.Data.OleDb.OleDbType.Integer);

        dReader = cmd.ExecuteReader();

        while(dReader.Read())
        {
            if (textBoxQuantityContainer[index].Value != 0 && textBoxQuantityContainer[index].Value >= Convert.ToDecimal(dReader["Quantity"].ToString()))
            {
                newVal = Convert.ToDecimal(dReader["Quantity"].ToString()) - textBoxQuantityContainer[index].Value;
                command = "UPDATE [Seranne] SET [Quantity]= " + newVal + " WHERE [Code] IN(" + string.Join(", ", integers) + ")";
                cmd.ExecuteNonQuery();
            }

            index += 1;
        }

        if (newVal == 0)
        {
            System.Media.SoundPlayer sounds = new System.Media.SoundPlayer(@"C:\Windows\Media\Windows Notify.wav");
            sounds.Play();
            MessageBox.Show("Cannot Update", "Error");
        }

        else
        {
            System.Media.SoundPlayer sound = new System.Media.SoundPlayer(@"C:\Windows\Media\Windows Notify.wav");
            sound.Play();
            MessageBox.Show("Was Updated Successfully", "Success");
        }

        dReader.Close();
        conn.Close();
    }

Answer: change the following like this in while loop,
      newVal = Convert.ToDecimal(dReader["Quantity"].ToString()) - textBoxQuantityContainer[index].Value;
      string command = "UPDATE [Seranne] SET [Quantity]= " + newVal + " WHERE [Code] IN(" + string.Join(", ", integers) + ")";
      cmd.ExecuteNonQuery();

after your while loop , since the 'newVal' is 0 when it was used in query and was updated later on.
Comment: @Furqan: if i do that, it will be messed up, because the `cmd.executeReader();` is on top or before the `string command = ....` and if i put this `OleDbCommand cmd = new OleDbCommand(command, conn);` at top before `string command = ....`, it gave an error: `Command text was not set for the command object.`

Please refer to the question **EDIT Code** sir, thanks
Comment: @FuhansPujiSaputra, I have updated the answer, and moved the query line just before the cmd execution, please check now.
Comment: @Furqan: i don't get you, if i follow exactly like you suggest to me in above, what would i do to this one: `OleDbCommand cmd = new OleDbCommand();`? because that is should be at before the `while loop`? if i filled that command with `command, conn`, and make a variable `string command;` at the top, it should be error, because the command not recognized by the system (since the full command is on below inside the while loop), and if i declare the variable `OleDbCommand cmd` at the top and the full command is inside while loop, the `cmd` in `cmd.ExecuteReader` not recognized. Sorry for arguing
Comment: Sir @Furqan, please refer to the question **EDIT Code** again, i have updated my code in there. Thank you so much and sorry for arguing.
Comment: @FuhansPujiSaputra, is it still updating 0?
Comment: @Furqan: i mean, the updated code that you just gave me, it is not going to work, because of the comment that i was gave to you in the above. So, in other words, the program will not run, because there is an error, and i won't know if the value is still 0 or not since the program not running. Thank you so much


How to use secret manager in creating DMS target endpoint for RDS

Question: How do we create a DMS endpoint for RDS using Terraform by providing the Secret Manager ARN to fetch the credentials? I looked at the documentation but I couldn't find anything.
Answer: There's currently an open feature request for DMS to natively use secrets manager to connect to your RDS instance. This has a linked pull request that initially adds support for PostgreSQL and Oracle RDS instances for now but is currently unreviewed so it's hard to know when that functionality may be released.
If you aren't using automatic secret rotation (or can rerun Terraform after the rotation) and don't mind the password being stored in the state file but still want to use the secrets stored in AWS Secrets Manager then you could have Terraform retrieve the secret from Secrets Manager at apply time and use that to configure the DMS endpoint using the username and password combination instead.
A basic example would look something like this:
<code>data "aws_secretsmanager_secret" "example" {
  name = "example"
}

data "aws_secretsmanager_secret_version" "example" {
  secret_id = data.aws_secretsmanager_secret.example.id
}

resource "aws_dms_endpoint" "example" {
  certificate_arn             = "arn:aws:acm:us-east-1:123456789012:certificate/12345678-1234-1234-1234-123456789012"
  database_name               = "test"
  endpoint_id                 = "test-dms-endpoint-tf"
  endpoint_type               = "source"
  engine_name                 = "aurora"
  extra_connection_attributes = ""
  kms_key_arn                 = "arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012"
  password                    = jsondecode(data.aws_secretsmanager_secret_version.example.secret_string)["password"]
  port                        = 3306
  server_name                 = "test"
  ssl_mode                    = "none"

  tags = {
    Name = "test"
  }

  username = "test"
}
</code>
Comment: Thank you @ydaetskcor for the answer, I will give it a try.


get android phone smsc number programmatically

Question: I am trying to get the SMS center number (smsc) of a phone programmatically in android. Is that possible ? I have tried searching but couldn't find anything?
Answer: As someone pointed out!,
 But here are the steps:
0. Allow these permissions in the manifest file
<code> <uses-permission android:name="android.permission.WRITE_SMS" />
    <uses-permission android:name="android.permission.READ_SMS" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
</code>

Create a broadcast receiver service
You will receive the SMS onReceive in pdu format, then you will need to convert it to SMSMessage.

The SMSMessage has a bunch of properties and methods, one of them is
getServiceCenterAddress() which Returns the address of the SMS service center that relayed this message or null if there is none.
<code>  public class SMSProcessor extends BroadcastReceiver {
// handle the onReceive
  public void onReceive(Context context, Intent intent) {

    Bundle smsBundle = intent.getExtras();
    SmsMessage[] messages = null;
        String strMessage = "";
        clientSMS = new ClientSMS();
        if (smsBundle != null) {
            Object[] pdus = (Object[]) smsBundle.get(SMS_BUNDLE);
            messages = new SmsMessage[pdus.length];
            for (int i = 0; i < messages.length; i++) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    String format = smsBundle.getString("format");
                    messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i], format);
                } else {
                    messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                }

            clientSMS.setSmsc_originating_message(messages[i].getServiceCenterAddress());

  }
   // do stuff with the smsc aka value of getServiceCenterAddress()
}
</code>
Don't forget to register the Service in the Manifest file too
<code> <receiver
            android:name=".controllers.SMSProcessor"
            android:exported="true">
            <intent-filter android:priority="999">
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
            </intent-filter>
        </receiver>
</code>
Note: the export = true in order to listen for system wide services
and we set high priority for good reasons.
Comment: that's something different from the question asked, above. The question was how to get SMSC id/phone for incoming SMS in android phone.
Comment: What about the user and password, is there a way to get them?
Comment: which password and user? can you be specific
Comment: I can connect to an SMSC server using its ip, user and password, using this project for example: https://github.com/delhee/SimpleSMSTransmitter.git . Or maybe I got it wrong?
Answer: You can go in the android documentation and use the getServiceCenterAdress() method.
(android.telephony.SmsMessage)


Any equivalent of * style in Bash for acting on mutliple files NOT matching the same pattern

Question: I'm looking to iterate a script over all files in the present working directory without iterating over scripts (so any extension .py). I was prevously using this
for fileName in os.listdir('.'):
    if fileName != 'autocorrelation1.py':
        with open(fileName, "r") as input:

        REST OF SCRIPT HERE

Which worked when I only had the one script autocorrelation.py in the folder, but now I have a few python scripts I was wondering if there were a bash-style equivalent of * for example
for fileName in os.listdir('.'):
    if fileName != *'.py':
        with open(fileName, "r") as input:

        REST OF SCRIPT HERE

I guess I am being lazy and could do it in another line of code but was just wondering if anyone knew a more fun way!
Comment: small stylistic point: open() defaults to `r` so you could leave it off if you liked.
Answer: I recommend using the fnmatch module:
for fileName in os.listdir('.'):
    if not fnmatch.fnmatch(fileName, '*.py'):
        print fileName

The glob module could help you find matching files, if that was what you wanted:
for fileName in glob.glob('*.py'):
    print fileName

Comment: `glob` is the way to go here if we just want python files. Note that the `iglob` version is probably better since that returns an iterator.
Answer: In this particular case, the easiest solution is
if not file_name.endswith(".py"):

An alternative is
if not fnmatch.fnmatch(file_name, "*.py"):

Answer: Use glob with wildcards to check a set (or subset) of files and endswith() to filter .py files.
e.g.,
import glob

for fn in glob.glob('*'):  # specify set of files to check
   if not fn.endswith('.py'):
      print(fn)

Code updated in accordance with updated/clarified question.
This Python Module of the Week has more examples using glob
Comment: Downvotes without explanation don't help ***anyone*** (OP, SO or me). How does `glob` not apply here? I'm happy to correct omissions or improve the answer if errors are pointed out. The currently highest rated answer (posted at the same time) uses `glob` in the same manner.
Comment: @DonCallisto Yes, makes no sense and without *any* reasons *serves absolutely no purpose*. I guess it's easy when you can stay anonymous.
Answer: Besides the glob module, I'd suggest looking at these generators. Specifically this one:
# genfind.py
#
# A function that generates files that match a given filename pattern

import os
import fnmatch

def gen_find(filepat,top):
    for path, dirlist, filelist in os.walk(top):
        for name in fnmatch.filter(filelist,filepat):
            yield os.path.join(path,name)

# Example use

if __name__ == '__main__':
    lognames = gen_find("access-log*","www")
    for name in lognames:
        print name

Answer: Use re module, you can find it here
re.search('^.*py$',str(yourFileName))

And this is the output:
>>> import re
>>>
>>> a = re.search('^.*py$','prova')
>>> a
>>> a = re.search('^.*py$','prova.py')
>>> a
<_sre.SRE_Match object at 0x2b09559c1760>

Comment: Downvotes should be reserved for incorrect answer or answers that do not apply to OP's question, otherwise it seems petty.
Comment: That's right. And besides, in similiar contexts, REs and knowledge about them can be very useful.
Comment: If I had to guess: there is no benefit from using `re` over the other solutions. REs are quite expensive...
Comment: @Levon i agree with you, but evidently someone thinks differently


Non null relationships in primary constructor of entity

Question: I'm creating application with Spring Data Neo4j and Kotlin. I use standard kotlin way to declare entities (class with primary constructor). Everything worked fine until I wanted to create simple, one-to-many and mandatory relationship between my entities. When I'm calling .findAll() on my repository I get Parameter specified as non-null is null: method ...model.Campaign.<init>, parameter client.
I tried to call .findAll(depth = 1) to load related entities to my entity but that didn't help.
@NodeEntity
class User(var name: String)
{
    @Id @GeneratedValue
    var id: Long? = null
}

@NodeEntity
class Campaign(
    var name: String,
    @Relationship(type = "CLIENT", direction = Relationship.OUTGOING)
    var client: User)
{
    @Id @GeneratedValue
    var id: Long? = null
}

interface CampaignRepository : Neo4jRepository<Campaign, Long>

//...

campaignRepository.save(Campaign("C1", user))

campaignRespository.findAll()

Of course, I can just declare var client: User? as nullable and everything is fine. But, since in my model I will have both mandatory and optional relationships I want to know if there's a way to overcome this.
Comment: Are you sure that all the campaigns you actually fetched have a client?
Comment: in my test case I call `campaignRepository.deleteAll()` just before inserting this
Comment: so, there's no chance that some other campaign is trying to map to non-null field
Comment: Since the `client` is a `var`, maybe you somehow can use `lateinit` to fix it?
Comment: in kotlin you cannot use `lateinit` on primary constructor parameters
Comment: No, you would have to remove it from the constructor. Maybe Spring Data Neo4J can set the property with a setter or something (ref the "somehow" in my last comment)?
Comment: but, how i can place non-nullable property without initializer? if it's non nullable I have to initialize it in primary constructor
Comment: @kubawar You don't have to in initialize it in the primary constructor if the property is `lateinit`.
Comment: i found a solution based on your suggestions but it's not very elegant. i'll post it as an answer but if you have any other ideas, please publish them
Answer: I found a solution, but not very elegant:
@NodeEntity
class Campaign(
    var name: String,
    client: User?)
{
    @Id @GeneratedValue
    var id: Long? = null

    @Relationship(type = "CLIENT", direction = Relationship.OUTGOING)
    lateinit var client: User

    init
    {
        client?.let { this.client = it }
    }
}

Comment: There's an semi-official workaround to this issue available [here](https://jira.spring.io/browse/DATAGRAPH-1148?focusedCommentId=182284&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-182284). Quite a lot of extra code but does do the job


Is there a way to force IE to render in IE8 standards OR HIGHER?

Question: I know that to force IE to render in ie8, use:
<meta http-equiv="X-UA-Compatible" content="IE=8" />

But is there a way to force IE to render either ie8 OR ie9?
Answer: This:
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />

will render in the highest version available, without trying to emulate an earlier version, if that's what you meant.
Comment: @yaojiang: Well yes, but there's no `meta` tag to make IE7 behave like IE8.  :-)
Comment: i guess with this i might run into some problems where folks still use <ie8!? no?
Comment: im happy my company wont support <ie8 :)
Answer: As per http://msdn.microsoft.com/en-ca/library/jj676915%28v=vs.85%29.aspx
... content="IE=8,9" />

Comment: a quick question: if i put "ie=8,9,edge" would this mean "try to render 8 first then 9 then the latest"? or will it just use edge and render using the latest version whichever it may be?
Comment: the docs state that IE will pick the HIGHESt supported rendering engine listed in the allowed UA.s. e.g IE10 would chose 9, since it supports that, but IE8 would only use 8, because it couldn't possibly understand 9.


Additional parameters for devise model on sign up

Question: I am using Devise for my users in my rails app. When people sign up its only their email and password. How do I have access to the controller to permit more param such as first name and last name?
Thank you
Answer: You should add the parameters to the devise_parameter_sanitizer for sign_up
This can be done in your application_controller.rb
class ApplicationController < ActionController::Base
  before_action :configure_permitted_parameters, if: :devise_controller?

  protected

  def configure_permitted_parameters
    devise_parameter_sanitizer.for(:sign_up) << :first_name
  end
end

or configure the whole set of parameters using
def configure_permitted_parameters
  devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:password, :password_confirmation, :email, :first_name, :last_name) }
end

Another way is to create a class that inherits from Devise::ParameterSanitizer
class User::ParameterSanitizer < Devise::ParameterSanitizer
  def sign_up
    default_params.permit(:password, :password_confirmation, :email, :first_name, :last_name)
  end
end

Then in your application_controller.rb
class ApplicationController < ActionController::Base
  protected

  def devise_parameter_sanitizer
    User::ParameterSanitizer.new(User, :user, params)
  end
end


Is it possible to get a list of running processes with a Cloudwatch Alarm?

Question: We have an EC2 instance (Ubuntu) that has a few java-based applications and lately we're getting hit with high CPU utilization spikes that trigger one of our Cloudwatch alarms.  By the time we get into the server to look at the cpu utilization, things have calmed down.
What we'd love to see in one of the alarm emails is a list of running processes and their cpu utilization(%) at the time of the alarm.  Is this even possible?
Answer: I suggest you to try using process accounting and run atop to collect system data snapshots every 10 min (default) or reduce 5 min if you should need better resolution.
apt-get install atop acct
Then you can easily check what was going on at some point using syntax like
atop -r atop.log.file -b 00:00 -e 00:05
example above will show you what was going on in system usage snapshot between 00:00 and 00:05
Answer: I don't have experience doing anything similar, but in theory, it's possible to do it with existing building blocks:
CloudWatch -> SNS -> HTTP/HTTPS -> homebrew webapp -> collect data and email it

Setup your CloudWatch alarm so that it publishes an SNS message to a topic when it goes off.
Have a webapp running on your EC2 instance which, when a particular address is hit, collects the list of running processes and emails it.
Add a subscription to the SNS topic with the webapp's endpoint. You can either choose HTTP or HTTPS as the protocol.

You can combine this with the suggestion to use atop and configure your webapp to send the recent N-minute outputs.
Answer: To answer your question no. You cannot configure CloudWatch to list the processes on your server whenever a threshold is reached. You'd have to use some other software to accomplish this. CloudWatch only records metrics, for example if you wanted to know how many processes were running then you could configure CloudWatch to monitor that.


Generate password hash

Question: I have an external application written in VB.NET that needs to add user accounts to a drupal database.
We tried posting to the /user/register but something is funky with that code and it is not working. I also considered using a RESTful API plugin but that has proven to be more work than we are capable of delivering on short notice.
Just when I figured we could:

Add a value to sequences table
Use that previous value as ID of next user

We now discover that we need some fancy smancy hashed password. I look into the code and see D7 uses sha512 but also some hashing salt -- which again is yet another drupal method which accepts the number or iterations to hash (or something to that effect).
If the VB app uses a sha512 on a password will this suffice with Drupal? Will uses be able to login?
Tips, comments, etc more than welcome :)
Alex
Answer: No - a simple sha512 wouldn't be the same because its lacking the "salt" added by Drupal that prevents the "ability to use pre-hashed lists of candidate passwords" against your database (among other things). Its a security improvement over D5/D6 where a simple md5 update query could reset a user's password.
You might get more mileage out of connecting to the password-hash.sh script (in the scripts folder of your Drupal installation) in your VB script using whatever the equivalent to PHP exec() is in VB..
Comment: That could work actually...but VB apps are running on different computers -- not always within our network so short of installing SSH...hmmmm

What we have concluded thus far is we can add records without passwords or using a known password and forcing new registrants to change password on login
Answer: I believe that you'd need to be SHA512 hashing the password WITH the same style salt(s) as used on the Drupal instance.
My reasoning is that Drupal uses the salt when checking the validity of passwords and if you're saving unsalted SHA512 passwords they won't decode correctly when Drupal uses the Salt.
It's worth a try certainly however you're right in your own deduction that using an API of some form would be a better method.
You should start by following the password creation process in the includes/password.inc file.
You may be able to make use of the password_hash.sh script in the Scripts folder to perform the heavy lifting or to get ideas on how to implement this.
Comment: Adding to sequences and users seems to work so far and has not broken any code as of yet (wait 3 weeks :p)

Calling any Drupal API from VB.NET is far to complicated and unlikely as the D7 instance is running on a different Windows server -- at least not Linux :)

Generate password hash


How to write a list to text file with index in python

Question: Hi I have already written a code which will write a list to text file based on the index. I would like to add row numbers for each element.
with open('C://path/riskcontent.txt', 'w') as file_handler:
for item in content:
    file_handler.write("{}\n\n".format(item))

Output:
sentence
sentence
sentence

My desired output is:
1. sentence
2. sentence
3. sentence

How will I be able to add the indexing. Many thanks!
Answer: The fastest solution that jumps into mind:
with open('C://path/riskcontent.txt', 'w') as file_handler:
    index = 1
    for item in content:
        file_handler.write("{}. {}\n\n".format(index, item))
        index += 1

A bit more Pythonic way is to just use enumerate function:
with open('C://path/riskcontent.txt', 'w') as file_handler:
    for index, item in enumerate(content):
        file_handler.write("{}. {}\n\n".format(index + 1, item))

The +1 is there to adjust for the 0 based indexing.
Comment: perfect thanks so much! I will accept the answer as soon as it is available


Dúvida função def com entrada em modo tuple

Question: Bom pessoa eu tenho o seguinte código:
<code>    def tuplas(x):

        return x[::2]

tuplas(('Hello', 'World', 'estamos', 'vivos'))
</code>
Este código vai funcionar perfeitamente, porém se eu retirar os parênteses da minha tupla, obviamente o python vai dar error:
<code>TypeError: tuplas() takes 1 positional argument but 4 were given
</code>
Obviamente devido há eu ter definido apenas um argumento na função, é na verdade claro eu teria que ter inserido um argumento para cada item da tupla. Eu que inserindo os dados em modo string "Hello World estamos vivos" é dando um split terei sucesso mais a saída será como string e não uma tupla.
A dúvida é possível eu inserir meu dados na forma de tupla não colocando os parênteses ex: 'Hello', 'World', 'estamos', 'vivos' com apenas um argumento na função def tupla(x), não me questionando para eu colocar os outros argumentos é esta saída for na forma de tupla mesmo.
a função seria a seguinte:
<code>    def tuplas(x):

        return x[::2]

tuplas('Hello', 'World', 'estamos', 'vivos') # desse modo da error
</code>
Ou não teria como, eu teria que colocar os parênteses para o python reconhecer isso como tupla.
Espero ter sido claro.
Answer: Existe uma sintaxe especial que permite a você receber um número variável de informações em uma função:
<code>>>> def tuplas(*args):
...     return args[::2]
...
>>> tuplas('Hello', 'World', 'estamos', 'vivos')
('Hello', 'estamos')
</code>
Comment: Perfeito @marcelo-theodoro funcional 100%


ImageButton getting bigger and bigger

Question: I use glide to load an image in an ImageButton view. Clicking on the button opens the camera and the picture taken goes on the Button.
I'm facing a rather strange problem, at every picture taken, the image on the button become bigger..
Do you have an idea why ?
Some code might help :
<code>// I use this to update the ImageButton
RequestManager glide = Glide.with(this);
glide.clear(mLeftTopImageButton);
glide.load(file.getAbsolutePath()).into(mLeftTopImageButton);
</code>
On the xml file :
<code><LinearLayout
    android:orientation="vertical"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginBottom="12dp"
    android:layout_weight="1" >
    <ImageButton
        android:background="?android:colorBackground"
        android:id="@+id/button1_image"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@android:drawable/ic_menu_camera" />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="12sp"
        android:textStyle="bold"
        android:gravity="center_horizontal"
        android:text="Button1"/>
 </LinearLayout>
</code>
edit:
Here is an exemple in image

Thanks,
Comment: Bigger how? Height, width or both? Does `ImageView` gets bigger or just image?
Comment: Based on the image size, it will increase/decrease the ImageButton dimensions. So try to fix the dimensions of the ImageButton if you want to make look of images consistent.
Comment: The width should be fixed already by the `LinearLayout` weight right ?
I will add 2 screenshots showing the problem
Comment: Seems like it's because of different height of Images, see 2nd ss's Left top View and Right top View, First (left) has less height 2nd one has more height, Width also changes according to height and as you don't have the fixed height, this is happening. In short, try fixing the Height instead of Wrap Content.
Comment: Okay thanks it worked, but I still think it's strange that the height of pictures changes..
Thanks anyway (:
Answer: As @"Lalit Singh Fauzdar" said it was enough to fix the height in order to prevent this behavior.
Comment: Glad to see it.

ImageButton getting bigger and bigger


RibbonCheckBox alignment in a RibbonGroup

Question: <code><RibbonWindow x:Class="xxx.yyy"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
...
    <Ribbon x:Name="mainRibbon" Grid.Row="0" >
...
        <RibbonTab Name="ComparisonTab" HorizontalContentAlignment="Left" Header="Comparison" >
            <!--<StackPanel Orientation="Vertical" HorizontalAlignment="Left">-->
            <RibbonGroup HorizontalContentAlignment="Left" Header="Images" >
                <RibbonCheckBox HorizontalAlignment="Left" Width="200" IsChecked="{Binding CompInfo1Check}" Label="{Binding CompInfo1Text}" />
                <RibbonCheckBox HorizontalAlignment="Left" Width="200" IsChecked="{Binding CompInfo2Check}" Label="{Binding CompInfo2Text}" />
                <RibbonCheckBox HorizontalAlignment="Left" Width="200" IsChecked="{Binding CompInfo3Check}" Label="{Binding CompInfo3Text}" />
            </RibbonGroup>
            <!--</StackPanel>-->
        </RibbonTab>
</code>
I have some checkboxes with a dynamic text (labels) and I want to have them left aligned within a ribbon group.
I've tried every imaginable combination of Horizontal(Content)Alignment on them and on their parents. I tried to put them into a container (StackPanel, Grid). I even tried to set a label as a separate element.
The checkboxes stubbornly remain centered within a ribbon group. How do I align them horizontally to the left?
Comment: This is probably something hardcoded into the Ribbon.
Answer: I've found a workaround in using standard check boxes inside a ribbon. There is no problem with their alignment. They could be styled to look as the ribbon check boxes, if required.
So, the modified xaml is:
<code>        <RibbonTab Name="ComparisonTab" HorizontalContentAlignment="Left" Header="Comparison" >
            <RibbonGroup Header="Images" >
                <StackPanel Orientation="Vertical" HorizontalAlignment="Left">
                    <CheckBox Height="25" IsChecked="{Binding CompInfo1Check}" Content="{Binding CompInfo1Text}" />
                    <CheckBox Height="25" IsChecked="{Binding CompInfo2Check}" Content="{Binding CompInfo2Text}" />
                    <CheckBox Height="25" IsChecked="{Binding CompInfo3Check}" Content="{Binding CompInfo3Text}" />
                </StackPanel>
            </RibbonGroup>
        </RibbonTab>
</code>
EDIT
Probably a better way is to use a grid, RibbonCheckBox without a label and a TextBlock instead.
Explained here.


Send Email to multiple users in an advanced Java loop

Question: I have following code:
for (User user : users) {
    MailService mserv = new MailService();
    mserv.sendPasswordResetMail(user, null);
}

I am using an advanced for loop, so Is it viable to create multiple MailService objects? Is it possible that I only create one MailService object and can send email to multiple users, code:
MailService mserv = new MailService();
for (User user : users) {
    mserv.sendPasswordResetMail(user, null);
}

What should I do?
Comment: By advanced you mean enhanced?
Comment: *What should I do?* -- You should [edit] your post to ask a more concrete question.  Are you trying to ask something about enhanced for loops, or about re-using a `MailService` object?
Comment: Why wouldn't it be possible? Also, why not just try it yourself and find out?
Answer: Yes you should be able to iterate only the list of users & send mails. No need to create service objects in loop. Why don't you use Spring's DI for Service layer?


Count how many times a node is referenced

Question: I have a content type: classroom
I have another content type: lesson
Lesson nodes have an entity reference field (field_classroom) that reference classrooms.
I want to create a view that outputs a table like this:

Classroom
Number of lessons

Leicester Square
5

Piccadilly Circus
8

London Bridge
0

So, there are five lesson nodes that reference the "Leicester Square" classroom (all the classrooms are named after places in London), 8 that reference the classroom named Piccadilly Circus, and 0 lesson nodes referencing London Bridge.
Is there a way to achieve this in views?
I'm playing around with relationships and aggregation but I can't get it to work.
Answer: Silly mistake. I had the relationship the wrong way round. Now it's working perfectly. These are the steps:
1.) Create a relationship: Content using field_classroom (not content referenced from field_classroom)
2.) Enable aggregation
3.) Add a field: field_classroom
4.) Use the relationship
5.) Set aggregation on the field to COUNT
And it works!


Rounding in bitwise shift

Question: This is an excerpt from the article on wikipedia https://en.wikipedia.org/wiki/Arithmetic_shift:

Shifting right by n bits on a two's complement signed binary number
  has the effect of dividing it by 2^n, but it always rounds down
  (towards negative infinity). This is different from the way rounding
  is usually done in signed integer division (which rounds towards 0).

Can someone explain what is meant by rounding towards negative infinity and rounding towards zero (and how they differ) and give examples?
What I've noticed in C: -10 >> 4 = -1 because -10 = -1*16 + 6 but -10 / 16 = 0 because -10 = 0*16 - 10 (which is the same way % works, it gives negative remainder for negative numbers in C). I don't know if this is related to the text, but wanted to give info on what I know and don't know.
Comment: An example: (-1)/2 = 0 (rounded towards 0), -1 (rounded towards negative infinity)
Comment: I am not sure where you are stuck with distinguishing between the two rounding modes. When the result is between two integers, simply choose the one indicated by the rounding mode, i.e. pick the closest integer in the direction indicated.
Comment: "Here" meaning what in particular? Another example: (-13)/4 = -3 (rounded towards zero), -4 (rounded towards negative infinity). Please clarify (in the question) what specifically you find confusing about the rounding modes. Without that it would be difficult to provide an answer because the naming seems self-explanatory.
Comment: [there are multiple types of rounding](https://en.wikipedia.org/wiki/Rounding#Rounding_to_integer): round toward zero, away from zero, to +inf, to -inf...
Comment: This is the same as my example, right? -1 = 0*2 -1 and also -1 = -1*2 +1.
Comment: If I understand correctly, the result here will always be either 0 or -1 right?
Comment: Now it's clear. Thanks for the explanation.
Answer: At school I learned all numbers from 1 to 1.499[...] will round to 1 and thus from 1.5 to 1.999[...] will round to 2.
Rounding towards 0 must be understood as rounding the result to the next nearest to zero integer. So all numbers from 1 to 1.999[...] will round to 1 and all numbers from -1.999[...] to -1 will round to -1.
With rounding towards minus infinite you will round the result to the next nearest to minus infinite integer. So all numbers from 1 to 1.999[...] will round to 1 as before but all numbers from -2 to -1.000[...]1 will round to -2.
About the behavior of right shifting negative values it may depend of the language but in C, this is dangerous because implementation defined as stated in section 6.5.7 of C standard

The result of E1 >> E2 is E1 right-shifted E2 bit positions. If E1 has an unsigned type
  or if E1 has a signed type and a nonnegative value, the value of the result is the integral
  part of the quotient of E1 / 2E2. If E1 has a signed type and a negative value, the
  resulting value is implementation-defined.
Answer: its mostly because any negative value when using arithmetic shift right with enough shift value it will always give -1 as an answer because arithmetic shift right keeps the sign bit and 0b11111111 is -1(in a byte) and 0b11110110 is -10 and the most significant zero is at 4 for -10 so if you arithmetic shift it that much it'll default to -1 or if the value is positive it'll default to 0

Rounding in bitwise shift


ethtool error for limiting interface speed

Question: i am limiting my bandwidth using ethtool and i used this command:
sudo ethtool -s eth2 speed 500
But i got error message:
Cannot advertise speed 500
i tried adding duplex half
               duplex full
               autoneg off
               autoneg 0n
i still get this message and i can't find the cause of this problem, any idea?
note im on ubuntu machine, and my eth2 is originally 1G .
Comment: ethtool changes the *link* speed, which, for your port, probably has valid speeds of 10/100/1000 mbps. ethtool isn't the tool you are looking for
Comment: See: http://unix.stackexchange.com/questions/28198/how-to-limit-network-bandwidth  You probably should be looking at TC, or something else.
Answer: The ethtool does not work as a bandwidth limiter for your NICs, that parameter just sets the NIC speed that will be advertised as capable of, and you cant set an arbitrary value on that parameter and expect it to work. It expects one (or a combination of) of a very specific list of possible values, which are correlated to the duplex mode setting. From the man page of ethtool:
<code>advertise N
              Sets  the  speed  and duplex advertised by autonegotiation. The
              argument is a hexidecimal value using one or a combination of
              the following values:
              0x001    10 Half
              0x002    10 Full
              0x004    100 Half
              0x008    100 Full
              0x010    1000 Half(not supported by IEEE standards)
              0x020    1000 Full
              0x8000   2500 Full(not supported by IEEE standards)
              0x1000   10000 Full
              0x03F    Auto
</code>
Comment: In addition: you typically can't change the speed and duplex settings  at all for a para-virtualised NIC in VM.


Como rodar todos os meus testes de uma vez?

Question: Como rodar todos os testes unitários de uma vez no flutter?
Cada teste tem somente a opção Run como na imagem:

Então gostaria de saber como rodar todos os meus testes de uma vez sem ter que clicar em cada um.
Answer: [Edit]
Caso seus testes estejam agrupados em diversos caminhos e pastas você precisa obrigatoriamente deixar eles dentro do diretório test do projeto e todos os arquivos devem possuir o sufixo _test.dart.
Com esta configuração feita poderá ir no terminal e simplesmente aplicar o comando referente ao projeto fazendo assim todos os testes programados rodarem:
Projeto Flutter
flutter test

Projeto dart
pub run test

Além disso, existe a possibilidade de você agrupar seus testes e assim rodar todos presentes ali de uma única vez.
Exemplo
Arquivo: test/widget_test.dart
import 'package:flutter_test/flutter_test.dart';

void main() {
  group('Counter', () {
    test('value should start at 0', () {
      expect(Counter().value, 0);
    });

    test('value should be incremented', () {
      final counter = Counter();

      counter.increment();

      expect(counter.value, 1);
    });

    test('value should be decremented', () {
      final counter = Counter();

      counter.decrement();

      expect(counter.value, -1);
    });
  });

  group('Counter 2', () {
    test('value should start at 0', () {
      expect(Counter().value, 0);
    });

    test('value should be incremented', () {
      final counter = Counter();

      counter.increment();

      expect(counter.value, 1);
    });

    test('value should be decremented', () {
      final counter = Counter();

      counter.decrement();

      expect(counter.value, -1);
    });
  });
}

class Counter {
  int value = 0;

  void increment() => value++;

  void decrement() => value--;
}

Para rodar os testes poderá fazer das seguintes formas:

Clicar no Run do grupo desejado;
Clicar na aba Debug do VSCode e iniciar o processo por lá (obs: apenas se utiliza o VSCode para desenvolvimento);
Ir no terminal e rodar o comando flutter test test/widget_test.dart
;

Para maiores detalhes consulte a documentação:
https://flutter.dev/docs/cookbook/testing/unit/introduction
https://pub.dev/packages/test#running-tests
Comment: @rubStackOverflow editei a resposta adicionando o cenário descrito no seu comentário. Se entendi bem o que busca creio que resolverá seu problema.
Comment: Pode até resolver para arquivo único mas no meu caso são vários arquivos separados em diversas pastas.
Answer: Uma alternativa para quem prefere visualizar na aba de teste do visual studio

Editar o arquivo launch.json e adicionar:
{
    "name": "All Tests",
    "type": "dart",
    "request": "launch",
    "program": "test/",
}
Selecionar All Tests, para rodar os teste Crtl+F5


Proper indexation settings for search in large PostgreSQL table

Question: Trying to get search results from database as fast as possible. The problem is, even after creating index for every field that search goes on, results coming back from PostgreSQL server are insanely slow: at least 20 seconds.
Any suggestions?
More details
Here is the sql query:
SELECT COUNT(*)
FROM "Part"
WHERE ("part_no"='aeroflex')
   OR ("msn"='aeroflex')
   OR ("nsn"='aeroflex')
   OR ("name" ILIKE '%aeroflex%')
   OR ("manufacturer" ILIKE '%aeroflex%')
   OR ("mfg_sku"='aeroflex')

And here is the SQL dump of table which consists of 2.8 million rows
-- ----------------------------
--  Table structure for Part
-- ----------------------------
DROP TABLE IF EXISTS "electronic_parts"."Part";
CREATE TABLE "electronic_parts"."Part" (
    "id" int4 NOT NULL DEFAULT nextval('"Part_id_seq"'::regclass),
    "part_no" varchar COLLATE "default",
    "manufacturer" varchar COLLATE "default",
    "description" text COLLATE "default",
    "slug" varchar COLLATE "default",
    "nsn" varchar COLLATE "default",
    "price" numeric,
    "name" varchar COLLATE "default",
    "mfg_sku" varchar COLLATE "default",
    "msn" varchar COLLATE "default"
)
WITH (OIDS=FALSE);
ALTER TABLE "electronic_parts"."Part" OWNER TO "root";

-- ----------------------------
--  Primary key structure for table Part
-- ----------------------------
ALTER TABLE "electronic_parts"."Part" ADD PRIMARY KEY ("id") NOT DEFERRABLE INITIALLY IMMEDIATE;

-- ----------------------------
--  Indexes structure for table Part
-- ----------------------------
CREATE INDEX  "part_i1" ON "electronic_parts"."Part" USING btree(msn COLLATE "default" "pg_catalog"."text_ops" ASC NULLS LAST);
CREATE INDEX  "part_i2" ON "electronic_parts"."Part" USING gin(to_tsvector('english'::regconfig, name::text) "pg_catalog"."tsvector_ops") WITH (FASTUPDATE = YES);
CREATE INDEX  "part_i2" ON "electronic_parts"."Part" USING gin(to_tsvector('english'::regconfig, name::text) "pg_catalog"."tsvector_ops") WITH (FASTUPDATE = YES);
CREATE INDEX  "part_i3" ON "electronic_parts"."Part" USING gin(to_tsvector('english'::regconfig, manufacturer::text) "pg_catalog"."tsvector_ops") WITH (FASTUPDATE = YES);
CREATE INDEX  "part_i3" ON "electronic_parts"."Part" USING gin(to_tsvector('english'::regconfig, manufacturer::text) "pg_catalog"."tsvector_ops") WITH (FASTUPDATE = YES);
CREATE INDEX  "part_i4" ON "electronic_parts"."Part" USING gin(to_tsvector('english'::regconfig, description) "pg_catalog"."tsvector_ops") WITH (FASTUPDATE = YES);
CREATE INDEX  "part_i4" ON "electronic_parts"."Part" USING gin(to_tsvector('english'::regconfig, description) "pg_catalog"."tsvector_ops") WITH (FASTUPDATE = YES);
CREATE UNIQUE INDEX  "part_u1" ON "electronic_parts"."Part" USING btree(part_no COLLATE "default" "pg_catalog"."text_ops" ASC NULLS LAST);
CREATE UNIQUE INDEX  "part_u2" ON "electronic_parts"."Part" USING btree(nsn COLLATE "default" "pg_catalog"."text_ops" ASC NULLS LAST);
CREATE UNIQUE INDEX  "part_u3" ON "electronic_parts"."Part" USING btree(mfg_sku COLLATE "default" "pg_catalog"."text_ops" ASC NULLS LAST);
CREATE UNIQUE INDEX  "part_u4" ON "electronic_parts"."Part" USING btree(slug COLLATE "default" "pg_catalog"."text_ops" ASC NULLS LAST);

Here is the EXPLAIN
https://explain.depesz.com/s/5Lh
System specs
DB: PostgreSQL 9.5.6 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609, 64-bit
OS: Ubuntu 16.04.2 LTS
RAM: 512MB (It's just for development purposes)
There is no load at all on server. Currently testing as 1 user.
Comment: Please always add `EXPLAIN ANALYZE` results of your queries when the question is performance related. -- The standard `text_ops` operator class will not help `LIKE` and `ILIKE` queries, when the pattern is not left anchored (i.e. it should help if you search for `"manufacturer" LIKE 'aeroflex%'` -- notice that the pattern does not start with `%` neither `_`). --   `gin_trgm_ops` or `gist_trgm_ops` of the [`pg_trgm`](https://www.postgresql.org/docs/current/static/pgtrgm.html) module can help you with these `ILIKE` searches.
Comment: Read through the [info link on the postgresql-performance tag](http://stackoverflow.com/tags/postgresql-performance/info). Edit your question, and include those things.
Comment: @MikeSherrill'CatRecall' updated my question. https://explain.depesz.com/s/5Lh
Comment: @pozs explain https://explain.depesz.com/s/5Lh
Comment: @pozs please help me with more details. gin_trgm_ops or gist_trgm_ops which one to select? I'm newbie to postgre. Previous database was MySQL
Comment: @demonoid then the [module's docs](https://www.postgresql.org/docs/current/static/pgtrgm.html#AEN182717) are a good start. -- also, some [general information about GIN vs. GiST here](https://www.postgresql.org/docs/current/static/textsearch-indexes.html) [and here](http://stackoverflow.com/questions/28975517/difference-between-gist-and-gin-index).
Comment: @pozs do you think that everything else is good in my structure?
Comment: @demonoid PostgreSQL might not choose any index because of your query's complexity, but in theory it could (with proper indexes). But this really depends on a lot of things.
Comment: @pozs tried everything you said. updated my question. nothing changed in terms of performancehttps://explain.depesz.com/s/qjRT
Comment: These two conditions probably cause the table scan on Parts: `("name" ILIKE '%aeroflex%')`, `("manufacturer" ILIKE '%aeroflex%')`. You can test by commenting out or removing these two, and running `explain analyze...` again.
Comment: @demonoid you are supposed to add the `gin_trgm_ops` or `gist_trgm_ops` index to speed up the `ILIKE` query, not the FTS (`tsvector_ops`) one. The second link I added is just for comparison of the two.
Answer: Likely, it's the following two parts to your query that are slowing it down: ("name" ILIKE '%aeroflex%') and ("manufacturer" ILIKE '%aeroflex%'). The reason for this, is postgres can't use a regular index with an ilike operator that doesn't start the string (i.e. it can use an index to speed up 'aeroflex%', but not '%aeroflex%'.
Your indexes show that you did some research into this, by creating indexes with to_tsvector, but ilike doesn't use these indexes, instead you need to use the special operator @@ with to_tsquery
To take advantage of to_tsvector indexes you've already created use a where constraint like:
where to_tsvector('english', "name") @@ to_tsquery('english', 'aeroflex')

Alternatively, if you'd prefer to use like and ilike, you can make use of the pgtrm module.
First: Activate the module
CREATE EXTENSION pg_trgm;

Next: Add the index on the columns you want to filter with like or ilike
CREATE INDEX part_name_trigram_i ON "Part" USING GIN("name" gin_trgm_ops);

You can find more information on trigrams from the documentation page https://www.postgresql.org/docs/current/static/pgtrgm.html and on natural language search in postgres at https://www.postgresql.org/docs/current/static/datatype-textsearch.html


Convergence of $\sum_{n=1}^\infty \frac{\sin nx }{n}$: why can't we use the M test?

Question:
Why can't we use the  M test for testing the convergence of this series:  $$\sum_{n=1}^\infty \frac{\sin nx }{n}?$$

We have $\frac{\lvert \sin nx \rvert}{n}\leq \frac{1}{n}$ hence the series must be divergent.
Comment: Note that $0\le 1/n$ does not imply $\sum 0$ is divergent
Comment: Also, this series is convergent (for $x \in \mathbb{R}$) by Dirichlet's criterion.
Comment: See https://math.stackexchange.com/questions/1750987/showing-sum-n-0-infty-frac-sinnxn-converges-uniformly for one right way to prove convergence and where the poles (may) happen, https://math.stackexchange.com/q/2016440/115115 for another approach to almost the same problem.
Answer: The $M$-test would go exactly the other way ("thing $\leq$ convergent $\Rightarrow$ convergent"): you need to upper bound the summand by a quantity $M_n$ (independent of $x$) such that $\sum_n M_n$ is absolutely convergent. (To conclude the series of functions is itself uniformly convergent.)
Here, you upper bound it by something that is divergent. So the M-test does not tell you anything -- you cannot conclude anything from this. ("thing $\leq$ divergent $\Rightarrow$ nothing")
As an illustration: consider
$$
\sum_{n=1}^\infty \underbrace{\frac{\sin n x}{ n^2}}_{f_n(x)}
$$
which is a series of functions absolutely convergent. But you can say exactly the same, namely $\lvert f_n(x)\rvert \leq \frac{1}{n}$ for all $x\in\mathbb{R}
$... clearly, since does not imply divergence of $\sum_{n=1}^\infty f_n(x)$.
Answer: I don't know about the Wierstrass M test, but on the contrary, I have used Squeeze theorem.
$-1 \le \sin {nx} \le 1$
$-\frac{1}{n} \le \sin {nx}{n} \le \frac{1}{n}$
$\lim_{n \rightarrow \infty} \frac{1}{n}=\lim_{n \rightarrow \infty} -\frac{1}{n}=0$
Hence by squeeze theorem , $\sum _{n=1}^\infty \frac{\sin{nx}}{n}$ is also convergent since limit is defined.
Comment: "The summand goes to $0$" is not sufficient to argue that the series converges... $\sum_{n} \frac{1}{n}$ diverges, after all.


How to pass object as a parameter in Javascript?

Question: I found a few questions on here relating to my question but didn't exactly get the answer I was looking for. I am wanting to do something like this, similar to what jQuery often does:
createCSS("mystyle.css", {
    media: "screen",
    type: "text/css"
});

I tried this to accomplish what I want but it's not working:
var prop = {
    media: '',
    type: ''
};

function createCSS(href, prop) {
    var anchor = document.createElement("link");
    anchor.setAttribute("href", href);
    anchor.setAttribute("media", prop.media);
    anchor.setAttribute("type", prop.type);

    if(typeof anchor != "undefined") {
        document.getElementsByTagName("head")[0].appendChild( anchor );
    }
}

Now, I know I could just create single multiple parameters like createCSS("mystyle.css", "screen", "text/css"); but I don't like that, the other way looks cooler.
Plenty new to javascript so any help would be very much appreciated!
Comment: Have you tried to just eliminate the var prop = { ... } declaration? And test if everything else works...
Answer: You don't have to declare/initialize var prop. Your function looks fine, just call it passing an object as prop, as in your own example:
createCSS("mystyle.css", {
    media: "screen",
    type: "text/css"
});

If the intention with the var prop part was to avoid assigning undefined to the attributes, you need a little tweak inside the function:
function createCSS(href, prop) {
    prop = (typeof prop !== "object") ? {} : prop;
    prop.media = prop.media || 'screen';  // default media will be screen
    prop.href = prop.href || 'text/css';  // default type will be text/css
    // rest of code
}

Some minor improvements I'd suggest:

Your variable anchor does not contain an anchor () element. Why not call it link?
You don't seem to need the if(typeof anchor != "undefined") conditional. since you're creating the element a few lines above, that variable will never be undefined. You can skip the if and appendChild directly.
Comment: Oh, wow. Okay. I would think `prop.media` and `prop.type` would render undefined. Thanks!
Comment: you can predefine `prop`, but in that case don't forget to include it into the call: `createCSS("mystyle.css", prop)`
Comment: You already had it and didn't know it :). Also: I just added a couple of suggestions that may help you improve your code.
Comment: @Bfavaretto wow! Thanks. I like it. And thanks for letting me know about the unnecessary conditional statement. I found it by sniffing around online and didn't really like the looks of it anyway. Good suggestions, too.
Answer: "I tried this to accomplish what I want but it's not working"
The way you pass your object is fine. Although there are some interesting choices in the function, it does what you are asking. However, have you inspected the link you create? It lacks the rel directive which is a requirement.
You may want to change your function to this:
function createCSS(href, prop) {
 var anchor = document.createElement("link");
 anchor.setAttribute("href", href);
 anchor.setAttribute("media", prop.media);
 anchor.setAttribute("type", prop.type);
 anchor.setAttribute("rel", prop.rel);
 document.getElementsByTagName("head")[0].appendChild( anchor );
}

var prop = {
 media: "screen",
 type: "text/css",
 rel: "stylesheet"
}

createCSS( "mystyle.css", prop );

Comment: @TravisJ Thanks! It actually took me like 10 minutes to figure out why `test.css` wasn't working, and it was because of the `rel`. +1


Discrepancy in using background-color for some css styling

Question: So I am pasting the code here:
<!doctype html>

    <title>Skeleton website</title>

Logo goes here

Link 1

Link 2

Link 3

A pretty standard skeleton for a website, I think!
So here's my question:
Why isn't the background-color: white in the #header styling portion getting applied?
If you notice way up where at the start of the styling section, I have applied 0 margins and padding for all elements unless otherwise specified. After that I made sure to add different background-color attributes to all the different elements on the webpage.
They work just well and perfectly override the * css styling.
However, as far as the header id is concerned, it is having trouble overriding the gray applied to the entire webpage with the white that is specified.
Does anyone know why this might be happened? I am thoroughly confused and honestly a little frustrated. This has got to be a minute detail I am missing out on, but I need a second pair of eyes and a hand to smack my head and point me in the right direction.
Thanks  a ton! Appreciate it a lot!
Cheers.
Answer: It is because you have applied background-color: gray to all the elements. This means the #logo and #controllinks elements have a background colour of gray. As these elements sit inside the header you will not see the background colour of the header.
Instead you should give the body a background colour of gray instead of all elements.
CSS
* {
    margin: 0;
    padding: 0;
}

body {
   background-color: gray;
}

See the codepen here
Comment: This seems to have solved the issue! Thank you so much! Both for the solution and the explanation.
Answer: Your #logo div don't have any specific css and so it is getting *{background-color:grey;} and it covers the #header. If you reduce the size of #logo you can see your #header div with white background
So instead of *{background-color:grey;} give body{background-color:grey;}
Answer: You can use the following modified CSS for #header ::
#header
{
 text-align: center;
 background-color: white;
 float: left;
 width: 100%;
 display: block;
}

And Use:
   *
    {
        margin: 0;
        padding: 0;
    }
  body{
  background-color: gray;
  }


Prove that in a finite monoid each element is invertible

Question: Let $(M,\circ)$ be a finite monoid. Suppose the identity element $e\in M$ is the only idempotent element. Then prove that each element in $M$ has inverse.
How can I prove this?
Comment: Let $a \in M$. Consider the set $\{e, a, a^2, \cdots \}$. Can this set be infinite?
Comment: This set is finite. From this we can say $a^{mn}$ is idempotent for some integers $m,n$, i.e., $a^{mn}\circ a^{mn}=a^{mn}$. Can I show the result from this?
Comment: @Mac If you can show what you say in your comment then you are ready. You are allowed to conclude that $a^{mn}=e$ since $e$ is unique as idempotent. Then $a^{mn-1}$ will serve as inverse of $a$. You could edit the proof of what you say in your comment so that it can be checked by others.
Comment: Duplicate of [A finite Monoid $M$ is a group if and only if it has only one idempotent element](http://math.stackexchange.com/questions/568034/a-finite-monoid-m-is-a-group-if-and-only-if-it-has-only-one-idempotent-element?rq=1)
Answer: Let $a$ be an element of a finite monoid.
Then $n>0$ and $k>0$
exist with $a^{n+k}=a^{n}$, leading to $a^{m+kr}=a^{m}$ for $m\geq n$
and $r\geq0$.
Choose some $r$ such that $kr\geq n$ and note that
$a^{kr}$ is idempotent.
If identity $e$ is unique as idempotent
then $a^{kr}=e$, showing that $a^{kr-1}$ serves as inverse of $a$.


How do I solve a partial derivative $f(x,y)$ where $g(r,\theta)=f(r \cos \theta, r \sin \theta)$?

Question: We are given the following information:

$f(x,y)$ is differentiable.
$g(r, \theta) = f(r \cos \theta, r \sin \theta)$
$f_x(1,1)=-2$ and $f_y(1,1)=3$.

We are told to use the chain rule to find $g_r (\sqrt{2},\pi / 4)$.
Attempt 1:  (INCORRECT)
My first attempt to solve this involved me thinking about the vector created by the points $(1,1,-2)$ and $(1,1,3)$, which is just a straight line. I figure this implies that $x$ and $y$ are constants.
The next step I took was to integrate $f_x$ and $f_y$. Since $f_x(1,1)=-2 \implies f=-2x+c_y$ and $f_y(1,1)=3 \implies 3y+c_x$. Because the partial derivatives are from the same equation, we can say that $f(x,y)=-2x+3y$. Because $f_r=f_x \cos \theta + f_y \sin \theta$, and the partial derivatives are constants, $g_r (\sqrt{2},\pi / 4) = (-2) \cos \dfrac{\pi}{4} + 3 \sin \dfrac{\pi}{4} = \dfrac{\sqrt{2}}{2}$.
Comment: No, this is not right. From the partial derivatives *at a single point*, you can't say what the function $f(x,y)$ is for all $x$ and $y$. You were told to use the chain rule, weren't you, so why don't you try that instead?
Comment: I suppose we have $f:\mathbb R^2\to\mathbb R$ and $g:\mathbb R^2\to\mathbb R$?
Comment: The question doesn't say anything to the contrary, so I'd assume so.
Comment: Are $f_x$ and $f_y$ constant functions?
Comment: I see the error in my reasoning. It could have been any linear (or higher order) combination of variables which add up to 1, like: $\{x^3-x^2+x: x=1\}$
Comment: Based on my notes, I have two equations which I think make sense here:

$f_r=f_x \cos \theta + f_y \sin \theta$ and $ f_\theta = f_y r \cos \theta - f_x r \sin \theta$.

I don't know if $f_x$ or $f_y$ are constant, but I do know they are differentiable which brings credibility to the fact that $f_x(1,1)=-2$ and $f_y(1,1)=3$. It doesn't matter if they are constant, the question is not asking about the partial derivatives.

I think I lack a contextual example for where this applies. Can I get an example of a question in physics or elsewhere?
Comment: Actually, I'd like to clarify that question: what kind of object should I get at the end of the calculation?
Answer: I'll set $\theta=\phi$ for typographical convenience. Now, we have that $g_r=f_r.$ Also, setting $x=r\cos\phi$ and $y=r\sin\phi,$ we have that $$g_r=f_r=f_xx_r+f_yy_r.$$
Also note that when $r=\sqrt 2,\,\phi=π/4,$ we have that $(x,y)=(1,1).$
Can you now complete this?
Answer: Your second attempt is basically correct, but there's a term missing from the left side of your second equation.  This should be
$$
\frac{\partial f}{
\partial x}\cdot\frac{\partial x}{
\partial r}+\frac{\partial f}{
\partial y}\cdot\frac{\partial y}{
\partial r}\ .
$$
Comment: Thanks. I made the change and added it to my answer.
Answer: Second attempt at question, following guidance from the community.
Were given that $\dfrac{\partial f}{\partial x}=-2$ and $\dfrac{\partial f}{\partial y} = 3$
$f_r=f_x \cos \theta + f_y \sin \theta \\
\dfrac{\partial f}{\partial x} \cdot \dfrac{\partial x}{\partial r} + \dfrac{\partial f}{\partial y} \cdot \dfrac{\partial y}{\partial r}=(-2)\left( \cos \dfrac{\pi}{4}\right) + (3) \left( \sin \dfrac{\pi}{4}\right) = \dfrac{\sqrt{2}}{2}$