AWS S3 Java SDK upload fails with "Connection pool shutdown" in Groovy

Question: I am using the Amazon Java SDK (that latest is version 1.11.147 as of this writing) with Groovy (Groovy Version: 2.4.11 JVM: 1.8.0_112 Vendor: Oracle Corporation OS: Mac OS X) to upload files to S3. Using the instructions from Amazon's documentation for a Transfer Manager, I was able to copy contents from one bucket to another. However, uploading always fails. I attempted the the following 3 methods. I have Grapes grab new versions of httpclient and httpcore because of what I read at the this Stack Overflow Post Apache PoolingHttpClientConnectionManager throwing illegal state exception
<code>@Grapes([
  @Grab(group='com.amazonaws', module='aws-java-sdk', version='1.11.147'),
  // https://mvnrepository.com/artifact/org.apache.commons/commons-compress
  @Grab(group='org.apache.commons', module='commons-compress', version='1.13'),
  // https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient
  @Grab(group='org.apache.httpcomponents', module='httpclient', version='4.5.3'),
  // https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore
  @Grab(group='org.apache.httpcomponents', module='httpcore', version='4.4.6')
])

// creds is String saying which ~/.aws/credentials profile to use
def credentials = new ProfileCredentialsProvider(creds)

def s3client  = AmazonS3ClientBuilder.standard().
                withCredentials(credentials).
                withRegion(region).
                build()
def tx = TransferManagerBuilder.standard().
         withS3Client(s3client).
         build()

def config_path = "/path/to/my/root"
def dir = "key_path"
def f = new File("${config_path}/${dir}/")

// Method 1, upload whole directory in one call
def mfu = tx.uploadDirectory(data_bucket, dir, f, true)
mfu.waitForCompletion() // <-- throws exception, w/o this line, just doesn't upload, but script continues

// Method 2, upload each file separately
def ld
ld = { File file ->
  file.listFiles().each { g ->
    if (g.isDirectory()) {
      ld.call(g)
    } else {
      def key = g.toString().substring(config_path_length)
        def fu = tx.upload(data_bucket, key, g)
      def fu = tx.upload(data_bucket, key, g)
      fu.waitForCompletion() // <-- throws exception, w/o this line, just doesn't upload, but script continues
    }
  }
}
ld.call(f)

// Finally Method 3, avoiding TransferManager altogether, and call putObject directly on each file
def ld
ld = { File file ->
  file.listFiles().each { g ->
    if (g.isDirectory()) {
      ld.call(g)
    } else {
      def key = g.toString().substring(config_path_length)
        def fu = tx.upload(data_bucket, key, g)
      s3client.putObject(new PutObjectRequest(data_bucket, key, g)) // <-- throws exception
    }
  }
}
ld.call(f)
</code>
However, no matter which method I try, I always get the following stacktrace:

Caught: java.lang.IllegalStateException: Connection pool shut down
  java.lang.IllegalStateException: Connection pool shut down    at
  org.apache.http.util.Asserts.check(Asserts.java:34)   at
  org.apache.http.pool.AbstractConnPool.lease(AbstractConnPool.java:184)
    at
  org.apache.http.impl.conn.PoolingHttpClientConnectionManager.requestConnection(PoolingHttpClientConnectionManager.java:251)
    at
  com.amazonaws.http.conn.ClientConnectionManagerFactory$Handler.invoke(ClientConnectionManagerFactory.java:76)
    at com.amazonaws.http.conn.$Proxy11.requestConnection(Unknown Source)
    at
  org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:175)
    at
  org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
    at
  org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
    at
  org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
    at
  org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
    at
  com.amazonaws.http.apache.client.impl.SdkHttpClient.execute(SdkHttpClient.java:72)
    at
  com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1190)
    at
  com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1030)
    at
  com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:742)
    at
  com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:716)
    at
  com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:699)
    at
  com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:667)
    at
  com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:649)
    at
  com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:513)
    at
  com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:4221)
    at
  com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:4168)
    at
  com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1718)
    at com.amazonaws.services.s3.AmazonS3$putObject.call(Unknown Source)
  ...

I am unable at this time to confirm whether groovy is using the updated httpcomponent libraries, or if that is the problem. Installed in the 1.8 JDK are httpclient_4.2.6 and httpclient_4.3.5. Any suggestions for how to get unstuck would be greatly appreciated.  Thank you. -Vincent
Answer: I figured it out. the s3client had another TranferManager attached to it elsewhere in the code. when tx.shutdownNow() was called, it closed this TransferManager as well.
Comment: how did you resolve this? I am getting this exception also?
Comment: @shanelee I stopped passing around the TransferManager reference and instead used a new one in each function that transferred s3 files.
Comment: I concur with @VincentJørgensen solution. Had same problem as I was re-using the S3 client within a utility, changing the utility to create a new client each time cleared this right up.
Comment: Same problem here, I was shutting down the transfermanager after downloading, and then tried to use listobject on it


network programming basics, need help to understand addrinfo / sockaddr_in structs usage etc

Question: I started to learn C/C++ network programming but I am stuck at the beginning. I am kinda noob in programming but I understand basic stuff such as C libraries, pointers, structs,  etc. I cannot find well explained information about some details related to addrinfo / sockaddr_in structs. Amount of similar structs is annoying and online tutorials are messy. As additional information I can tell that I am programming on windows, using visual c++ 2010 express. I do not know if the information I already know is correct. I think it works that way:

sockaddr_in is no longer need to be created and filled manually anywhere because the function "getaddrinfo" does that for me, using the information I define manually inside addrinfo, so addrinfo is a thing to replace all sockaddr_in.
seems the HOSTENT struct is useless, as it is used in "gethostbyname" function and that became deprecated because of "getaddrinfo"

Now some questions:
How does introducing of "addrinfo" change usage of common functions - do any functions now take another arguments such as addrinfo instead of sockaddr_in as a part of them?
It seems that old-style programming without addrinfo is more beginner-friendly, I think I want to use sockaddr_in only for now as I only learn and want to make simple stuff, is that a good idea?
Please tell me if my understanding is correct and answer my questions if possible, comments or explanations are welcome.
EDIT
As I did not get direct answers explaining things I do not understand I did keep trying to figure out how it works and I probably understand these things a bit more.
The thing I want to know the most now is role of HOSTENT struct after "gethostbyname" got deprecated because "getaddrinfo" function made it useless. I want to know details because I want to know what I am doing in every part of the code.
Comment: If you're looking to learn in this level of detail, you may want [Stevens](http://www.amazon.com/gp/product/0131411551/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=0131411551&linkCode=as2&tag=kfsorg-20).
Comment: That is not big level of detail in my opinion, I think people who do C++ network programming know how usage of these structs work. I am also looking for confirmation that the information I gathered is correct. People who use getaddrinfo will know the answer for that.
Answer: I'm unfortunately not going to answer your questions, however, I'd totally recommend to read the Beej's Guide, which is a great reference for getting started in a convivial way: http://beej.us/guide/bgnet/
Comment: I did already read that, Beej's guide is old (it encourages to use winsock.h what is ancient library now) and does not describe these structs well enough. I cannot find detailed information and it is hard to progress with such a mess with header usage changes.
Answer: OK , I'm not sure what you are looking for in an answer. So I will attempt to take the general advise route. I completed a project last year and I went down the winsock route and while I'm sure there are any number of new ways I found I liked the winsock / sockaddr_in stuff ( altough I'm by no means a guru at any aspect of programming). I essentially started off with a simple server/ client pair that allowed two people to chat across an ad-hoc network. And I found the sockaddr_in structs intuitive enough to use. If you wanted to start off on a smaller scale you could have the server/client local on one machine by setting the client port as a loopback IP and have your client connect to this socket (either from within the same app via threads or have separate apps for your client and server). Just have your server listen for a connection and send a simple "Success" string or something. I got most of these ideas from a guy I found on youtube (Shocking I know !) Here's a link . Hope this helps. Happy Coding !
Comment: Thanks, you gave me good example for start with detailed description. And answer I am looking for are details about changes caused by really confusing struct "addrinfo" that replaced "sockaddr_in". Beej's guide is the only one mentioning what these structs have in common, and it is hard to find detailed information to understand the differences.
Comment: I only used the sockaddr_in so take this post with a pinch of salt !! At a glance it seems the addrinfo struct is composed of a few more data members than the sockaddr_in structure (including an instance of sockaddr itself..Also describes more about the socket it is associated with e.g TCP or UDP or RAW etc.).Perhaps if you were trawl through some MSDN documentation or a forum buried away somewhere you would strike gold and find someone giving a best used case analysis for these two. In my opinion I would start with the sockaddr_in approach and learn the basics. Hope this helps!
Answer: The Berkeley Socket API is 30 years old (born in 1983). So it's full of a lot of cruft. And the Windows Socket API is a multi-iterated "bsd-ish". Or, to put this another way, you're starting down something of a rabbit hole that you probably don't need to.
If you really want to understand the evolution of the API, you're actually going to have to turn to books - very likely Steven's "Unix Network Programming", and then read material on WinSock porting. But there's no one definitive source because Windows is not developed in transparency, and the last 10 years or so MS have been patchy at keeping their developers well informed (this is a case in point).
But if what you actually want to do is get into the practicalities of moving packets around the network, rather than the minutae of what the involved structures are, you might want to start by looking at a slightly higher level API such as "libevent" (unfortunately, very C like) or "ZeroMQ" or "AMQP" (rabbitmq or Apache qpid).
Comment: I am not looking for evolution of API, but I have troubles to understand these basics as this is complex and hard to understand with changing stuff and new struct using outdated one as part of it, also source codes look not very logical (more like a mess than showing how it works) so I cannot answer by myself and I do not even know how to start coding to test this myself. Also i'd prefer to start from winsock than from alternatives.


LIBDBUSMENU-GLIB-WARNING **: Unable to get session bus: Failed to execute child process "dbus-launch" (No such file or directory) while x-forwarding

Question: I've set up x-forwarding on an Ubuntu 16.04.3 server and although the forwarding works, every time I start a GUI application it reports the following error in the terminal.
(<app-name>:<pid>) LIBDBUSMENU-GLIB-WARNING **: Unable to get session bus: Failed to execute child process "dbus-launch" (No such file or directory)

This is obviously not critical, but it isn't working as it should.
How can I repair this?
Edit I'm mostly trying to start Firefox.
Answer: The solution to this issue was to install 'dbus-x11'.
sudo apt-get install dbus-x11

I came to this solution by looking for similar issues.
I've found Pablo Saratxaga's answer on Serverfault, suggesting a script for a similar issue.
https://serverfault.com/a/673837/409813
I've thought it would be worth to run

export $(dbus-launch)

because this is the main command that the script is starting.
The error message from the output is the following.
The program 'dbus-launch' is currently not installed. You can install it by typing:
apt install dbus-x11

I installed dbus-x11 and x-forwarding started to work without showing an error message.
Comment: dbus-x11 doesn't exist for ubunt 24.04.


Unable run basic script

Question: This issue appears to be happening with every require statement I attempt to use in my ruby script.
How do I get ruby to properly use the gem?
Here is the ruby script:
require_relative 'oga'

handle = File.open("xml_list.xml")
document = Oga.parse_xml(handle)
print document.css("listitem").first
f.close

Here is the output when I run sudo ruby extract_list.rb in terminal:
Ignoring executable-hooks-1.3.2 because its extensions are not built.  Try: gem pristine executable-hooks --version 1.3.2
Ignoring ffi-1.9.6 because its extensions are not built.  Try: gem pristine ffi --version 1.9.6
Ignoring gem-wrappers-1.2.4 because its extensions are not built.  Try: gem pristine gem-wrappers --version 1.2.4
/Users/sparks/.rbenv/versions/2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- ./oga (LoadError)
from /Users/sparks/.rbenv/versions/2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from extract_list.rb:1:in `'

Comment: I have tried running gem pristine for each of the mentioned gems and have tried running gem pristine --all. I still get the same result.
Comment: What is your question?
Comment: How do I resolve the conflicts mentioned in the response and get the oga gem to be included properly?
Answer: Found the source of the problem. I had an old rvm ruby that broke when I upgraded to Yosemite. I had to sudo rvm uninstall all to fix the problem.
Now everything is working properly. :)

Unable run basic script


NodeJS/express: Cache and 304 status code

Question: When I reload a website made with express, I get a blank page with Safari (not with Chrome) because the NodeJS server sends me a 304 status code.
How to solve this?
Of course, this could also be just a problem of Safari, but actually it works on all other websites fine, so it has to be a problem on my NodeJS server, too.
To generate the pages, I'm using Jade with res.render.
Update: It seems like this problem occurs because Safari sends 'cache-control': 'max-age=0' on reload.
Update 2: I now have a workaround, but is there a better solution?
Workaround:
app.get('/:language(' + content.languageSelector + ')/:page', function (req, res)
{
    // Disable caching for content files
    res.header("Cache-Control", "no-cache, no-store, must-revalidate");
    res.header("Pragma", "no-cache");
    res.header("Expires", 0);

    // rendering stuff here…
}

Update 3:
So the complete code part is currently:
app.get('/:language(' + content.languageSelector + ')/:page', pageHandle);

function pageHandle (req, res)
{
    var language = req.params.language;
    var thisPage = content.getPage(req.params.page, language);

    if (thisPage)
    {
        // Disable caching for content files
        res.header("Cache-Control", "no-cache, no-store, must-revalidate");
        res.header("Pragma", "no-cache");
        res.header("Expires", 0);

        res.render(thisPage.file + '_' + language, {
            thisPage : thisPage,
            language: language,
            languages: content.languages,
            navigation: content.navigation,
            footerNavigation: content.footerNavigation,
            currentYear: new Date().getFullYear()
        });
    }
    else
    {
        error404Handling(req, res);
    }
}

Comment: 304 is not a problem. It simply means that your response is not modified and your browser turns to cache to fetch the resource. Can you post the relevant code in which anomaly is happening.
Comment: yes, actually it isn't modified, but Safari empties its cache on CMD + R (reload) and the server only says it didn't change.
Comment: It is related because with 304 the body is not sent and the browser uses its cache, but since there is no cache, you get a blank page
Comment: @AkshatJiwanSharma Any program is developed to be meet the product owner's contract exactly. The product owner is the one who owns the code and pays the money, not some organization that writes papers that nobody cares about. If the contract says "200" then absolutely any status that is not equal to "200" is a bug. When there is a bug I MUST rewrite code until everything is exactly as expected. W3C do not have a say in the matter.
Comment: How is blank page related to 304 status code? Node would also send 304 to other browsers.
Comment: Update 2 with manually set headers to disable caching helped to fix the issue.
Comment: We created this to help hack around it: https://github.com/Dakuan/jumanji
Answer: Easiest solution:
app.disable('etag');

Alternate solution here if you want more control:
http://vlasenko.org/2011/10/12/expressconnect-static-set-last-modified-to-now-to-avoid-304-not-modified/
Comment: Could you explain the "easiest solution" or give a reference on how this affects?
Comment: @SamuelMéndez it disables caching basically, the wiki on etag has a lot of good info https://en.wikipedia.org/wiki/HTTP_ETag
Comment: This makes sense.  I believe the etag was not being recomputed properly because I wasn't setting the the last modified date, as mentioned in vlasenko's link.

My problem went away when I updated my code as follows:

const headers = { 'Last-Modified': (new Date()).toUTCString() };
app.get('/*', (req, res) => {
    res.sendFile(join(DIST_FOLDER + '/index.html'), { headers } );
});
Comment: Worked for me :)
Answer: Try using private browsing in Safari or deleting your entire cache/cookies.
I've had some similar issues using chrome when the browser thought it had the website in its cache but actually had not.
The part of the http request that makes the server respond a 304 is the etag. Seems like Safari is sending the right etag without having the corresponding cache.
Comment: that works for me when I tried to delete entire cache, thanks
Answer: I had the same problem in Safari and Chrome (the only ones I've tested) but I just did something that seems to work, at least I haven't been able to reproduce the problem since I added the solution. What I did was add a metatag to the header with a generated timstamp. Doesn't seem right but it's simple :)
<meta name="304workaround" content="2013-10-24 21:17:23">

Update
P.S
As far as I can tell, the problem disappears when I remove my node proxy (by proxy i mean both express.vhost and http-proxy module), which is weird...
Comment: I also use an Apache proxy, this could be the problem.
My workaround was to just disable caching for content sites with http headers.
Comment: Disabling cache through the headers is definitely the way to go. At first it didn't work for me but now it does. In other words I must've made a mistake somewhere the first time around :)
Answer: As you said, Safari sends Cache-Control: max-age=0 on reload. Express (or more specifically, Express's dependency, node-fresh) considers the cache stale when Cache-Control: no-cache headers are received, but it doesn't do the same for Cache-Control: max-age=0. From what I can tell, it probably should. But I'm not an expert on caching.
The fix is to change (what is currently) line 37 of node-fresh/index.js from
if (cc && cc.indexOf('no-cache') !== -1) return false;

to
if (cc && (cc.indexOf('no-cache') !== -1 ||
  cc.indexOf('max-age=0') !== -1)) return false;

I forked node-fresh and express to include this fix in my project's package.json via npm, you could do the same. Here are my forks, for example:
https://github.com/stratusdata/node-fresh
https://github.com/stratusdata/express#safari-reload-fix
The safari-reload-fix branch is based on the 3.4.7 tag.
Comment: Great work! I see that express 3.5.1 includes your fix via node-fresh 0.2.2.
Comment: Actually, I'm wrong, your fix was reverted and did not actually make it to 0.2.2. Still no fresh/express fix.
Answer: Old question, I know. Disabling the cache facility is not needed and not the best way to manage the problem. By disabling the cache facility the server needs to work harder and generates more traffic. Also the browser and device needs to work harder, especially on mobile devices this could be a problem.
The empty page can be easily solved by using Shift key+reload button at the browser.
The empty page can be a result of:

a bug in your code
while testing you served an empty page (you can't
remember) that is cached by the browser
a bug in Safari (if so,
please report it to Apple and don't try to fix it yourself)

Try first the Shift keyboard key + reload button and see if the problem still exists and review your code.
Answer:
Operating system: Windows
Browser: Chrome

I used Ctrl + F5 keyboard combination. By doing so, instead of reading from cache, I wanted to get a new response. The solution is to do hard refresh the page.
On MDN Web Docs:

"The HTTP 304 Not Modified client redirection response code indicates
that there is no need to retransmit the requested resources. It is an
implicit redirection to a cached resource."
Answer: // just add * in URL

app.get('/api*', (req, res)=>{

// do something

});


How can I make personal notes on the map?

Question: I'd like to be able to add my own notes and comments to locations in Skyrim - for example "There's a bandit leader here whom I couldn't kill yet - come back later to finish the job". How can I do that? Mods are an option.
Answer: There is a mod that allows it indeed, you can download it from here:
http://www.nexusmods.com/skyrim/mods/38731/
The features list:

You can place your own markers with your own, self-written notes attached to them.
Up to 60 custom markers (if you want more, it's easy to add more in Creation Kit).
You can fast travel to your markers.
You can edit and remove your markers.
Works with SkyUi's Location Finder.
First line of your note become a marker name (displayed on the map and in Location Finder).
English and Polish localizations.

As you see, it is only available in English or Polish so this might conflict if your game is in a different language. However, you can instruct Steam to change the language of the game in the game's properties menu.
Comment: @JoethePerson Don't start a rollback war here. Please. @Assylum, do note that the edits in question were valid, and they *were not* removing the link from your post, but instead moving it to within the text of your answer. [like this.](http://gaming.stackexchange.com/a/155178/3129). I'd encourage you to do so yourself, because it really does look better and improve readability. You can do this with the WYSIWIG editor, or, if you'd prefer to know the markdown yourself, it takes the form of `[wordwordswords](http://URLGOESHERE.COM)`.
Comment: @LessPop_MoreFizz I don't like hiding links behind text. Plain and simple. I don't see how this contributes to my answer in any way.
Comment: You realize you can see where a link leads by hovering the cursor over it, right?
Comment: It looks better to have a link instead of a URL in the middle of the post
Comment: @Assylum [here is the editing page](http://gaming.stackexchange.com/help/editing)
Comment: There is need to edit the link out. Thank you. Please refrain from re-editing.
Comment: As per the rules, you are not allowed to re-edit if the author rejected the edit. Therefore I ask you to move on and leave my answer alone. It is a minor edit that is not allowed anyway.
Comment: I guess that's close enough. I though about adding a custom note to each location on the map, but I guess that's not possible.


How to create a data lake from Kafka to Hdfs with Spark - storing in custom directories?

Question: I have an RDD transformed into a dataFrame of the following structure:
+-------------+--------------------+
|          key|               value|
+-------------+--------------------+
|1556110998000|{"eventId":"55108...|
|1556110998000|{"eventId":"558ac...|
|1556110998000|{"eventId":"553c0...|
|1556111001600|{"eventId":"56886...|
|1556111001600|{"eventId":"569ad...|
|1556111001600|{"eventId":"56b34...|
|1556110998000|{"eventId":"55d1b...|
...

Key is a timestamp rounded down to one hour, value is a json String.
What I want is to store the values into different buckets according to the timestamp. So basically I want the structure as follows:
...
/datalake/2019/03/31/03
/datalake/2019/03/31/04
/datalake/2019/03/31/05
...
/datalake/2019/04/25/08
/datalake/2019/04/25/09
...

Storing the actual rdd just with eventsRdd.saveAsTextFile("/datalake"); does not do the trick, as all events end up in one single file. Additionally this file is overwritten in the next "round".
So how would I go about this? I read some articales about partitioning but they didn't really help. I am actually thinking about switching to Kafka Connect and not using Spark at all for this.
Below is some code I tried to store the events (just on local fs for now)
private void saveToDatalake(JavaRDD<E> eventsRdd) {
        JavaPairRDD<Long, String> longEJavaPairRdd = eventsRdd
                .mapToPair(event -> new Tuple2<>(calculateRoundedDownTimestampFromSeconds(event.getTimestamp()), serialize(event)));

        SparkSession sparkSession = SparkSession.builder().appName("Build a DataFrame from Scratch").master("local[*]").getOrCreate();
        StructType dataFrameSchema = DataTypes
                .createStructType(new StructField[]
                        {DataTypes.createStructField("key", DataTypes.LongType, false),
                                DataTypes.createStructField("value", DataTypes.StringType, false),

                        });
        JavaRDD<Row> rowRdd = longEJavaPairRdd.map(pair -> RowFactory.create(pair._1, pair._2));

        Dataset<Row> dataFrame = sparkSession.sqlContext().createDataFrame(rowRdd, dataFrameSchema);

        Dataset<Row> buckets = dataFrame.select("key").dropDuplicates();
        //buckets.show();
        buckets.foreach(bucket -> {
            Dataset<Row> valuesPerBucket = dataFrame.where(dataFrame.col("key").equalTo(bucket)).select("value");
            //valuesPerBucket.show();
            long timestamp = bucket.getLong(0);
            valuesPerBucket.rdd().saveAsTextFile("/data/datalake/" + calculateSubpathFromTimestamp(timestamp));
        });

    }

private String calculateSubpathFromTimestamp(long timestamp) {
        String FORMAT = "yyyy/MM/dd/HH";
        ZoneId zone = ZoneId.systemDefault();
        DateTimeFormatter df = DateTimeFormatter.ofPattern(FORMAT).withZone(zone);
        String time = df.format(Instant.ofEpochMilli(timestamp));
        System.out.println("Formatted Date " + time);
        return time;
    }

Comment: What kind of datalake? Azure? If so then it is possible using Kafka Connect HDFS. I managed to implement Kafka Connect HDFS for Azure Data Lake a couple of weeks ago. It is non-trivial, but you would not have to write any code.
Comment: Have you considered using Kafka Connect HDFS to do this?
Comment: At a high level, you'd have to do `dataFrame.withColumn()` a few times, converting the timestamp to years, months, days. Then you'd use a method like `saveAsTable` instead... Or create the table and `dataFrame.sql("INSERT INTO...")`
Comment: Indeed I am pursuing the Kafka Connect HDFS approach now. So far I managed to read the data from Kafka in Protobuf format and store in HDFS in the right folders (YYYY/MM/DD/HH) in Protobuf format as well. What's left is now to convert / de-serialze the protobuf events into proper json and then storing.

For now HDFS will be sufficient, but later on we will move to S3 and I know there are connectors available as well, so that should not be too big of an issue.
Answer: We got it done by using Kafka Connect HDFS Connector and providing a custom Serializer class to convert Protobuf Messages from Kafka into JSON.


What happens when the Beholder beholds a Drunk Seer who was drunk that night?

Question: What happens when the Beholder beholds a Drunk Seer who was drunk that night? Does he see what they beheld before they blacked out, or does he just see that they were drunk?
Answer: As lore dictates, the Drunk seer checks their target before blacking out and inevitably forgetting what the result of their check was. The same does NOT apply to the Beholder because guess what? THEY WEREN'T DRUNK! So the Beholder can actually find out what the Drunk seer's report is on the night that they get drunk.


How to toggle hide/show a button based on the focus between 2 other HTML inputs?

Question: I have a login section, with I want to achieve something new:
When a user puts the focus on email or password input, the button should show 'LOGIN', When none of them has the focus, the text should be 'NOT A USER YET?'
The problem is I can't handle it properly when email loses focus and password input has the focus right after.

(source: firefoxusercontent.com)

(source: firefoxusercontent.com)
here is what I have tried so far:

The design doesn't matter, just the functionality in js

HTML:
<form action="" method="post">
    <input type="text" name="email" placeholder="Email" style="width: 120px;height:25px;line-height: 1.1;position: absolute;left: 0;top: 0;border-radius: 3px 0 0 0" class="input-xs form-control lg_email no-shadow-on-focus">

    <input type="password" name="password" placeholder="Password" style="width: 120px;height:25px;line-height: 1.1;position: absolute;left: 0;top: 25px;border-radius: 0 0 0 3px" class="input-xs form-control lg_psw no-shadow-on-focus">

    <button type="submit" style="width:80px;text-align: center;font-size: 15px;height:50px;line-height: 25px;border-left: none;background-color: blue;display: none;position: absolute;right: 0;top:0;border-radius: 0" class="btn btn-lg btn-primary bgLogin">LOGIN</button>

    <button class="f-11 btn bgUser btn-primary" style="width:80px;text-decoration: none;height: 50px;position: absolute;right: 0;top:0;border-radius: 0 3px 3px 0">NOT A
 user yet ? </button>

</form>

JS
setInterval(function(){
    if($(".lg_email").is(":focus") || $(".lg_psw").is(":focus")){
        $(".bgLogin").show();
        $(".bgUser").hide();
    }else{
        $(".bgLogin").hide();
        $(".bgUser").show();
    }
},500);

This way, the action wait for a little bit to trigger.
Answer: What about something like:
$(function()
{

    $(".lg_email, .lg_psw").on('focus',function()
    {
       $(".bgLogin").show();
       $(".bgUser").hide();
    });

    $(".lg_email, .lg_psw").on('blur',function()
    {
         $(".bgLogin").hide();
         $(".bgUser").show();
    });
});

This way your using direct events rather than having to use an interval.
Comment: you're missing comma between lg_email and lg_psw
Answer: Here's a solution:
https://jsfiddle.net/mzvarik/f6g8bau5/
Also don't use <form action=""> but just <form>, it used to be buggy years ago, but it's just not needed if it's empty.
Comment: thanks for the advice! and yours works as well, but I will mark the first answer as accepted since both works


How to catch default values after a form was set to default in Drupal 7

Question: My form function
function my_module_settings($form, $form_state) {
   $form['my_textfield'] = array(
    '#type' => 'textfield',
    '#title' => 'Title',
    '#default_value' => variable_get('my_textfield', 'demo'),
    );

     $form['actions']['reset'] = array(
      '#type' => 'submit',
      '#value' => t('Reset to defaults'),
      '#submit' => array('my_module_settings_reset'),
    );

    $form['#submit'][] = 'my_module_settings_submit';
    return system_settings_form($form);
  }

  function my_module_settings_submit () {
    // Do something on sumbit.
  }

  // My reset function
  function my_module_settings_reset($form, &$form_state) {

  form_state_values_clean($form_state);

  // print_r($form_state['values']);
  foreach ($form_state['values'] as $key => $value) {
    variable_del($key);
   }

   // I need to get $default right after "Reset" button pressed
   $var = send_default_values($default);

}

So, my_module_settings($form, $form_state) - is a standart module settings form. I added "Reset" button. I'd like to get an array of all default values ('demo' in my case) upon submission and pass it to the send_default_values($default) function. $form_state['values'] contains an old field value right after "Reset" pressed, but actually the form has been changed to its default state.
Ideas, suggestions?
Answer: The system_settings_form adds the reset button by default so you don't have to do that. Also, it restores the default values automatically when pressed. Moreover, I don't think you need another submit function because the system_settings_form will save the values in the variable table in the database.
EDIT: apparently in D7 they removed that functionality
Comment: I'm not sure that system settings form has reset button by default. Look at this http://drupal.org/project/settings_reset_button. The button was removed in drupal 7. Anyway, +1 for your replay
Comment: sorry, my bad. I had no idea they removed this functionality in D7


Identify this metal slider bracket?

Question: I am doing a DIY project at home and came across this sliding metal bracket and plastic plate assembly. I have no idea where it came from but I think probably IKEA, although it could be anywhere. But it seems to actually do exactly what I need - that is if I could figure out how to mount it.
I have been puzzling over this for an hour with no instructions but I cannot figure out how the metal part clamps to the plastic part, and I don't have any instructions. I have also been googling things like "metal sliding bracket", "metal keyboard sliding bracket", throwing in works like "IKEA" but I cannot find this precise part.
I don't know if I am missing another piece which holds it all together. Can anybody identify this thing so I can find an assembly guide or something?
Comment: What is the size of it
Comment: Can you tell of any way of the plastic and metal pieces fit together?  Screw holes matching up, or posts/holes fitting together.  Any piece of the plastic adjustable/moves?
Answer: The metal slider looks like one side of a drawer slide.  The metal pin fits into the side of the drawer.  No idea about the plastic part.
Most IKEA parts are specialized to the configuration of the specific furniture you bought, and may be missing parts to make them more general.
Answer: First guess
It is a sliding curtain rood for vertical blinds.
The plastic part gets mounted on the wall,or inside the window opening.
The rood snaps in to it.
Comment: Seems too short for vertical blinds.  More of the length of a drawer slide, maybe one where the drawer clips in/on.

Identify this metal slider bracket?


JavaScript: recursion inside anonymous promise resolver functions

Question: I have a function that return a promise. (foo in this example)
I try to call this function inside their resolve function that was declared as anonymous.
I have tried with this but this not work.
my code looks like this
var foo = function(boo) {
    /* .... */
    return deferred.promise;
};

var bar = 42;

foo(bar).then(function() {
    foo(bar--).then(this); //"this" don't work
});

What am I doing wrong?
Thanks
Comment: Are you trying to call `foo` or the anonymous function?
Comment: foo inside anonymous function and then(anonymous) with this anonymous function. I try to retrieve anonymous function inside it.
Answer: The simplest way is to name the anonymous function
foo(bar).then(function fn() {
    foo(bar--).then(fn);
});

You can also declare the function separately
function fn() {
    foo(bar--).then(fn);
}
foo(bar).then(fn);

Comment: Note this won't wait for anything async unless you `return`


remove all flash objects without overloading browser

Question: I'm loading on my site third party content. Now I'm trying to remove all flash objects from my page using header script code. The problem is that everything must load in browser and i can only remove flash objects after page was loaded. So what i did is working, but it is overloading the browser when my code remove flash object. Please tell me how to do that better ?
var all = document.getElementsByTagName("*");
for (var i=0, max=all.length; i < max; i++)swfobject.removeSWF(all[i].id);

i want to replace flash object with , like all[i].parentNode.replaceChild(mydiv, all[i]);
mydiv is an image which shows a warnning in place of flash object which is not allowed.
Do i need just to remove the flash object and then insert the warnning, or what to do to not overload the browser after I'm replacing the flash object.
I'm not using jquery on my website, so please advice using only native javascript
firefox browser is very busy... in task manager, i see FlashPlayerPlugin_11_7_700_224.exe  | CPU 21%
Comment: What do you mean by 'overload'? What exactly are you experiencing?
Comment: firefox browser is very busy... in task manager, i see FlashPlayerPlugin_11_7_700_224.exe  | CPU 21%
Comment: have a look at my answer , i've edited it for your special case
Answer: The reason is because you're using the getElementsByTagName and passing it "*", which means you're looping through possibly thousands or tens of thousands of elements.
A better way to do this would be:
var allEmbeds = document.getElementsByTagName("embed");
// put code here to loop through and remove the embed elements
var allObjects = document.getElementsByTagName("object");
// put code here to loop through and remove the object elements, if they meet the criteria

You will need to do a check to see if each object is actually a Flash object. You can do that by checking if it has a classid attribute equal to "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" or a type attribute equal to "application/x-shockwave-flash".
Answer: There is more elegant way. Why not to simply redefine some methods in the swfobject class? Try to do this, put this script after your


Network connects slowly or not at all

Question: Okay, so my network card id is f6d6050. I use ndiswrapper and have it all correctly installed. Funnily though, I have to run sudo modprobe -v ndiswrapper every time I log on in order for it even to bother searching for a network. The problem here though, as you can probably guess from the title, is that most days it takes 5-10 minutes to successfully connect to the network. Most times it asks several times to confirm my network key, and it will occasionally even refuse to connect until I restart my computer.
Any ideas? Is there any code that may be helpful in finding out? Thanks.
Answer: Please do:
sudo su
echo ndiswrapper >> /etc/modules
exit

That should make your connection start automatically and hopefully will speed up the connection time too.
Comment: Well that actually did solve the automatic problem, which is great. I never figured out how to find rc.local and add a script there, so that's great, but the connection still feels a little bit sluggish. It wasn't as slow as usual though, which I guess is an improvement so thank you.

Network connects slowly or not at all


Attempted to read or write protected memory

Question: I am trying to learn WPF. I am following along with a book(WPF in 24 hours) and occasionally I get the following error:
Attempted to read or write protected memory. This is often an indication that other memory has been corrupted.
When I click "OK" the application continues to run as if nothing is wrong.So far I have worked with XAML only and have not entered any other code. The examples that I have found so far in SO and google reference specific code issues. Any shove in the right direction would be appreciated.
Oh...I am using VS2008 Pro
Comment: what OS? Using source control at all?
Comment: Happens to me too. I think this is a Visual Studo bug. Restarting the Visual Studio works.
Comment: The OS is Vista Home Premium. I am not using source control in this case as they are simply samples from the book. I do have subvserion setup though.
Answer: I had this when declaring a Style without specifying the TargetType. I cannot remember if that was in WPF or Silverlight2 though.
Answer: Old question, but in case it helps someone...
I had this error as a build error in a XAML file of a Template10, MVVM UWP app.
The reason appears to be because I was referencing a ViewModel that is in a separate .dll.
Moved the referenced ViewModel into the app, the build error goes away.


Proof that the incidence matrix of a laminar family is TU.

Question: A friend and I wrote a proof for this using the consecutive ones property that I haven't seen anywhere, so I thought I would share it here.
$\textit{Def:}$ A matrix has the Total-Unimodularity (TU) property if the determinant of all of its square submatrices has determinant 1, -1, or 0.
$\textit{Def:}$ A family of subsets $S$, is called laminar if for all $s,t \subset S$, if $s \cap t$ is not empty, then either $s \subset t$, or $s \supset t$.
Let $S$ be a laminar family of a nonempty finite set $V$, and let $A_5$ denote its $M \times N$ incidence matrix.
Prove that $A_S$ is TU.
Comment: Coule you say what means TU ?
Comment: Should have known to add it. I just appended it to the question.
Answer: $\textbf{Claim:}$ $A_S$ can be permuted into a matrix having the consecutive ones property.
$\textbf{Proof:}$ Permute the rows of $A_S$ so that they have descending row-wise sums.
$\textit{Base Step:}$ Permute the columns so that the first row has the consecutive ones property.
$\textit{Inductive Step:}$ Assume the first $N-1$ rows have the consecutive ones property. Then consider the $N^{th}$ row, $r_l$, and an arbitrary row $r_u$ from the first $N-1$ rows.
For the inductive step it will suffice to show that we can permute the columns of our permuted $A_S$ matrix to ensure the consecutive 1's property in $r_l$, while maintaining this property in $r_u$.
By the Laminar Property and the ordering of the rows of $A_S$, the set $l^{th}$ set in $S$, $s_l$ has either $s_l \subset s_u$, or $s_l \cap s_u = \emptyset.$ Thus, over all the indices $i$ where $r_l$ is 1, the value of $r_u$ is either all 1, or all 0. By the consecutive ones property, all of the indices within this selection are the same value of 1, or all 0.
Then we can freely permute the columns where $r_l$ is 1, and all of the ones within this selection, without altering the values in any of the rows above $r_l$. Thus, we can permute this subset of columns of $A_S$ to give $r_l$ the consecutive ones property, without compromising the consecutive ones property of any of the first $N-1$ rows.
$\textbf{Note:}$ As shown here, $M$ has the consecutive 1's property $\Rightarrow$ $M$ is TU. In addition, all permutations of $M$ are also TU.


Web Socket vs JMS or Activemq

Question: I want to know what are the differences between Java Web socket and JMS (or ActiveMq) ? Please let me know or have any source having any comparison of WebSocket and JMS and where to use websocket and not to and where to use Activemq instead of websocket please. Activemq is an implementation of JMS. Activemq might use Web socket. What if web socket is used to transfer messages (having any type of data) instead Activemq ?  This may depend on the type of application and requirements, how ever as general and to make me easy to get an decision what to use, let me have your ideas(I want to message between two web applications, simply,fast and light weight).
Those who vote to Close : Please think to help, at least let some one to get help, knowledge and not to avoid it.
Comment: "Web application" normally means something that runs on a web server.  Websockets are really only applicable when a browser is involved.  Unless by "web application" you mean "browser application"?
Comment: @WarrenDew. I appreciate & thank for your attention. My applications are web based, and no browser is involved. All communications are between web applications runs on servers. No browser at all. You mean, sockets are used only when browser (web pages, jsp, html, js) communicates with the server web application ? If it is so, web sockets cannot be used for my requirement. I dont have much knowledge of them. before I start, I am observing possibilities. Once again thanks
Answer: Web sockets are a way of providing two way socket style interfaces between a web browser and a web server, with the server able to push information, rather than only responding to browser HTTP "pull" requests.  It sounds from your question and clarifications that that's not what you need.
Plain sockets, however, are a good way of providing synchronous communications between applications.  If the application receiving the messages can process them synchronously - as soon as they are sent - regular sockets may be a good solution.
Message queues are intended for asynchronous communications - cases where a message, after being sent, may need to be stored for a while before the recipient picks up the message and acts on it.  Because of the need for storage, message queues require a separate server to store the message, or in some cases a database server if you already have one.
Plain sockets are simple, fast, and lightweight; message queues aren't really since they require setting up a separate server.  If you need asynchronous message delivery, though, there may be no truly simple, fast, and lightweight solution, so message queues may be the next best thing.
Comment: Thanks for your answer. I read about ActiveMq also. Now with your answer it is clear about web socekts, JSM and also, plain sockets.
Comment: Yeah, I wanted to know about plain sockets vs JMS.

Web Socket vs JMS or Activemq


Angular 2 Form Getting Duplicated?

Question: I'm using Angular 2 RC3.  I'm mostly following the documentation here: https://angular.io/docs/ts/latest/guide/forms.html.  When I get to "Submit the form with ngSubmit" things start to go poorly.  If I add
<form (ngSubmit)="onSubmit()" #heroForm="ngForm">

I get:
EXCEPTION: Error: Uncaught (in promise): Template parse errors:
Reference "#heroForm" is defined several times.

If I remove the #heroForm attribute and add:
<button type="submit" class="btn btn-default" ...

Then onSubmit() gets called multiple times.  There aren't multiple entries for the form in the dom.  Why the apparent duplication, what's going on?
Here's a very simplified component that gets the "is defined several times" error:
import {Component } from '@angular/core';

@Component({
    template: '<form #heroForm="ngForm"></form>'
})
export class Server {
}

This component is loaded via
<router-outlet></router-outlet>

and an entry in an app.routes.ts file.  I'm using Router version 3.0.0-alpha.7.
Solution
I was using both the old and the new forms approaches by accident. My main.ts file was doing bootstrap(AppComponent, [provideForms()]) ... in other words I forgot to add in disableDeprecatedForms(). It should have been bootstrap(AppComponent, [ disableDeprecatedForms(), provideForms() ])
Comment: Hard to tell without seeing what exactly you're doing.
Comment: @GünterZöchbauer Fair enough, perhaps my question should be phrased "how would one go about debugging an issue like this"
Answer: You should check if in your form-templates you have #heroForm tag defined only once. The method onSubmit() should be defined in your component class and needs to be linked to the form in use (using ngSubmit).
If you add your components code (including the imported libs) will be easier to figure out from where you get that error.
But, I suspect you try to use the old forms mechanism. I would suggest you try to use the new approach as is quite different. Unfortunately the documentation is still work in progress and some of the examples provided are using the old approach.
In Angular2 you have 3 ways to configure forms:
1) template-driven
2) model-driven or reactive approach using low level APIs
3) model-driven but with a higher level API (FormBuilder)
Here are 2 very useful blog-posts for this:

http://blog.thoughtram.io/angular/2016/03/21/template-driven-forms-in-angular-2.html
http://blog.thoughtram.io/angular/2016/06/22/model-driven-forms-in-angular-2.html
Comment: Thank you!!  Your suspicion was correct, and those links were super helpful.  I must have been using _both_ the old and the new forms approaches by accident.  My main.ts file was doing bootstrap(AppComponent, [provideForms()]) ... in other words I forgot to add in disableDeprecatedForms().  It should have been bootstrap(AppComponent, [ disableDeprecatedForms(), provideForms() ])
Comment: No worries, I'm glad it helped
Answer: I had the same issue, but unlike the first poster I was calling disableDeprecatedForms().  Since I was converting an existing old form, in my case, my component.ts file had the old
import {FORM_DIRECTIVES} from '@angular/common';

and...
directives: [FORM_DIRECTIVES]

Replacing these with the NgForm fixed my issue.
Comment: Seems like FORMS-DIRECTIVES can be elusive.  I had some left in my code in RC4 that did not cause an issue, but do in RC5.  Perhaps because adding FormsModule at the root level exposes the issue everywhere it is used.
Answer: You can use (submit) instead of (ngSubmit)
Answer: Tried everything, the only one that worked for me was change the <button> for a <input type="submit">.

Angular 2 Form Getting Duplicated?


python2.7 memory limit release

Question: I want one Giga byte data string.
using this code
length = 0x20000000

payload = ''.join(random.choice(string.printable) for _ in range(length))

but python excepted and print this error "MemoryError"
full error message :
payload = ''.join(random.choice(string.printable) for _ in range(length))
MemoryError

i found this excepted case in stack overflow.
using "import sys, sys.setrecursionlimit(10**6)" will fix it!
so, i adding this code.
but not solved!!
i can't "import resource". because, can't not install..
Comment: ah.. Do you have a good way for create many stirng?
Comment: How much memory does your system have?
Comment: my laptop have 8g !
Comment: Is both your OS and python install 64bit?
Comment: yes! my os version is windows 10 64bit!
Comment: I used to think it was a good idea to start with Python without understanding the underlying C code sometimes, but here is a great example of why I was wrong.
Answer: I think the best option for you is to use a bytearray:
barray = bytearray()
length = 0x20000000
for _ in range(length):
    barray.append(random.choice(string.printable))

This only consumed about 0.5 gigs on my machine.
Note, increasing the recursion limit won't help you here, indeed you aren't using recursion at all. You are just making something that is very large. Just the array of pointers underlying the list that gets created by ''.join will require about 0x20000000 * 8 * 1e-9 == 4.294967296 gigabytes, and that doesn't count the strings in the list themselves, each of which requires a full python object, which is another 40 or so bytes per object, so you see, you were just running out of memory. So taking into account your individual string objects:
>>> 0x20000000 * (48) * 1e-9
25.769803776000003

So you would need over 20 gigs! Doable on some modern laptops, but 8 gigs sure isn't enough.
Comment: Any directly mutable container (so not a list) would work. Your solution is probably simplest. numpy arrays would work to. Well seen.
Comment: @MadPhysicist yes, a `numpy.array` would work, but a `bytearray` is essentially a mutable string in Python 2, so that's probably the most appropriate.
Comment: I am not disagreeing with you one bit. Your answer is excellent.

python2.7 memory limit release


Adding an outlet to a circuit

Question: I'd like to add an outlet behind our television.  I was going to pull power from an the outlet in the picture.  The outlet used to be switched, but the light switch has been re wired so it no longer controls the outlet.  How do I pull power from this outlet?
Also, I am out of 12/2 so I would like to use some 12/3 I have. I can do this, and either cut off the red or wirenut it right?
Answer: Easy peasy.
The black wires in the back of the box are certainly always-hot.
The white wires are certainly neutral, and they are using the receptacle to be a splice (i.e. To replace a wire nut) while also supplying the receptacle.
The red is your switched hot from the switch, which you defeated.
You want to add a third hot and neutral from your new cable.  It would also be nice to power the receptacle straight off the always-hot (black) and abandon that extra loop up to the switch.  It would also be nice to stop using those unreliable and troublesome "back stab" wire connections.
You can't use two wiring methods (backstab and screw) on the same receptacle, so you can't splice 3 wires to a receptacle.  The exception is the Leviton "screw-and-clamp" types, which support 4 wires per side and are about $3.00.  Alternately you could pigtail the receptacle.
So I would add the new cable.   Join the now-3 black wires on the brass side of the Leviton screw-and-clamp, or the 4 wires (with pigtail from the receptacle) with a red wire nut.   Same thing with the whites.
Red wire nuts are ideal to bind four #12s or #14s, it helps to tape any 2 wires together so you are trying to line up 2 bound pairs of wires instead of four loose ones.
As for the red, I would splice the existing and your new red together with a yellow wire nut. Cap the red wire off in the new receptacle, and also go back into the switch box and cap it off there.  Now it's de-energized, but it's in the wall in case the next homeowner wants to set up a switched outlet at either old or your new location.
Comment: so I will cap red in the switch box.  Then I will add a new wire between the existing outlet and the new outlet.  I will take all (3) blacks and pigtail them, connected to brass screw.  I will take all (3) whites and pigtail to the other side of the outlet.  Sorry if this sounds like I'm just regurgitating what you said, but I just wanted to write t out myself to confirm I am following your directions.
Comment: @AlexanderBaker That sounds right.
Comment: I would like to vote for pigtailing the receptacle as it tends to follow the NEC intent closer. Also that Leviton type was the only type of receptacle I would allow my electricians to use in residential. Yes it's just that much better.

Adding an outlet to a circuit


Prove that $\int_{E}f = \int_{I}\int_{[\phi(x),\psi(x)]}f(x,y)dydx$ using Fubini's Theorem

Question:
Problem. Let $E$ be a domain in the plane bounded by the continuous curves $y = \phi(x)$ and $y = \psi(x)$ for $x \in  I = [a,b]$, where $\phi(x), \psi(x)$. Prove that if $f$ is a Borel measurable, integrable function defined on $E$, then
  $$\int_{E}f = \int_{I}\int_{[\phi(x),\psi(x)]}f(x,y)dydx.$$

My attempt. Use the Fubini's Theorem that says
$$\int_{I}\int_{[\phi(x),\psi(x)]}f(x,y)dydx = \int_{I \times [\phi(x),\psi(x)]}f(x,y)d(y \times x)$$
where $x \times y$ represents the product measure. But I could not relate $\int_{E}f$ with $\int_{I \times [\phi(x),\psi(x)]}f$. I believe that this is the main point of the question. Can someone help me?
Comment: Your equation at the end doesn't make sense as stated: In $I\times [\phi(x),\psi(x)]$, you haven't said what $x$ is.
Answer: The idea is to apply Fubini's theorem in $\mathbb R^2.$ Recall that for any $g$ Borel measurable and integrable on $\mathbb R^2,$ we have,
$$ \int_{\mathbb R^2} g \ = \int_{\mathbb R}\int_{\mathbb R} g(x,y)\,\mathrm{d}x\,\mathrm{d}y. $$
The key trick is to embed the information about $E$ into this function $g.$ So we set,
$$ g = \chi_E f. $$
Where $\chi_E$ is the characteristic function of $E \subset \mathbb R^2.$ By our assumptions $g$ is indeed Borel measurable and integrable, such that,
$$ \int_{\mathbb R^2} \chi_Ef = \int_E f = \int_{\mathbb R}\int_{\mathbb R} \chi_E(x,y)f(x,y)\,\mathrm{d}x\,\mathrm{d}y. $$
Now $(x,y) \in E$ if and only if $x \in I$ and $\varphi(x) \leq y \leq \psi(x).$ So we conclude that,
$$ \int_{\mathbb R}\int_{\mathbb R} \chi_E(x,y)f(x,y)\,\mathrm{d}x\,\mathrm{d}y = \int_I \int_{\psi(x)}^{\varphi(x)} f(x,y)\,\mathrm{d}x\,\mathrm{d}y, $$
from which the result follows.
Comment: Nice, I got it! Thank you!


Nextjs13 experimental app directory with next auth not working/ giving a session?

Question: I am using next.js auth 4.
file structure
As you can see here is my file structure. I am using next.js's experimental app folder component. I was told to not use pages for this but I ran into a problem with this. This code is straight out of the next.js box but in next auth it says I need to wrap my entire app in a session provider. I here on stack to use the layouts file for it. But in this advice I don't have a session to give my session provider!
see:
rootlayout.jsx
export default function RootLayout({ children }) {

  return (

      <meta charSet="UTF-8" />
      <meta httpEquiv="X-UA-Compatible" content="IE=edge" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      <title>Testing code</title>

      <Providers>
        {children}
      </Providers>

  )
}

provider.jsx
'use client'
import { SessionProvider } from "next-auth/react"

const Providers = ({children}) => {
    return (
        <>
            <SessionProvider>
                {children}
            </SessionProvider>
        </>
     );
}

export default Providers;

The session provider doesn't get a session because of the root layout.
Before the app.jsx would give it a session.
If I add an pages folder it might interfere with the project but how can I  fix this?
Answer: Hey I see some issues in the above code.

Folder structure issue
It should be something like

app/api/auth/[...nextauth]/route.js

[...nextauth] - is a folder used by nextjs for dynamic routing example - localhost:3000/api/auth/callback
For refrence - https://next-auth.js.org/getting-started/example

2. provider.jsx
'use client';

import { SessionProvider } from 'next-auth/react';

const Provider = ({ children, session }) => {
    return <SessionProvider session={session}>{children}</SessionProvider>;
};

export default Provider;

In folder structure shared above its mentioned layout.jsx and page.jsx which is correct but in question you mentioned rootLayout.jsx which is incorrect. I don't understand which one you are using but the correct way to do it is by using
layout.jsx

export const metadata = {
    title: 'Promptopia',
    description: 'Dsicover & Share AI Prompts',
};

const RootLayout = ({ children }) => {
    return (

                <Provider>
                    {children}
                </Provider>

    );
};

export default RootLayout;

Note: Please import provider used in layout.jsx
You dont have to send session manually from rootLayout, Nextjs will take care of that automatically
Comment: How would the above code change if im using typescript ? I get an error because Provider needs a "session" argument but I have no session to pass to it in the layout file.


Where can I find widgets for Unity?

Question: I want to class up my desktop with various widgets that tell me network bandwidth hdd usage during r/w and real time memory usage just to name a few.  What a good way to go about that?
Comment: Desktop, not panel, close voters...
Comment: This isnt about "application indicators"
Answer:
System load indicator in the software center
(sudo apt-get install indicator-multiload)
Conky
(sudo apt-get install conky)

Where can I find widgets for Unity?


Slow recovering from lock screen Ubuntu 18.04

Question: I addition to being aesthetically pleasing, I am quite pleased with some of the new features in 18.04.  However, what I am not quite impressed with is how slow it is recovering from the lock screen.  See, on my 8-year-old laptop, every time I open the screen or I come back to it after it locked automatically due to inactivity it takes what I consider to be an extremely long time to recover from a locked screen after typing in my password.  Two weeks or so ago I switched to 18.04 (fresh install) on my laptop that was using 16.04.  Unlocking the screen on 16.04 took only a second or two while now, on 18.04 it takes 15-20 seconds or so.  Once in, everything seems to run as smoothly as usual.
Anyone can tell me how I can check what is causing this?
P.S.: It is likely some people will say that it may have something to do with how many extensions I have running.  However, my guess that it should not as there are only two shell extensions running (that I can tell): Ubuntu AppIndicators and Ubuntu Dock.
Update:
As suggested in the first comment, here is the output of journalctl -b. The End looks like this only displaying the last commands corresponding to the time stamp right at the moment I started to unlock the system.
May 28 09:36:56 tm2 org.gnome.Shell.desktop[1342]: Window manager warning: Overwriting existing binding of keysym 73 with keys
May 28 09:36:59 tm2 gdm-password][5500]: gkr-pam: unlocked login keyring
May 28 09:36:59 tm2 gnome-software[1630]: no app for changed firstname.lastname@example.com
May 28 09:36:59 tm2 gnome-software[1630]: no app for changed firstname.lastname@example.com
May 28 09:37:00 tm2 gnome-shell[1342]: [AppIndicatorSupport-DEBUG] Registering StatusNotifierItem :1.61/org/ayatana/Notificati
May 28 09:37:00 tm2 gnome-shell[1342]: [AppIndicatorSupport-DEBUG] Registering StatusNotifierItem :1.56/org/ayatana/Notificati
May 28 09:37:00 tm2 gnome-shell[1342]: [AppIndicatorSupport-DEBUG] Registering StatusNotifierItem :1.56/org/ayatana/Notificati
May 28 09:37:00 tm2 gnome-shell[1342]: [AppIndicatorSupport-FATAL] unable to lookup icon for chrome_app_indicator_1_1
May 28 09:37:00 tm2 gnome-shell[1342]: [AppIndicatorSupport-FATAL] unable to lookup icon for chrome_app_indicator_1_1
May 28 09:37:00 tm2 gnome-shell[1342]: [AppIndicatorSupport-FATAL] unable to lookup icon for chrome_app_indicator_1_1
May 28 09:37:00 tm2 gnome-shell[1342]: [AppIndicatorSupport-FATAL] unable to lookup icon for chrome_app_indicator_1_1
May 28 09:37:01 tm2 gnome-shell[1342]: [AppIndicatorSupport-FATAL] unable to lookup icon for chrome_app_indicator_1_1
May 28 09:37:01 tm2 gnome-shell[1342]: [AppIndicatorSupport-FATAL] unable to lookup icon for chrome_app_indicator_1_1
May 28 09:37:01 tm2 gnome-shell[1342]: [AppIndicatorSupport-FATAL] unable to lookup icon for chrome_app_indicator_1_1
May 28 09:37:01 tm2 gnome-shell[1342]: [AppIndicatorSupport-FATAL] unable to lookup icon for chrome_app_indicator_2_8
May 28 09:37:01 tm2 gnome-shell[1342]: [AppIndicatorSupport-FATAL] unable to lookup icon for chrome_app_indicator_2_8
May 28 09:37:01 tm2 gnome-shell[1342]: [AppIndicatorSupport-FATAL] unable to lookup icon for chrome_app_indicator_2_8
May 28 09:37:01 tm2 gnome-shell[1342]: [AppIndicatorSupport-FATAL] unable to lookup icon for chrome_app_indicator_2_8
May 28 09:37:02 tm2 gnome-shell[1342]: [AppIndicatorSupport-FATAL] unable to lookup icon for chrome_app_indicator_2_8
May 28 09:37:02 tm2 gnome-shell[1342]: [AppIndicatorSupport-FATAL] unable to lookup icon for chrome_app_indicator_2_8
May 28 09:37:02 tm2 gnome-shell[1342]: [AppIndicatorSupport-FATAL] unable to lookup icon for chrome_app_indicator_2_8
May 28 09:37:06 tm2 org.gnome.Shell.desktop[1342]: Window manager warning: Overwriting existing binding of keysym 73 with keys
May 28 09:37:07 tm2 org.gnome.Shell.desktop[1342]: Window manager warning: Overwriting existing binding of keysym 73 with keys

Unfortunately, I do not know what I am looking for.  I note that this time it took about 8 to 10 s to unlock.
Also, I did dmesg | grep error and here is what I see:
[    5.462658] EXT4-fs (sda2): re-mounted. Opts: errors=remount-ro
[    6.824954] platform regulatory.0: Direct firmware load for regulatory.db failed with error -2

In the latter, I do not see anything that could potentially trigger the delay.  Mind you though, I do not know how to read the whole output of dmesg.
Update 2:
I am NOT using Wayland as very often when I use it the computer freezes.  I only use it when I need to use the overhead projector otherwise I cannot get the second monitor (and the main monitor goes black until I unplug the VGA cable).
One more thing that I noted is that when it takes very long time and I do CTRL + ALT + F1 I go to a terminal message window where I can actually see my password as I typed it as the last line in the output. This is now a very severe security vulnerability issue in my system.
Comment: I'm experiencing this too, and I'm wondering if this is an issue introduced in a more recent update? It wasn't an issue when I first installed 18.04.
Comment: Same issue here. I hate that.
Comment: Same problem on fresh install, some times take 10-20 seconds till desktop shows up.
Comment: Mine only takes a second in both Unity and Gnome desktops on 18.04. Lock the screen, then unlock it, go to the terminal, type `journalctl -b`, press the `End` key and look for message(s) that might indicate the delay. Additionally after unlocking you can type `dmesg` and see if errors appear there.
Comment: Same issue here. Is there any way to just get rid of the lock screen and just have the screen go black like it used to? I have already told it not to log me out or ask for a password but I still get that utterly pointless splashscreen with an image and a time on it, and then I have to wait for that to go away! I don't have an old computer but I have a very cheap computer.
Comment: Even on fast computers, this [bug](https://gitlab.gnome.org/GNOME/gnome-control-center/issues/757), is so annoying.
Answer: I think this is bug #1774188. Sorry--there is no fix or work-around available at time. If you go say it effects you, it may get more attention from the developers.
Comment: Thanks.  I have added my name to the list.  I have not had the chance to install 18.10 but wondering if the issue persists there are well.
Comment: I submitted a bug upstream [here](https://gitlab.gnome.org/GNOME/gnome-control-center/issues/757).


Can I electrically isolate appliances by putting them on separate legs of a split phase supply?

Question: In my office, I have a server (powered through a UPS) and a laser printer on the same circuit. When the laser printer turns on, the lights dim and the UPS will briefly switch to battery. This prematurely wears out the battery, and, if there were no UPS, would cause extra wear and tear on the server's power supply.
Can I electrically isolate these two from each other by putting them on separate legs of my house's split-phase power supply? In other words, do loads on one leg of a split-phase power supply affect loads on the other leg?
Possibly related answer here.
Comment: This is a **very** common problem. I have had it myself with my desktop computer for many years and I was at a customer earlier today and noticed the same problem.
Comment: Right now, are they on the same circuit, i.e. if you shut off or trip the breaker powering one, does the other lose power? If on 2 breakers, what is the physical relationship of the breakers to each other in your panel? Put a stickynote to mark each breaker and shoot us a photo of that area of your panel.  I'm  also fishing for panel make/type (in very coarse terms; we need to know QO vs Pushmatic, but not QO2448 vs QO3042).
Comment: I'm pretty sure that they're on the same circuit, but I will check tomorrow when there's daylight.
Answer: If the outlets are on completely separate wire runs from the breaker panel OR sharing a neutral but on opposite legs (sharing on the same leg is illegal), then the wire resistance from the panel to the outlets will be isolated between them and the voltage drop will be minimized. (The current draw is low enough that there should be no noticeable drop at the panel).
So yes, even if they were on the same breaker, let alone phase, as long as the wire runs are separate, the server should not see a drop from the laser printer. Also good if a neutral is legally shared.
(The reason that the shared neutral is OK is that each circuit's return current will be 180 degrees out of phase. Therefore, the worst case current through the neutral will be one circuit's. In fact, when the laser turns on, the voltage may even rise slightly to the server as some of the server return current will actually flow through the laser, bypassing the neutral.)
Answer: The problem is they're on the same circuit, and they may actually be overloading that circuit.  The classic example is a gaming PC (10A) or server (13A) and a laser printer (7-12A in operation, 50A when cycling on the fuser assembly).  In case you're counting, circuits are typically 15 or 20 amps.  So you overload them right quick.   The circuit breaker is a slow-trip, and might take 15 minutes to trip at a modest overload.
However, the overload is happening on the same 2 wires -- and the resistance of those wires (against the high current) is causing an excessive voltage drop.
<code>E=IR
Voltage Drop = Current * Wire Resistance.
</code>
The resistance of a wire is proportional to its length, so if it's a long wire run back to the panel, it will make the voltage drop worse.
Another thing that will make voltage drop worse is poor connections in receptacles or switches.  This is common with "back-stab" connections and can happen with screws also.  Feel for any outlets on the circuit getting warm.  Outlets shouldn't get warm.

Running another circuit from the panel will solve the problem.
It will not matter if the circuit is on the same pole or the opposite pole - the problem is the long wire run.  So the laser printer will suffer its own voltage drop in its cable run, and the computer will feel only its own voltage drop in its cable run.   If the computer does feel it, that indicates a supply problem - too small a subpanel, or a developing problem in the service drop from the street.
You could consider a multi-wire branch circuit - however that could cause interaction because now you have 3 resistors in play instead of just 2.  MWBCs are generally more trouble than they're worth, especially now that AFCI is required and GFCI is widely used.


How can I remove the ends of this tap spout?

Question:
I'm trying to find a shower that fits these taps but with no success.I have seen showers with ends that screw into the tap spout but I don't know how to remove the black plastic ends that are already in there.
Comment: Usually the end caps are just friction fit. You can pry them off with your fingernail or a small screwdriver.
Comment: I'm not clear on what you want: are you looking for a [faucet aerator](https://en.wikipedia.org/wiki/Faucet_aerator) for the end of this faucet?
Comment: Yes Daniel,as the taps have flat spouts I'm thinking the only way I can attach a shower to these taps is to remove the black plastic ones with ones that have a thread on so the shower hose can be screwed on
Comment: Please use the [edit] link underneath your post to add extra information, and `add a comment` to reply to someone who has commented on yours. Thanks and welcome to the site.
Comment: Yes Daniel,as the taps have flat spouts I'm thinking the only way I can attach a shower to these taps is to remove the black plastic ones with ones that have a thread  on so the shower hose can be screwed on that way.
Answer: Wow, I haven't seen separate hot & cold taps in a long time. I'd say it's time for an upgrade. It looks like you've been after that pictured one pretty good. I'd spray them inside & out with vinegar a half dozen times throughout an entire day & then run the hot water one for a minute.
The hot water would heat it up & hopefully loosen everything, including any mineral deposits that the vinegar broke-up. Then, give it another jerking twist, rather than a slow torqueing twist. If that all works on the hot side, then you'd pour hot water over the vinegar-ed cold tap until that's heated.
I can't make out if the black plastic piece is hollow or not. But, if it is I think your only other option is to use an Internal Pipe wrenching bit of the right diameter, like this.
Comment: Thanks Iggy I will try that.Im presuming they are hollow as water comes through them.Its not my house so upgrading or installing a shower with electrics and plumbing isn't an option I'm afraid.
Comment: Ah, I see. Yeah, I just meant the ends might be aerators & you'd have to bust those out in order for the Internal Pipe wrench bit to get a solid grip. But, hopefully the vinegar, heat & jerking does the trick.
Comment: Thanks Iggy that worked a treat,much obliged.Thanks to all who responded.
Comment: Fantastic! Good luck with the shower hook-up, it'll be a great improvement.
Comment: @Iggy separate taps for hot and cold are still quite common in many places in the world, especially in the UK. If I had to guess, that is where the OP is from.
Comment: I've actually never ever seen them on a tub, where they could actually make some sense. I lived horribly with them for a few years on a sink.


Call-of-Duty Warzone: how do you get the FPS to show on screen?

Question: I checked the Blizzard launcher but didn't see it. I tried googling with no relevant results: "warzone how to show fps". I checked the ingame settings too.
How do you get the FPS to show on screen in Call of Duty: Warzone?
Answer: In the game settings, go to:
Options » General » Telemetry
And enable: Frames Per Second (FPS) Counter
Answer: I have options, No general. I guess they updated and removed it. so here is your answer: It does not exist and everything you google on will send you to the exact same bs.
Comment: Hey, welcome to Arqade.SE ^^ Take the [tour](https://gaming.stackexchange.com/tour) if you haven't already and read the [help center](https://gaming.stackexchange.com/help) if in need of guidance. Do you have something to support your claim? Like a screenshot or a reference to a patch mentioning the removal of the option? Also, seems like the OP is playing on PC, settings might vary with consoles, so are you also playing on PC?


How to check whether I already replied to a tweet or not?

Question: I am aware of a method in which we can save tweet ids to which we replied in a text file. Then while replying to a new tweet, search in that file, and check whether we already replied to that id or not. If the tweet to which we are replying to already exists in the file, then don't reply.
But the problem is by the time this list of ids will grow and and searching will become time consuming.
I am thinking to get tweet ids of all the replies. Then check username of those replies. If it matches with mine, then don't reply.
My question is how to get tweet ids of replies? I am not able to figure out a way to do this using twitter apis and tweepy. Alternate solutions are welcome.
Answer: You can simply create a list with the ids you replied to
replied = []

then for each reply:
replied.append(tweet.id)

When you need to check if the tweet is already replied:
if tweet.id not in replied:
    #e.g. reply


What is the best graphical interface for inputting a list of pairs?

Question: I want to create a graphical interface for inputing skill build orders for an RPG game. A skill build is an ordered list of (skill, number) pairs, like this (see footnote):
(A x1) -> (B *) -> (C x2) -> (A *)

I want to create a graphical interface that can add items to this kind of list, preferably in any position of it.
The main idea I am having now is to make some sort of drag-and-drop interface, with icons representing the skills
current build = (A x1) -> (B *) -> ...
-----------------------------------------
amount: [ 1 | 2 | 3 | 4 | * ] (radio buttons or drop-down selector)
skills: +---+  +---+  +---+
        | A |  | B |  | C |
        +---+  +---+  +---+

Clicking an icon would add the item-number combination to the end of the list (the most common place to add things to) and dragging it to a spot on the result list would cause it to be inserted there instead.
But I imagine having to do multiple clicks to select the number and the icon would be awkward. An alternative might be having a button for each possible pair:
+----+  +----+  +----+
|A  *|  |B  *|  |C  *|
+----+  +----+  +----+

+----+  +----+  +----+
|A x1|  |B x1|  |C x1|
+----+  +----+  +----+

+----+  +----+  +----+
|A x2|  |B x2|  |C x2|
+----+  +----+  +----+
//and so on

But then I think it would get way too cluttered.
What is the best way to input such a list of pairs?
Are there any places where a similar problem was solved and where I can take inspiration from?
Some design considerations:

I have 4-5 skills and the numbers range from 3-5 (and the * wildcard)
Some numbers (1 and *) will be selected more often then others (2,3,4). All skills are equally likely to be selected.
If we choose an asymmetrical design, skills should be prioritized over numbers.
I am primarily interested in obtaining a fast and clean workflow. It is OK if the final result ends up a little complicated or unintuitive.

This is not intended to be the default interface. I want this to be faster then the simple but slow interface where each skill is entered manually for each level.

For the curious, a pairing like
(A x1) -> (B *) -> (C x2) -> (A *)

can be interpreted as
As a first priority, level up A once
As a second priority, level up B whenever possible
As a third priority, level up C twice
As a fourth priority, level up the remaining levels of A

The main reason for using this is because describing directly what skill to take at each level is longer and less clear:
A, B, C, B, C, B, A, B ...  // this is simple, but less clear

Comment: What's the number? The rank of the skill or the number of times to train it? Does the wildcard just mean to train it until it's at whatever the maximum is?
Comment: Its the number of times to train it. I took that part of to avoid clutter and make the question more generic, let me put it back in then...
Comment: This sounds similar to the skill queue feature in EVE HQ: http://www.evehq.net/
Comment: @missingno - what did you end up doing?
Comment: @RogerAttrill: Real life caught up and I didn't get enough time to finish this part of my side project yet :(
Answer: You could use a single drag and drop action to pick a skill, drag it towards an amount to 'collect' it as you drag, and then continue dragging on towards a list of your skill build order and drop over an insertion point in the list.
This is illustrated by the sequence below:
Comment: Really interesting! Do you know any place this is used (so I'd be able to take a look at it functioning) or did you just come up with the idea?
Comment: It's my own idea - based on something else I was considering for this question: [two level selection](http://ux.stackexchange.com/questions/8970/user-control-for-a-two-level-selection). I adapted it for your question, but it's a similar concept. There's widgets out there where you can drag/drop items into a list which makes space for the drop, but I've never seen anything where you 'collect' information during the drag to combine a multi-step process into one action. If I had time I'd love to try it out. Maybe worth asking the OP on that question what they did and how it went?
Comment: Must the user need to do the second drag? Could they instead choose to instead drag/drop the ABC onto the 1234* and it would then automatically plonk onto the end of the list by default. (Additionally, it should also be possible drag/drop the items in the build order to rearrange, and even possibly replacement ABC / 1234* dropped onto already added skill build items).
Comment: @Erics - it's not a *second* drag it's a *continued* drag - ie one operation. It allows inserting into an existing list and anyway, you may not *necessarily* want to have to figure out the order in your mind before you start doing anything (eg - which pair do I need to do first). But yes - you could *also* drop over the middle column and have it auto-append to the list column. And also drag and drop within the columns to re-arrange as well - yes definitely.


Find $A$ such that $f(0) = A$ and there exists $f'(0)$

Question: Let
$$f(x)=
\begin{cases}
(e^{3x}-3e^x+2)/x^2 & :x \neq 0\\
A & :x=0\\
\end{cases}$$
I'm supposed to find $A$ such that there exists $f'(0)$. My attempt:
First, I found $A$ such that $f$ is continuous at $x=0$, using de l'Hospital's rule to calculate $\lim_{x \to 0^{+}}f(x)$ and $\lim_{x \to 0^{-}}f(x)$.
$$f(x)=
\begin{cases}
(e^{3x}-3e^x+2)/x^2 & :x \neq 0\\
3 & :x=0\\
\end{cases}$$
Then I calculated one-sided limits of the difference quotient at $x=0$ using de l'Hospital's rule (but I'm not sure if I'm allowed to do so - I've read that applying this rule to the definition of derivative may lead to some kind of circular reasoning).
$$\lim_{h \to 0^{+}}\frac{f(0+h)-f(0)}{h}=\lim_{h \to 0^{-}}\frac{f(0+h)-f(0)}{h}=\lim_{h \to 0}\frac{f(0+h)-f(0)}{h}=f'(0)=4$$
Is this solution correct? Wolfram Alpha and Desmos tell me that $f'(0)=0$ for $A=3$. However, when I set $A$ to a different value (meaning the function isn't continuous at $x=0$ and hence not differentiable) I still get $f'(0)=0$, which is quite confusing.
Comment: The derivation works only when $f(0)=A=3$  Otherwise the difference quotient blows up.
Answer: What do you mean by "same result" for$A\ne 3$?  In that case $f'(0)$ does not exist.
To get continuity, use power series for the numerator: $1+3x+\frac{9x^2}{2}-3(1+x+\frac{x^2}{2})+2=3x^2$  Therefore $\lim_{x\to 0}3$.
Answer: You are right, wolfram says f'(0)=4
Comment: I'm supposed to find A such that there exists f′(0). That sentence is bad, since for certain function we can have a situation that f(x) is contiuous but not differentiable at x=0. As you know, even  we know that it is continuous at set X, we still can't say whether it is differentiable at certain points inside set X
Comment: That doesn't prove he is right, it just proves that wolfram alpha agrees with him!
Answer: You have calculated $A$ correctly now for finding $f^{\prime}(0)$
$$\begin{align} f^{\prime}(0) &= \lim_{x \to 0}\dfrac{\dfrac{e^{3x}-3e^x+2}{x^2} - 3}{x}\\
&=\lim_{x \to 0}\dfrac{e^{3x}-3e^x+2-3x^2}{x^3}\\
&=\lim_{x \to 0}\dfrac{e^{3x}-e^x-2x}{x^2}\\
&= \lim_{x \to 0}\dfrac{3e^{3x}-e^x-2}{2x} \\
&= \frac{9}{2}\lim_{x \to 0} \dfrac{e^{3x}-1}{3x} - \frac{1}{2}\lim_{x \to 0} \dfrac{e^x -1}{x} \\
&= 4 \end{align}$$
Answer: $f(x)= 4x+3$ if $x = 0$
(filled needed 7  more characters)
Comment: So $f'(x)$ is dicontinuous at $0$. (f not differenciable)
Comment: that way the function is continuous and derivable 1 time
Comment: I see, but why is $A=4x+3$ better than $A=3$?
Comment: Because if A = 3 then the side limits of the derivative in x=0 is $f'(0)=4$ but at $f'(0)=0$ so the derivative is not continuous at x=0.
Comment: I don't quite get what you mean. How is $f'(0)=4$ and $f'(0)=0$ at the same time?
Comment: The limit by the right side, the limit by the left side and the value at the point.
Comment: $$\lim_{x \to 0^{+}}f'(x)=\lim_{x \to 0^{-}}f'(x)=4$$ $$f'(0)=0$$


Lossless video compression codecs

Question: I want to create a video (bar.xxx) that is lossless from a video (foo.xxx) using ffmpeg. Could you please show me the parameters for such a video. The video must be playable on VLC and/or Totem. The wrapper format must be either mp4, avi or mov.
Answer: First make sure that you have FFmpeg and the extra codecs installed.

Under Xenial Xerus this command should suffice:
sudo apt-get install ffmpeg libavcodec-extra

Under Trusty Tahr this guide should be followed:

FFmpeg Trac: Compilation Guide Ubuntu

Then for either Trusty or Xenial the following command will convert your input video to lossless H.264 in an mp4 container:
ffmpeg -i input -c:v libx264 -preset veryslow -qp 0 output.mp4

The file will be quite large and the video is lossless, but be aware that the value of converting to lossless depends very much on the quality of your initial file.
Neither Totem or vlc should have any troubles playing such a file. You could perhaps experiment a little with huffyuv:
-c:v huffyuv

but you might find that these files are massive for the arguably the same results as lossless H.264...
References:

FFmpeg Trac: Lossless H.264

Lossless video compression codecs


is there a way to test onCreateOptionsMenu(Menu menu) in android?

Question: i want to write a test to validate what i do in onCreateOptionsMenu
Can anyone assist me how to go about it?
<code>@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.global, menu);
        setdate(menu,this);
        return super.onCreateOptionsMenu(menu);

    }
</code>
Comment: what's the exact problem/error you got ?
Comment: i just cant figure a way to write a test for it?that is how to validate that the right menu is shown and setdate is called
Answer: For testing, if you want to check whether setDate() is called, you can add logs and check them in DDMS -> Logcat :
<code>@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.global, menu);
        Log.d("tag","onCreateOptionsMenu calling setDate");
        setdate(menu,this);
        Log.d("tag","onCreateOptionsMenu called setDate");
        return super.onCreateOptionsMenu(menu);

    }
</code>
On Display, the menu stored at R.menu.global will be displayed
Answer: set this changes in res/menu/main.xml
<code><menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
    android:id="@+id/testMenu"
    android:title="@string/test"/>
</menu>
</code>
and in your Activity:
<code>@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

    @Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
    case R.id.testMenu:
        //here write your action or call your method for example: setData()
        Log.i("TEST_MENU" , "Test Passed");
        break;
    default:
        break;
    }

    return super.onOptionsItemSelected(item);
}
</code>


PHP Merge PNG Images

Question: How can i merge 2 png images, or a JPEG over a png? I have this image:

The result would have to be like this:

Is there a lightweight library that can do this, or is it possible with php functions? I just want to keep the overlay image withing the background (margin of 10px) - i like to integrate it into my api.. so i can create them on the fly - or store them for later, but being able to create/batch create them online.
Comment: Look up the GD and ImageMagick libraries. GD is more commonly used. ImageMagick is more powerful. Both will be capable of overlaying pictures. However there's a *lot* of detail missing in your question. For example, do you actually need the images combined, or would it be better simply to display them layered on top of each other on the page? Do you even need images; if your background image is just a border with rounded corners, why not use an HTML border? What should the layering do if there is more to the background than plain white? What about transparency on the foreground image?
Comment: Well i provide XMLTV EPG TV guides, and in the XMLTV files is room for icons. So when  use the guide, you will have station icons. Now i have a good collection of icons - but i add new stations every week, and creating these images takes some time, uploading them etc. So i thought would be easier to do it from the admin panel - online, instead of on my desktop and then uploading through ftp..
Answer: Try using the Intervention Image PHP library, more specifically the insert function.
From the documentation:

Paste a given image source over the current image with an optional position and a offset coordinate. This method can be used to apply another image as watermark because the transparency values are maintained.

And an example:
<code>// create new Intervention Image
$bg = Image::make('public/background.jpg');

// create a new Image instance for inserting
$logo = Image::make('public/logo_discovery.png');

// Insert the logo onto the background
$bg->insert($logo, 'center');
</code>
Comment: Re "don't have laravel or composer" -- Honestly, if you're doing PHP without Composer, then you're making things much harder for yourself than you need to. Composer is very easy to learn and use, and once you're using it, it makes PHP about a gazillion times easier to work with.
Comment: Thank you, only problem with this is - i dont have laravel or composer. So i dont know if it works without / or how to use it without these..
Comment: Hmm, I don't know how to use it without [Composer](https://getcomposer.org/). Maybe you could use the [source code](https://github.com/Intervention/image) directly? If you haven't used Composer before, I'd definitely recommend you check it out.
Comment: I havent used it "yet".. i didnt need it yet, but i will check it out thanks

PHP Merge PNG Images


How can I bind my Steam game to my Ubisoft account?

Question: I'd like to know if anyone knows how to bind my Steam purchased game to my Ubisoft account. We're talking about "South Park: The Stick of Truth" in this particular case.
Problem discription:
The thing is that unlike "South Park: The Fractured but Whole", "South Park: The Stick of Truth" doesn't let you call up the Ubisoft menu (Shift+F2) while in game. In fact it doesn't even require you to download Ubisoft launcher, thus binding your Steam-purchased copy to your Ubisoft account, even if they are linked.
I also have other games on Steam as well as EpicGames that are Ubisoft's production (that same mentioned above "South Park: The Fractured but Whole" f.e.), but all of them require Ubisoft launcher and immediately bind with my Ubisoft account upon installation and launch.
Results of my own efforts on the matter:
I've tried to search the net and StackExchange for answers, but so far I've not found any ways that can work in this case. I've also tried contacting Ubisoft support team, but they've simply said "NO", without even trying much, I assume.
This said, so far my best guess would be to find a CD key of the said game and use it in Ubisoft launcher in "Activate a key" directory. But neither in the Steam library nor in the Steam receipt I can find it (I've checked the options of the game in the library, there is no "CD keys" line, as suggested for other games). Regarding that I have another idea where it might happen to be - the game's files, but I don't know exactly where and how to search for it in them.
Comment: I'm not familiar with  Ubisoft launcher, but Steam allows you to add a non-Steam game to the library, allowing some Steam features to be used in the game. If Ubi launcher allows a similar thing, you might be able to add a "non-Ubi" game (even though it is) to enable the Ubisoft overlay in-game. Doesn't answer the title question, but might suit your needs.
Comment: I didn't know Steam can do that, thanks. Where can I find out more about it? (besides obvious - the net)
Comment: The net. lol https://support.steampowered.com/kb_article.php?ref=2219-YDJV-5557
Answer: Sadly, as support said, it's not possible.
Steam and others do not share licenses between games, Valve just allows others to include their launcher and give an additional, separate license from their service for the game.
Some games do have a third-party CD-key, but when included they're either automatically "redeemed", Steam will prompt at startup to copy the key so you can easily activate the game through the other service, or there will be a cd-key that can be found from the Library page of the game in the Steam client.
Related answer about games being bought on Steam and using UPlay (now Ubisoft Connect) as DRM.


Drupal webform form action

Question: I'm adding a form to a Drupal website. I've created a new page, and created a webform, the webform has been assigned to the page content as a block.
The problem I'm having is when submitting the form, instead of showing the errors of the form at the top of the page like the rest of the forms do, the form action is set to the individual web form page, and any styling/content blocks disappear.
Essentially what I need to do is ensure the form posts to the same page, if I edit the form action in dev tools, the errors show fine at the top of the page.
EDIT: Should also add - I've setup the page and wbeform as per all the others, and they all function as they should and post to the same URL as the page.
Any help appreciated.
Thanks
Comment: you could try the webform ajax module for the block. https://www.drupal.org/project/webform_ajax
Answer: If you are using the Webform module then you can go to the configuration page of the block in the 'Blocks' section, and look for the following checkbox:
Show all webform pages in block
The description under the checkbox tells you that anything that has to do with the webform (includes errors) will be shown on the current page, instead of redirecting you to the original webform page:
By default multi-page webforms redirect to the node page for all pages after the first one. If checked, all pages will be shown in the block instead.

Drupal webform form action


Travese through all webs and intersect lists

Question: I want to traverse through all webs and child sites, to find lists with the same name and make intersection of them with child list priority  and show result in web part in repeater. Lists contain Title, Name, Link

So far I have folowing:
 using (SPSite oSPsite = new SPSite("http://niki/default.aspx"))
                {

                    SPWebCollection siteWebs = oSPsite.AllWebs;
                    foreach (SPWeb web in siteWebs)
                    {
                        web.AllowUnsafeUpdates = true;
                        try
                        {
                            SPList list = null;
                            try
                            {
                                list = web.Lists[ListName];
                            }
                            catch { }

                            if (list != null)
                            {

                                list.EnableModeration = true;
                                SPListItemCollection collection = list.GetItems(list.DefaultView);
                                repeater.DataSource = collection;
                                repeater.DataBind();
                                list.Update();
                            }
                        }
                        finally
                        {
                            if (web != null)
                                web.Dispose();
                        }
                    }

The result shows only last iteration, and no intersection implemented. I have no idea how to add two SPListItemCollection, or is there another way? Thanks.
Answer: You can use List to store the data you needed, and you also can defined the data stucture by yourself.


how to resolve the error while using Scanner class in java

Question: I have created a class "My" in which i am simply taking input from user using Scanner class"
import java.util.Scanner;

class My
{
    public static void main(String[] args)
    {
         int val;
         Scanner sc = new Scanner(System.in);
         System.out.println("Enter no = ");
         val= sc.nextInt();

         System.out.println("number " + val);
    }
}

But I am getting following errors:
My.java:1: cannot resolve symbolsymbol  : class Scanner
location: package util
import java.util.Scanner;

My.java:8: cannot resolve symbol
symbol  : class Scanner
location: package util
 java.util.Scanner scanner = new java.util.Scanner(System.in);

My.java:8: cannot resolve symbol
symbol  : class Scanner
location: package util
 java.util.Scanner scanner = new java.util.Scanner(System.in);

Comment: Remove `` in the code snapts
Comment: created Scanner object as "scanner" but used as "sc"
Comment: what is `sc` in your code??? change your line to `val = scanner.nextInt();`
Comment: After your edit your code no longer agrees with the error messages. Don't do that.
Answer: You have created Scanner object as scanner, so change sc to scanner . Code will compile without any issues.
Also one more point, Instead of using below code
java.util.Scanner sc = new java.util.Scanner(System.in);

You can directly use Scanner sc = new Scanner(System.in) since you have already imported Scanner class
import java.util.Scanner;

Note: Use java1.5 and above to access Scanner class
Comment: Yes,I have updated it.I think there is some problem while importing Scanner class from util package because i am getting error for Scanner class not its object.please refer the first error.
Comment: Which version of java are you using?It should be 1.5 and above.  If that is not the case try setting the classpath
Comment: I am using j2sdk1.4.2_09, is it suitable or not?
Comment: Scanner class is available from java 1.5 , So use java 5 and above versions to access Scanner class
Answer: `import java.util.Scanner;`

You can keep the name sc for your Scanner but change    java.util.Scanner in the body of your code to Scanner as you don't need to call the imported package to declare the object.
Update
import java.util.Scanner;

class My
{
    public static void main(String[] args)
    {
    int val;
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter no = ");
    val= sc.nextInt();

    System.out.println("number " + val);
    }
}

Comment: I have imported java.utol.Scanner; class but still getting errors.