Spark 1.5.2 Shuffle/Serialization - running out of memory

Question: I am working with several hundred GB dataset (around 2B rows). One of the operation is to reduce RDD or scala case objects(containing doubles, maps, sets) into single entity. Initially my operation was performing groupByKey but it was slow and was doing high GC. so I tried convert it to aggregateByKey and later even into reduceByKey in a hope to avoid high user memory allocations, shuffle activity and high gc issue that I was encountering with groupBy.
Application resources: 23GB exec mem + 4GB overhead. 20 instances and 6 cores each. Played with shuffle ration from 0.2 to 0.4
Available cluster resources 10 nodes, 600GB total for yarn, 32GB max container size
2016-05-02 22:38:53,595 INFO [sparkDriver-akka.actor.default-dispatcher-14] org.apache.spark.MapOutputTrackerMasterEndpoint: Asked to send map output locations for shuffle 3 to hdn2.mycorp:45993
2016-05-02 22:38:53,832 INFO [sparkDriver-akka.actor.default-dispatcher-14] org.apache.spark.storage.BlockManagerInfo: Removed broadcast_4_piece0 on 10.250.70.117:52328 in memory (size: 2.1 KB, free: 15.5 MB)
2016-05-02 22:39:03,704 WARN [New I/O worker #5] org.jboss.netty.channel.DefaultChannelPipeline: An exception was thrown by a user handler while handling an exception event ([id: 0xa8147f0c, /10.250.70.110:48056 => /10.250.70.117:38300] EXCEPTION: java.lang.OutOfMemoryError: Java heap space)
java.lang.OutOfMemoryError: Java heap space
        at java.nio.HeapByteBuffer.<init>(HeapByteBuffer.java:57)
        at java.nio.ByteBuffer.allocate(ByteBuffer.java:331)
        at org.jboss.netty.buffer.CompositeChannelBuffer.toByteBuffer(CompositeChannelBuffer.java:649)
        at org.jboss.netty.buffer.AbstractChannelBuffer.toByteBuffer(AbstractChannelBuffer.java:530)
        at org.jboss.netty.channel.socket.nio.SocketSendBufferPool.acquire(SocketSendBufferPool.java:77)
        at org.jboss.netty.channel.socket.nio.SocketSendBufferPool.acquire(SocketSendBufferPool.java:46)
        at org.jboss.netty.channel.socket.nio.AbstractNioWorker.write0(AbstractNioWorker.java:194)
        at org.jboss.netty.channel.socket.nio.AbstractNioWorker.writeFromTaskLoop(AbstractNioWorker.java:152)
        at org.jboss.netty.channel.socket.nio.AbstractNioChannel$WriteTask.run(AbstractNioChannel.java:335)
        at org.jboss.netty.channel.socket.nio.AbstractNioSelector.processTaskQueue(AbstractNioSelector.java:366)
        at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:290)
        at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:90)
        at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:744)
2016-05-02 22:39:05,783 ERROR [sparkDriver-akka.actor.default-dispatcher-14] org.apache.spark.rpc.akka.ErrorMonitor: Uncaught fatal error from thread [sparkDriver-akka.remote.default-remote-dispatcher-5] shutting down ActorSystem [sparkDriver]
java.lang.OutOfMemoryError: Java heap space
        at java.util.Arrays.copyOf(Arrays.java:2271)
        at java.io.ByteArrayOutputStream.grow(ByteArrayOutputStream.java:113)
        at java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:93)
        at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:140)
        at java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1876)
        at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(ObjectOutputStream.java:1785)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1188)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347)
        at akka.serialization.JavaSerializer$$anonfun$toBinary$1.apply$mcV$sp(Serializer.scala:129)
        at akka.serialization.JavaSerializer$$anonfun$toBinary$1.apply(Serializer.scala:129)
        at akka.serialization.JavaSerializer$$anonfun$toBinary$1.apply(Serializer.scala:129)
        at scala.util.DynamicVariable.withValue(DynamicVariable.scala:57)
        at akka.serialization.JavaSerializer.toBinary(Serializer.scala:129)
        at akka.remote.MessageSerializer$.serialize(MessageSerializer.scala:36)
        at akka.remote.EndpointWriter$$anonfun$serializeMessage$1.apply(Endpoint.scala:843)
        at akka.remote.EndpointWriter$$anonfun$serializeMessage$1.apply(Endpoint.scala:843)
        at scala.util.DynamicVariable.withValue(DynamicVariable.scala:57)
        at akka.remote.EndpointWriter.serializeMessage(Endpoint.scala:842)
        at akka.remote.EndpointWriter.writeSend(Endpoint.scala:743)
        at akka.remote.EndpointWriter$$anonfun$2.applyOrElse(Endpoint.scala:718)
        at akka.actor.Actor$class.aroundReceive(Actor.scala:467)
        at akka.remote.EndpointActor.aroundReceive(Endpoint.scala:411)
        at akka.actor.ActorCell.receiveMessage(ActorCell.scala:516)
        at akka.actor.ActorCell.invoke(ActorCell.scala:487)
        at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:238)
        at akka.dispatch.Mailbox.run(Mailbox.scala:220)
        at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:397)
        at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
        at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
        at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
        at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
2016-05-02 22:39:05,783 ERROR [sparkDriver-akka.actor.default-dispatcher-2] akka.actor.ActorSystemImpl: Uncaught fatal error from thread [sparkDriver-akka.remote.default-remote-dispatcher-5] shutting down ActorSystem [sparkDriver]
java.lang.OutOfMemoryError: Java heap space
        at java.util.Arrays.copyOf(Arrays.java:2271)
        at java.io.ByteArrayOutputStream.grow(ByteArrayOutputStream.java:113)
        at java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:93)
        at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:140)
        at java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1876)
        at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(ObjectOutputStream.java:1785)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1188)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347)
        at akka.serialization.JavaSerializer$$anonfun$toBinary$1.apply$mcV$sp(Serializer.scala:129)
        at akka.serialization.JavaSerializer$$anonfun$toBinary$1.apply(Serializer.scala:129)
                                                                                67247,1       99%

About a Job
Read input data set having around 20 fields. 1B-2B. Create an output dataset aggregating over 10 unique fields. Which becomes query criteria basically. However out of those 10, 3 fields represent various combinations of them so that we don't have to query multiple records to get a set. out of those 3 fields lets sat a, b, and c each has 11, 2 and 2 possible values. so we could get max of 2^11 -1 * 2^2 - 1 * 2^2 -1 combination for given key.
//pseudo code where I use aggregateByKey

case class UserDataSet(salary: Double, members: Int, clicks: Map[Int, Long],
    businesses: Map[Int, Set[Int]])...) //About 10 fileds with 5 of them are maps

def main() = {

      create combinationRDD of type (String, Set[Set]) Rdd from input dataset which represent all combination
      create a joinedRdd of type (String, UserDataSet) - where key at this point already a final key which contains 10 unique fields; value is a UserDataSet

//This is where things fails
     val finalDataSet = joinedRdd.aggregateByKey(UserDataSet.getInstance())(processDataSeq, processDataMerge)

}

private def processDataMerge(map1: UserDataSet, map2: UserDataSet) = {

    map1.clicks ++= map2.clicks (deep merge of course to avoid overwriting of map keys)
    map1.salary += map2.salary

    map1
}

Comment: In order for us to help you, we at least need to see some code to see what you're actually doing with those 2B rows.
Comment: Just added some job description and pseudo code. let me know if I should provide more information.
Answer: So issue was indeed driver running out of memory and not executor. hence error was in driver logs. duh. however it wasn't very clear from logs. Driver ran out because 1) It was using default of -Xmx900m 2) Spark driver relies on akka libs and akka libs relies on stubborn JavaSerializer which uses Byte array instead of stream to serialize objects. As a temp solution I increased spark.driver.memory to 4096m in my case and I haven't seen memory error since. Thanks everyone for some insights into a problem space though.
Answer: To be able to help, you should post the code and also give an explanation of the input data.
Why the data ?
When aggregating by key, to achieve optimal parallelism and avoid issues, it's important to have an idea of what the key distribution looks like and also the cardinality.
Let me explain what they are and why they are important.
Let's say you're aggregating by country...there are about 250 countries on earth, so the cardinality of the key is around 250.
Cardinality is important because low cardinality may stifle your parallelism. For instance, if 90% of your data is for the US, and you have 250 nodes, one node will be processing 90% of the data.
That leads to the concept of distribution, that is, when you're grouping by key, how many values you have per key is your value distribution. For optimal parallelism, you ideally want roughly the same number of values for every key.
Now, if the cardinality of your data is very high, but the value distribution is not optimal, statistically things should even out.
For instance, let's say you have apache logs, where most users only visit a few pages, but some visit many (as it's the case with robots).
If the number of users is much greater than the number of your nodes, the users with lots of data get distributed around the nodes so parallelism is not that impacted.
Problems usually arise when you use keys with low cardinality.
If the distribution of the values is not good, it causes issues not unlikely an unbalanced washing machines.
Last but not least, it also depends greatly on what you're doing on the aggregateByKey. You can exhaust memory easily if you're leaking objects in either the map or reduce phase of processing.
Comment: Thanks. I know data is not distributed well. Cardinality of final keys compare to initial dataset is 100:1. 1B input set - 10M output set. Does that make sense? But I think I should compare it before shuffle and after shuffle where operation is failing, right? Can you explain why I see these error in driver logs? Is it an error from executor or driver? And is it due to overall memory given to executor and/or driver or is it a limit of spark shuffle blocks itself?


Autodesk Viewer problem and missing elements from translation to SVF

Question: I've been trying to encourage some of our less Revit-savvy building services engineers to utilise the Autodesk Viewer product. Unfortunately though, I have encountered a couple of problems, one of which I think I have solved and one which I am guessing is more to do with the Autodesk Viewer Applications programmed interaction with the model derivative API.
Initially I uploaded our services model with supporting architectural and structural models but the phase the solitary 3D view created in the viewer was "Existing" with a filter of "Show All". I managed to get around this by creating a 3D view in each model just called "3D" and setting the phase and filter as I like. Happy days.

Could this also have been better solved by setting generateMasterViews to true during the POST job on a custom Forge viewer app?

However, I am only getting some elements from the services model come through into the Autodesk Viewer application. Most notably it's missing ducts, sanitary pipework, cable trays, radiators. In the "3D" 3D view I have created everything is phased correctly, no issues from worksets, visibility graphics, view discipline is coordination (doesnt work to change to mechanical) and everything looks hunky dory in Revit. In the viewer though it's a different story. Even if I upload the services model on it's own. Strangely, in the 2d sheet views all the equipment and infrastructure is there fine, just in 3D it is now.
So my knowledge of Javascript and the Forge API is quite rudimental but I'm guessing the problem is with Autodesk Viewer's implementation of the model derivative API for when the model is translated to svf.

Does this sound correct?
Could it a bug within Autodesk's viewer app? I'm not too sure what the best Autodesk forum to post in would be.
Could it be a bug within the model derivative API? Or is it a setting that is beyond my knowledge?

I guessing I'm at a place where what I'm really after is a custom Forge viewer application to design in the functionality I am after, in this case control of phasing in the .svf file output and ensuring everything is coming through in the view.
Not the most interesting post by any stretch and if you're still reading now, thanks. But I'm sure I can't be the only one experiencing this problem. While I'd love to share a model to demonstrate whats happening, it's commercially sensitive unfortunately.
If anyone can shed a more technical light on
Cheers,Pete
Answer: Hi please make sure those elements are visible in 3D views and those 3D views are chosen in the publish settings of the Revit UI. Otherwise, the Model Derivative API will translate the default 3D view called {3D} only that might not contents proper element visibility configurations.
If this issue still persists after setting this up, please consider providing a none confidential model to forge[DOT]help[AT]autodesk[DOT]com for investigations. Thanks!
Comment: Thanks for your response Eason, I will try your recommendations and see if I have any success. Cheers, Pete
Comment: Hi Eason, problem solved by creating a publish set with what I need.

What I failed to understand was that modification was required to the publish settings in order to send to the viewer the views and sheets required and to stop it from automatically publishing a default 3D view and all sheets.

Thanks again for your response.

Cheers, Pete
Comment: You're welcome! It's great to hear that it works on your side. Most of Forge starters on Revit area might encounter this issue when they use Forge for the first time as I know, I will discuss with our team if there is somewhere we can put a guide for troubleshooting such issue. Cheers! :)


How can I unlock policies?

Question: How can I unlock policies in Kittens Game, and where can I find them?
I cannot find any policies tab in science. Do I need to unlock anything?
Answer: Policies are unlocked after researching engineering.
http://bloodrizer.ru/games/kittens/wiki/index.php?page=Policies
And are found in the Science tab.
http://bloodrizer.ru/games/kittens/wiki/index.php?page=Game+tabs

How can I unlock policies?


how to call functions/methods within CMS block or page?

Question: We are trying to make all our blocks and pages static so that designer or anyone else can easily change the content or design of the website, however. There is a feature that uses our own custom module. So, the template that we want to make static is calling methods out of our custom block, for example,
<code> <!--some html code-->
    .....
    <?php $this->helpMeBePartOfCMS(); ?>
    .....
 <!--some html code-->
</code>
How do i incorporate these method calls inside cms block or page?
Thank you
Answer: The CMS system makes it easy to include custom blocks (or widgets in Enterprise), but not so easy to make method calls. This is because the templates are never parsed as PHP, so you cannot just include a PHP tag.
Why don't you define a custom block to accomplish this? If that won't work, please provide a little more detail about what you're actually trying to include, so that we can troubleshoot further.
Hope that helps!
Thanks,
Joe

Since CMS block templates are not parsed as PHP code, there's no way to inject a call as you are describing. However, all classes descending from Mage_Core_Block_Abstract have the ability to call child and parent blocks. Use one of these methods to do what you are looking for from the block directly:
<code>getParentBlock
getChild
getSortedChildren
</code>
Comment: Well, we have slider template that displays featured products. The slider template is what we want to be in CMS block, however, this slider template needs to get these featured products by calling method getFeturedProducts() from the custom block. So it would use getFeturedProducts() ?> within and some other php code to. Can there be php code in CMS block or page?
Comment: Thank you Joe for replaying and helping
Answer: there is a way that you call these php codes in any phtml file (create a new and save any where in your templates) then call that phtml file in your cms page as a block (which we usually do for calling blocks)


JavaScript unicode aware string slice

Question: I am trying to slice the string containing Unicode characters. but it returns a replacement character. here is my sample code.
let str = ' ';
str = str.slice(0, -1);
console.log(str);

which gives me below result

" �"

how can I get rid of the replacement character?
Comment: What output do you want? an Error? ` ` or ` `?
Comment: @Kaiido output should be   without .
Answer: Try this, it won't break a 4 byte character into 2:

let str = ' ';
str = [...str].slice(0, -1).join('');
console.log(str);
Answer: That's because your  is a surrogate pair, which means that it is represented as four bytes (two code units á 2 bytes, UTF-16). As .slice works on code units (as all other string methods), you need to slice away the pair:

let str = ' ';
str = str.slice(0, -2);
console.log(str);

To work with code points  instead of code units you can use the iterator of strings, which will iterate over the code points (that is one character of the string might be a string with two chars):

let str = ' ';
for(const char of str)
  console.log(char, char.length);

You can use the iterator to build up an array, work on that, and turn the array back into a string as the other answer shows.
Comment: Sure, but that was already covered by the other answer. Tried to elaborate a bit on the *why*
Comment: Thanks for the answer, but it will not work In case the string contains normal and Unicode.
Comment: Arguably, the question asks for a "JavaScript unicode aware string slice", you are telling OP that "they" need to be aware of it.
Answer: the other solution doesn't take combining marks into account. for example:
foo = 'abc'
[...foo].slice(0, -1).join('')
// 'abc'

to account for that we need to combine those into single elements in the array:
[...foo].reduce((p, c) => c.match(/\p{Emoji_Modifier}/u) ? [...p.slice(0, -1), p[p.length - 1] + c] : [...p, c], [])
// ['a', 'b', 'c', '']

with that the full solution is:
[...foo].reduce((p, c) => c.match(/\p{Emoji_Modifier}/u) ? [...p.slice(0, -1), p[p.length - 1] + c] : [...p, c], []).slice(0, -1).join('')
// 'abc'

JavaScript unicode aware string slice


Painting the toilet bowl

Question: There is a spot, in the toilet bowl, right underneath where the water sits, that is a bunch of brown scratches. This is a new apartment unit I'm moving in. If I just remove a few inches of water, I should be able to paint over it, so it doesn't look like there is some poop stains. What's the right way to go about this? What type of paint? What is the right way to remove enough water so that I can paint that spot under the sitting water?
Comment: I'm fairly certain that nothing that comes out of the bottom end of a human can scratch a toilet. I *have* seen a (poorly maintained) toilet have some kind of biomineral residue. You just got to try something that'll react/dissolve it, and scrub hard.
Comment: Have you tried bleaching it yet?
Comment: One does not paint porcelain.
Comment: a new elongated (or round) "project source" toilet from lowes is $99 currently, they are better than any of the 10+ year old toilets.  you said "scratches".  you won't get that out of the current bowl.  use a tank bleaching puck to give blue bowl water, the scratches will fiill in with that color - because the glaze is scratched, at best might change your scratch color to a more desirable color.  replace your toilet.
Comment: unless the current toilet is a Toto, or a current high end model Kohler, if it has a sprial flush that takes more than 2 seconds to flush completely, replace the toilet.
Comment: almost forget, per your thread title - I'll be happy to come over and paint the toilet bowl for you haha, likely to still be brown though
Answer: Here's a trick we used to use on old houses that we renovated many years ago.  You have to be very careful, but if you get a flexible razor blade (the typical kind), you can lightly scrape the hard water and other deposits off of the inside of the bowl.  You have to go slow and with a light touch so as to not scratch the porcelain, but for some really bad toilets, this is the only thing we found that will work.  Bend the razor blade as you work so that it conforms to the roundness of the bowl and try to just get the edge of the blade under the deposits but over the porcelain.  You might end up with some faint silver scratch marks, but these are superficial and are from the blade not the bowl.  They will come off with regular cleaner.
Comment: Sounds a delightful way to spend your time ;) I use these instead [UK] https://www.harpic.co.uk/products/tablets/  although the  very worst I ever found took all 8 tablets, one a day, left 24h, to finally clear it.
Answer: Turn off the toilet shut off valve and flush the toilet. The water will go out and the toilet won't be able to fill up. Let it dry and get some acrylic appliance paint and paint the area. Matching the paint could be a challenge unless it's white.
If this is a rental, get with the landlord and have him fix it or at least get their OK to do the work.
Comment: Since you're renting, a minor caution about shutoff valves: some really old ones won't work, and worse — once you touch them, they start leaking. Home inspectors around here won't touch them for liability concerns.
Comment: @Tetsujin  With the shutoff valve turned off,  once you flush, the tank empties, the bowl fills, whirlpools and empties and no water can  get into the bowl or tank. The OP just wants the water to be below the waterline a few inches.
Comment: "The water will go out" … and immediately refill from the flush. You can't then flush it again, because there's no header. The water level will be exactly the same as it was before. You need to put something in the bowl to displace the water over the trap - hopefully without displacing enough to break the seal. A hand in a plastic bag might be sufficient.
Comment: I've seen both situations where the bowl empties or refills. If it did refill, dump a gallon of water into the bowl — that'll siphon out most and leave the level low.
Comment: Your toilets must work differently to ours. 'bowl fills whirlpools & empties' … back to the exact same level it started from.
Comment: @Tetsujin  Do you have one of those low flow, jet flush toilets?  I've got an 80's model with a Fluid master valve.
Comment: @JACK - I have no idea what one of those is. I really do think UK & US toilets are completely different to each other. From what I've read, yours are siphonic & ours are washdown. Yours have high water level & a narrow pipe, ours low level & big pipe. Yours use some kind of flapper to open the water flow, ours have a siphon flush. I really don't know what differences these really make, but if you switch off the water on ours & flush, you get one full flush, exactly the same water level as before the flush. You just don't have another flush because the tank is now empty, of course.
Comment: Hmmm… interesting - apparently a lot of UK dual-flush use the American-type mechanism… badly:\ https://www.theguardian.com/environment/2020/sep/29/dual-flush-toilets-wasting-more-water-than-they-save
Answer: Painting is likely to make it look worse and you'd need a paint that essentially needs to deal with flowing water and standing water. There's also a chance your landlord might now be happy about it, so documenting the current condition and getting their permission first is a good idea.
What you really need is an strain remover that's acidic - the stuff we use says "solvents, acid, surfactants" as its contents  and comes in a brown plastic bottle. I just dump maybe a cup or two in, scrub it hard and leave it for about 10 minutes, and flush. Repeat until clean. It takes time (and this can mean, every day for a week, just keep at it till its clean or there's no difference)

Here's another example of what the bottle looks like, though its generic enough it is a different brand from what I use, which is whatever the supermarket has.
Vinegar (the white, slightly nasty synthetic stuff) might work, but the brown bottle stuff smells better.
Comment: For those who don't know what HomeSaver is (we don't all live in the same country!) could you give a hint on what the generic active ingredient is, please?
Comment: The bottle I have literally says "Solvents, Acid, Surfactants", as mentioned in the answer.  Hence the mention of an acidic strain remover - I suspect its just sulphuric acid, detergent and water.
Comment: Ah, OK. Here in Europe the active ingredients are always listed, together with anything else which might cause an adverse reaction in a human.
Comment: I've added an image of the label. I'm not entirely convinced it'll help though.
Comment: @AndrewLeach - yeah, "Ingredients: some nasty stuff" isn't likely to pass muster over here ;) …though they do get away with "Contains: 5-15% oxygen-based bleaching agents, <5 % : anionic surfactants, non-ionic surfactants" which is the label from the Harpic tabs I mentioned on another answer.
Comment: It works. Its just... kinda hard to post as a generally useful answer. Nonetheless, nasty stuff + scrubbing, or less nasty stuff + scrubbing is better than paint :D

Painting the toilet bowl


How to publish a chatbot to Azure from QnA knowledge base

Question: I am creating a chatbot for my company - I have used Microsoft QnA to create a knowledge base, however I was following instructions from
https://www.meziantou.net/2017/05/16/creating-a-chat-bot-from-a-faq-with-azure-q-a-maker
https://channel9.msdn.com/Events/Connect/2017/T107
These videos/articles show a "BotService" preview. I am using the new "BotApp Service" and cannot figure out where to link up my knowledge base to my bot.
I am a true beginner to this and was encouraged by the video tutorials made with the old "BotService" - however when I have tried to do this, I've run into a wall with it already.
All I want to do is link up my current knowledgebase made in QnA to my Azure platform in order to use the bot on my website.
Thanks,
T
Answer: T, you should publish the QA Knowledge base/Q&A as a service, a step by step guide can be found here , I'd also recommend checking the QnA Maker page if you haven't already, it can be found here


Extract parameterized data from string using python from AWS Lambda EVENT

Question: This is the raw string
"body": "----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"status\"\r\n\r\n payment_received_unrecognised\r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"err\"\r\n\r\n An incorrect bitcoin amount has been received\r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"private_key_hash\"\r\n\r\n sadf65d4sf56sd4f6sd54fsdfs....\r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"box\"\r\n\r\n 111\r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"boxtype\"\r\n\r\n criptoBox\r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"order\"\r\n\r\n \r\n----------------------------6547984164*94652165481564\r\nContent-Disposition: form-data; name=\"user\"\r\n\r\n ADAM\r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"userformat\"\r\n\r\n \r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"usercountry\"\r\n\r\n \r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"period\"\r\n\r\n \r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"amount\"\r\n\r\n 0.0016\r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"amountusd\"\r\n\r\n 152.45\r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"coinlabel\"\r\n\r\n BTC\r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"coinname\"\r\n\r\n bitcoin\r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"addr\"\r\n\r\n 14dt4cSbvwghDcETJDuvFGHe5bCsCPR1jW\r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"tx\"\r\n\r\n 6f1c6f34189a27446d18e25b9c79db90be55b0bb775b1768b5aa4520f23d71a8\r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"confirmed\"\r\n\r\n 0\r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"timestamp\"\r\n\r\n 1422623712\r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"date\"\r\n\r\n 30 January 2015\r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"datetime\"\r\n\r\n 2015-01-30 13: 15: 12\r\n----------------------------276035280975268320779229--\r\n"
    }

I need to fetch value in DICT format, like
{
'status': 'payment_received_unrecognised',
'boxtype': 'Criptobox'
}

I am unable to extract data as i wanted... i need suggestion how to extract data from the string?
N.B: here string like "276035280975268320779229" changes every time i send request.
Answer: Here is an option using re.findall:
inp = '"body": "----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"status\"\r\n\r\n payment_received_unrecognised\r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"err\"\r\n\r\n An incorrect bitcoin amount has been received\r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"private_key_hash\"\r\n\r\n sadf65d4sf56sd4f6sd54fsdfs....\r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"box\"\r\n\r\n 111\r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"boxtype\"\r\n\r\n criptoBox\r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"order\"\r\n\r\n \r\n----------------------------6547984164*94652165481564\r\nContent-Disposition: form-data; name=\"user\"\r\n\r\n ADAM\r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"userformat\"\r\n\r\n \r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"usercountry\"\r\n\r\n \r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"period\"\r\n\r\n \r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"amount\"\r\n\r\n 0.0016\r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"amountusd\"\r\n\r\n 152.45\r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"coinlabel\"\r\n\r\n BTC\r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"coinname\"\r\n\r\n bitcoin\r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"addr\"\r\n\r\n 14dt4cSbvwghDcETJDuvFGHe5bCsCPR1jW\r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"tx\"\r\n\r\n 6f1c6f34189a27446d18e25b9c79db90be55b0bb775b1768b5aa4520f23d71a8\r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"confirmed\"\r\n\r\n 0\r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"timestamp\"\r\n\r\n 1422623712\r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"date\"\r\n\r\n 30 January 2015\r\n----------------------------276035280975268320779229\r\nContent-Disposition: form-data; name=\"datetime\"\r\n\r\n 2015-01-30 13: 15: 12\r\n----------------------------276035280975268320779229--\r\n"'
my_dict = dict(re.findall(r'\bname="(status|boxtype)"\s+(\S+)', inp))

print(my_dict)

This prints:
{'status': 'payment_received_unrecognised', 'boxtype': 'criptoBox'}

Comment: You could additionally format your regex with the keys that you are searching for, e.g.: `dict(re.findall("({})\"\s+(\S+)".format("|".join(list_of_keys)), inp))` this way you don't have to type every key you are searching for ;)


3 way dimmer on 4 way circuit

Question: I have a 4 way circuit with 6 total switches light switches. One is a dimmer switch. The other 5 switches only work properly when the dimmer switch is on. If the dimmer switch is off the other toggle switches do nothing. Can't turn light on or off.
Also the toggle switches must all be in the on position in order to be able to turn the light on from the dimmer switch. What I mean by this is that if the lights are turned off using one of the toggle switches, and then I try to turn the light on from the dimmer switch, I will need to elk over to one of the toggle switches to turn the light back on.
Hope you can help!  I realize that if the dimmer is dimmed, the toggle switches will turn the lights on dimmed, but it would be nice to be able to use all the switches for on/off.
Comment: Can you post photos of the insides of the boxes, and the model number of the dimmer?
Comment: The dimmer is model Lutron illumatech IPI06. I will post photos of the inside of the boxes as soon as possible. Thanks!
Comment: How did you wire the dimmer? How was the old switch wired?
Comment: Can you get a close-up of the insides of the dimmer-box for us?
Comment: It will only let me upload 2 images.  here is a link to the image of the inside of the dimmer box [dimmer box close up](https://drive.google.com/file/d/0B3U2sRwnpZv2dE0xWDdoNnJYZ0FCTnZ5RHpHOWM4bVpzQlhj/view?usp=sharing). @ThreePhaseEel
Comment: Also IDK if it helps or not, but I tried reversing the gray wires coming from the box to the dimmer switch.  One is connected to the red and one is connected to the black wire on the dimmer, even after flipping them, it functions exactly the same as before flipping them....
Answer: Looking at the Installation Instructions, if you bought the 3-way version then you either miswired it, or tried to install it in place of one of the 4-way switches previously in the circuit.  The 3-way dimmer must be at one end or the other of the circuit.  (if you bought a single pole aka 2-way, then it'll never work).
This little pic shows the layout.  The solid red bars are for one position of each 4-way; the dashed bars are for the other. So long as this particular 3-way dimmer is in one of the 3-way locations, it always passes the "dimmed" voltage to its live leg.
Comment: Something like this got me started in an electrical apprentice back in the 70's I don't know how many switches the contractor blew up from mis-wiring, this looks great Carl +.
Comment: thanks for your help.  I'm a complete novice.  Would you take a look at the photos I added?  Let me know if you can tell the wiring problem?  In the toggle switch box, all 4 wires are gray.  I can see in the box there is a yellow wiring going somewhere in there.
Answer: Your dimmer is miswired in two ways.
First, your house is wired using metal conduit instead of NM cable.  This has a few upsides:

You can add more wires to the conduits if you need to
Everything is wrapped in nice, grounded metal -- no need to worry about nailing through an electrical wire!
You can use whatever colors you want for "hot" wires save for grey, white, or green -- and as you see here, it's a good idea to use multiple colors systematically to tell wires apart

It also means that what you did with the dimmer's green wire is not correct.  In a conduit installation -- instead of nutting off the green pigtail as would be done in an install where there is no ground, you connect it to a 10-32 ground screw driven into a matching hole in the box.
Second, the dimmer's common terminal has been wired to a traveler, and one of the dimmer's travelers to the common wire.  Simply take the black wire from the dimmer and the red wire from the dimmer that's connected to the orange wire and interchange those two connections -- black from the wall should go to red on the dimmer and orange from the wall should go to black on the dimmer.
(Finally, the IPI-06 is made by Leviton, not Lutron -- they both make decent dimmers, though.)
Comment: I just bought this house and imagine that the previous owners installed the dimmers around the house themselves. I have a few areas that have this same problem where the dimmers are. I can't thank you enough!
Comment: I have to admit I left the ground wire capped as it was. I'm not sure exactly what I'm supposed to do with it.
Comment: @VijayShah -- you put a 10-32 screw into a matching hole in the back of the box and then terminate the green pigtail from the dimmer under the screw, just like screwing a wire to a switch terminal.  (Also, don't forget to upvote/accept the answer since it helped you!)
Answer: From the symptoms you describe, it sounds like the switches are all wired in series, since all switches (including the dimmer) need to be on for the light to be on.
If the switches are not so-called "3-way" switches (you can tell because 3-way switches have 3 terminal screws), then there is no way you can wire them up to do what you want. The good news is that is indeed possible to do what you want, and that the switches required to do the job are standard (but not "garden-variety") products, and they'll be more expensive.
If you want to have 3 switches all be able to turn a light on/off independently, you need to buy 2x 3-way switches and 1x 4-way switch. If you want to have 4 switches all be able to turn a light on/off independently, you need to buy 2x 3-way switches and 2x 4-way switches. If you want to have 5 switches all be able to turn a light on/off independently, you need to buy 2x 3-way switches and 3x 4-way switches. I'm sure you can detect the trend here…
In the case of 3 switches, you would wire them as shown here: http://www.buildmyowncabin.com/electrical/how-to-wire-4-way-switch.html
As you add more switches, you effectively extend the switch chain by duplicating the 4-way switches like the middle switch in the diagram. The dimmer would be wired in series at the very end of the chain of switches.
It's a complicated switch wiring job. Good luck!
Comment: I may have explained incorrectly! The dimmer switch seems to be the only issue. As long as the dimmer is on, I can turn on or off from any of the other switches.
Comment: What I mean by this is that if the lights are turned off using one of the toggle switches, and then I try to turn the light on from the dimmer switch, I will need to elk over to one of the toggle switches to turn the light back on.
Comment: Since the other switches function as desired, clearly they are all 4-way (or possible 3-way at each end of the run, of course)
Comment: Thanks for the clarification, Vijay. I was taking your description "the toggle switches must all be in the on position in order to be able to turn the light on" literally. Just another clarification question: is the "off" position of every toggle switch the same no matter what position any other toggle switch is in? That is, if "down" is "off" for switch 1, is "down" still "off" even if the other toggle switches are toggled? If so then you have some arrangement other than 3 or 4-way switching.

3 way dimmer on 4 way circuit


Removing grayscale in HTML in website header image

Question: I am not HTML knowledgeable AT ALL. My post here is about an issue concerning the HTML in this website I'm creating   http://testingthistemplate.weebly.com/
I'm just trying to remove the grayscale code I am using in a Weebly website header. Nobody at Weebly or the Weebly support community is responding to my question. I don't know what to do. All I want is my website headers (they come from a Weebly template) to show the header images (they're mine, that I upload) in their normal color, not black and white.
I would really, really appreciate any help in editing this code below and posting it back up for me to copy. Sorry for the trouble. Thank you!!!!!
body {

height: 100%;

font-size: 15px;

font-family: 'Cabin', Arial, sans-serif;

line-height: 1;

background: #2e2e2e;

color: #818181;

padding: 0 !important;

margin: 0 !important;

-webkit-font-smoothing: antialiased !important;

-moz-font-smoothing: antialiased !important;

-o-font-smoothing: antialiased !important;

-moz-osx-font-smoothing: grayscale;

I would really appreciate your help.
Answer: Try
#wrapper .wsite-background {
   filter : none !important;
}

Answer: You have this CSS in main_style.css stylesheet:
#wrapper .wsite-background {
    width: 100%;
    opacity: 0.4;
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center center;
    background-color: transparent;z-index: 10;
    -moz-filter: grayscale(100%);
    -ms-filter: grayscale(100%);
    -o-filter: grayscale(100%);
    filter: grayscale(100%);
    filter: gray;
}

Notice -moz-filter, -ms-filter, -o-filter, and filter settings? Remove those.
Answer: Try and search through a main_style.css file or something with a .css extension. Ten find a section with this name: #wrapper .wsite-background. Change the following:
-webkit-filter: grayscale(100%);
-moz-filter: grayscale(100%);
-ms-filter: grayscale(100%);
-o-filter: grayscale(100%);
filter: grayscale(100%);
filter: gray;

to
-webkit-filter: none;
-moz-filter: none;
-ms-filter: none;
-o-filter: none;
filter: none;
filter: none;


How to display icons for Service Locations on Maps?

Question: I'm working on displaying icons on maps, there are 3 types of icons:
Pick up point(s): The location that the vehicle should be navigated to
Point of Service: The location that the service will be undertaken
Pointaddress location(s): The location of the addresses
Here is the current solution I'm proposing but not sure if this makes sense and would like some guidance about whether these icons communicate there meaning well?
Comment: Why do you need point of service? What is it?
Comment: The location that the service will be undertaken once the vehicle has navigated to that pick up point. We need the point of service because it's where the crew need to go after they've been to the pick up point. Sometimes the crew need to walk between the two to undertake the service. See the black dotted line on image above.
Comment: The point of service could for example be the location of a bin store.
Comment: It might be worth considering a two stage process where they navigate to the pickup point location and are then prompted with the more accurate location they need to go to upon arrival.
Comment: This is an overview of the crew and what they are doing so there wouldn't be a prompt.
Comment: Looks like an app we did for Glasgow City Council, do they need to see the address? I making an assumption this is the person who booked the job...?
Answer: This question has no right answer. The best way to really know is by doing very good research testing maps apps and prototype this to test with real users. And you can do monitored and unmonitored tests to discover the user behaviour and based on their difficulties you can create new prototypes.
But here is my viewpoint:

The address location looks fine and insignificant for me.
For the others is quite confusing. Maybe you should try something like in my example.

It's important to consider:

What's is the most important information for the user? Give more importance to the icon related to the most important information.
Which other apps your user uses that have maps? Get as a reference and don't do it so differently.
The car route is important or just the pickup point?
Why the point address is so important that is polluting the map?
Why the user needs the service point? What the user will do there?
What the step-by-step for the user use your app?
The user can choose what points he would like to see on the map?
Comment: If you explain a bit more what your app does, maybe we can give some better advice.


Jsf Application closes when I close my browser

Question: I made an jsf application.This application has a menu containing start,stop buttons.When start is pressed , application starts to get data from web sites, and updates its database.The application also has progress bar for update process.However,this process takes a long time to finish.I want that when i close my browser , it should go on updating database.Besides, when i open it again, i should get previous state.However, this isn't happening.When i close browser the application closes too.How do i do that?
Thanks.
Comment: Note: If your method has more than 200 lines, you have a design problem. It would be better to review this method and apply [loose coupling](http://en.wikipedia.org/wiki/Loose_coupling) and [high cohesion](http://en.wikipedia.org/wiki/Cohesion_(computer_science)). Related: [What is high cohesion and how to use it / make it?](http://stackoverflow.com/q/10830135/1065197)
Comment: Could we see your backing bean code?
Comment: Codes are more than 1200 lines, is it necessary ?
Algorithm is :
1.Download files from net.
2.Open files and update database until no files remain.
3.Close files , and done !

Are you asking for java codes or xhmtl codes ?
Comment: I would like to know what is the scope of your Bean which manages the process
Comment: You're right but i mean total line in my class.I don't have a method with more than 1200 lines.Thanks for reply :) .
Comment: Still, looks like lot of code for a single class.
Answer: In my case, I would not extend the session life. Instead, create a task and add the object that performs the task into a Queue in an @ApplicationScoped bean and save in database (or any other place) the user that started the job and the status of the job.
When the user logs off (manually logging off or closing the web browser), the task will still be executed because is managed by the whole application (not by a request nor user session). When the user logs in again, he/she could ask to this application queue about the status of the task.
You will need (at least):

An @ApplicationScoped managed bean that will contain and handle the tasks.
A way to handle and execute one or more tasks at the same time. This could be achieved with a ExecutorService or similar technologies. Note: don't dare to manually start new threads by your own, this will only lead to kill your web application server.
An structure to map the user with the tasks he/she has started. It could be mapped with a Map<String, List<Task>> in order that a single user could have more than 1 task at the moment. It would be better to save this in a database (or similar) in order to have a log for these tasks that don't reside in memory. You can even design this in order that if you undeploy the web application or the server suddenly shut downs, you could restart the tasks at hand from a savestate point.
Comment: Good suggestion.Thanks for reply.My application will be used only by admin.Therefore,only one instance of my app should be run and all admins should get the same progress data.I guess i don't need queue for this.Besides, when i make my app @ApplicationScoped and close browser will the app keep on running?
Comment: yes, the `@ApplicationScoped` managed bean lives until the application is undeployed or the web application server (Tomcat, JBoss, GlassFish, etc.) shuts down.
Comment: I tried @ApplicationScoped and it works as i want.Thank you.I solved the problem thanks to you :) .


How can I make HBase wait to start until HDFS is ready?

Question: I'm building an automated install script for Hadoop, and I'm encountering an issue where HBase won't start, because HDFS isn't yet fully booted and ready. How can I programmatically (from Bash, ideally) tell whether the HDFS system is ready for HBase to boot, so I can wait until it is?
I tried using "hadoop dfsadmin -report" and grepping for the correct number of nodes, but apparently that will still return before the cluster is actually ready for business.
Answer: Use hadoop dfsadmin -safemode wait to check if HDFS is out of safe mode yet. Something like this should do the trick:
while $HADOOP_HOME/bin/hadoop dfsadmin -safemode wait | grep ON
do
    sleep 1s # Or 10s or 1m or whatever time
done

EDIT: As levand mentions in the comment, as per HADOOP-756, -safemode wait will itself wait until safemode is off. In that case, you can simply issue wait and the while loop would be unnecessary. But still, if you want to keep trying only for a certain amount of time and kill the process if DFS is still not up or something, then the while loop might still be useful. I have seen that kind of thing happen when we make mistakes in setting up the cluster.
Comment: Thanks! One question: Reading up on the dfsadmin -safemode wait command (at https://issues.apache.org/jira/browse/HADOOP-756), it looks like `wait` already blocks, eliminating the need to write your own loop. Am I missing something?
Comment: ah, awesome then. Long time since I worked on this.. cluster management was outsourced to another department long back, so now this is all someone else's headache ;D
Comment: `WARNING: Use of this script to execute dfsadmin is deprecated.
WARNING: Attempting to execute replacement "hdfs dfsadmin" instead.`
Answer: It seems like this is a somewhat older post, but I'd like to add to it a little bit.
When starting HDFS, if you use hdfs dfsadmin -safemode wait, it may throw the following exception:
safemode: Call From shworker1/xxx.xxx.xxx.xxx to main:8020 failed on connection exception: java.net.ConnectException: Connection refused; For more details see:  http://wiki.apache.org/hadoop/ConnectionRefused

Obviously, it is caused by HDFS starting incompletion.
Therefore, I've added a simple loop to ensure that HDFS starts up correctly and exits safe mode before proceeding with further operations:
while true; do
    # Block until HDFS exits safe mode or cannot connect to the NameNode
    hdfs dfsadmin -safemode wait
    if [ $? -eq 0 ]; then
        break
    fi
    # Note that HDFS may not have started yet and may throw ConnectException: Connection refused, so we need to continue looping
    sleep 0.5
    echo "HDFS not started yet...Retrying..."
done

Hope this will help you!


jQuery outerWidth with set argument?

Question: As I also faced the problem with jQuery's autocomplete incorrect width  -
I saw this piece of code :
_resizeMenu: function() {
    var ul = this.menu.element;
    ul.outerWidth( Math.max(    //<------
        ul.width( "" ).outerWidth(),
        this.element.outerWidth()
    ) );
}

But AFAIK , outerWidth doesn't take parameter other than bool param to indicate margins.
I don't think they did this only to get truthy , falsy value  , because they wouldn't need MAth.max in order to do it. they could use ||.
What am I missing ?
Answer: See the source of jQuery:
// Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods
jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
    jQuery.each( { padding: "inner" + name, content: type, "": "outer" + name }, function( defaultExtra, funcName ) {
        // margin is only for outerHeight, outerWidth
        jQuery.fn[ funcName ] = function( margin, value ) {
            var chainable = arguments.length && ( defaultExtra || typeof margin !== "boolean" ),
                extra = defaultExtra || ( margin === true || value === true ? "margin" : "border" );

            return jQuery.access( this, function( elem, type, value ) {
                var doc;

                if ( jQuery.isWindow( elem ) ) {
                    // As of 5/8/2012 this will yield incorrect results for Mobile Safari, but there
                    // isn't a whole lot we can do. See pull request at this URL for discussion:
                    // https://github.com/jquery/jquery/pull/764
                    return elem.document.documentElement[ "client" + name ];
                }

                // Get document width or height
                if ( elem.nodeType === 9 ) {
                    doc = elem.documentElement;

                    // Either scroll[Width/Height] or offset[Width/Height] or client[Width/Height], whichever is greatest
                    // unfortunately, this causes bug #3838 in IE6/8 only, but there is currently no good, small way to fix it.
                    return Math.max(
                        elem.body[ "scroll" + name ], doc[ "scroll" + name ],
                        elem.body[ "offset" + name ], doc[ "offset" + name ],
                        doc[ "client" + name ]
                    );
                }

                return value === undefined ?
                    // Get width or height on the element, requesting but not forcing parseFloat
                    jQuery.css( elem, type, extra ) :

                    // Set width or height on the element
                    jQuery.style( elem, type, value, extra );
            }, type, chainable ? margin : undefined, chainable, null );
        };
    });
});

As you can see innerHeight, innerWidth, height, width, outerHeight and outerWidth are all created with the parameters margin and value.
Since the first parameter isn't a boolean (typeof margin !== "boolean"), chainable will be true, which in turn means the margin parameter will be used as the value when calling jQuery.acess (chainable ? margin : undefined).
This means it will call jQuery.style( elem, type, value, extra ) where type is "width", value is the result of Math.max and extra will be "border".
See for yourself what's happening by debugging jquery-1.10.2.js#9746 @ http://jsfiddle.net/95b7K/
Comment: Are you saying that there is an overload which is not documented ?
Comment: Yeah it seems like it. `jQuery.style` also doesn't seems to be documented. Btw, the only difference with calling `width` with a parameter seems to be that `extra` is set to "content".

jQuery outerWidth with set argument?


Samsung induction range pot sensor non-functional

Question: Model number NE58H9970WS/AC
Issue: Large right front burner will not heat -- displays the code for 'no pot detected'. Condition persists with any pot, with or without contents. All other functions are normal.
I read the very helpful thread at Samsung induction stove not detecting cookware. There, pairs of burners (left or right) exhibited a similar problem. Unlike the posts on that thread, only one burners malfunctions on my range, requiring a modified diagnosis.
Does the failure of a single burner eliminate the PCBs as the source of the problem? I could not tell if the load sensing function for both burners was channeled through a single circuit for the PCB controlling that side. Can anyone here say?
Per the earlier thread, I disassembled the range and examined the wiring and the PCBs. I found no wiring issues. Careful examination of the solder points on the three PCBs found no clear failure points. One point was marginally questionable, and I re-soldered it. No change to the problem.
If the PCBs are not the problem, what remains seems to be the button sensor in that burner, and the wiring from the button sensor to the PCB. As noted, the wiring appears in good condition. Does anyone have info about failure of the sensor button? As this part is comparatively cheap, I will try replacing this next.
As always, questions, comments, and insights are appreciated.
Comment: Based on many questions about various types of appliances here and several partly functional ranges seen on my local craigslist, I think the problem is that it says "Samsung" on it. ;^)
Comment: I guess there are differing opinions on their appliances... I have a Samsung microwave oven bought well over two decades ago, that's still performing well :)
Comment: just a thought, were you able to test the buttons with a multi meter? I would imagine they would read as an "open circuit" when they are raised, and when they are pressed in, it would show resistance. Or perhaps the other way around
Answer: Are you sure you are using a large enough pot for that "burner"? On my GE, I have pots that work fine on the three normal induction rings but not on the large-pot one, and I have seen undersized pots that will not be accepted by any.
I presume you have already checked that a magnet will stick to the pot. If it won't, you can't use that pot on an induction cooktop. (If it's oven-safe you might want to retain it for that use.)
(I have seen people try to use a magnetic saucepan to heat a nonmagnetic pot indirectly. Works about as well or poorly as a double-boiler ever works.)


Deleting Data for HABTM in cakephp

Question: i am a new beginner in cakephp. I am trying to do a deletion based on HABTM relationship, but failed. Please help me.
I have three tables: products, users and users_products table.
one product can have many users and one user will have many products. The structure of users_products table is : id, user_id, product_id, renew_id.
I want to delete all datas in users_products and products table when renew_id meet certain condition, but i do not want to touch anything on the users table.
I am thinking to write a while loop to delete the records, but afraid will cause many queries and not using cakephp features.
How can i do this?
Answer: For Has Many and HABTM data deletion we prefer this method
//delete(int $id = null, boolean $cascade = true);
  $this->Product->delete($id,true);

Cascade will work only when the relationship is defined in Model.
Answer: You can delete rows from the join just like any other model.
$this->UsersProduct->delete() or $this->UsersProduct->deleteAll()
If you are using HABTM that relation might not be available so you can define the relations in the models such as User hasMany UsersProduct and Product hasMany UsersProduct, that would allow access from both sides.
You can also use ClassRegistry::init('UsersProduct')->deleteAll()
As a side note, your join model is incorrectly named as it should be ProductsUser based on the conventions, that is join tables are alphabetical order of the join models. Following conventions would give you a table called products_users

Deleting Data for HABTM in cakephp


Can I choose between GNOME Shell and Unity on login?

Question: After installing the gnome-shell package, will I have option to switch between Unity 3D and gnome-shell at the time of logging in (just like we have choice for unity 3d and 2d)?
Comment: Hum, 11.10 already includes GNOME3 - oh, you must be talking about GNOME Shell...
Answer: Install the package gnome-shell, then you get an additional session GNOME in the login screen:

How do I install and use the latest version of GNOME?
Comment: You will also want to install the package gnome-tweak-tool. After installing gnome-shell (more precisely, gnome-themes-standard, which comes with it), you will be able to select the Adwaita theme for windows and GTK+, and the Gnome theme for icons. I really recommend doing this, because Gnome Shell has been crafted very carefully around those themes :)


Get paid to like on facebook legal or illegal? (.. and Google+ ?)

Question: Just checking it for my GPT site,
Is it LEGAL to get pay my users for liking my page on Facebook?
And the same for google+ (Pay my users for pushing the google+ button)?
I searched like whole Facebook / Google to find the guidelines and check this, but i haven't found something.
Thnx!
Comment: Does the number of likes mean so much then?
Answer: It looks like you can as long as the site/application is your own.
From: http://developers.facebook.com/policy/#integration

c. You must not incentivize users to Like any Page other than your own site or application, and any incentive you provide must be available to new and existing users who Like your Page.

As for legal, I honestly can't think of a single law that would be violated if you gave someone money to perform the action of liking your page.


Max flow for a complete graph

Question: What is the maximum flow for any two vertices as source and sink in a complete graph?
My assumption is: V-1. Am I right?
Answer: I assume each edge has capacity 1, and that $V$ is the number of vertices. Only $V-1$ arcs leave the source, so $V-1$ is certainly an upper bound. It's not hard to see it can always be achieved, since for each vertex other than the sink there's a path from the source to that vertex to the sink, and there's a path direct from source to sink.

Max flow for a complete graph


Android device not recognized in eclipse

Question: I tried to plug my Samsung Galaxy S to my Ubuntu box for developing applications in Android, but the problem is that lsusb doesn't recognize the device.
I tried with a friend smartphone and it is recognized, but mine is not.
Any idea?
Comment: The android of your friend have the same android version? As `2.2`, `3.4`, `4.1`..
Answer: A quick search on the web reveals that you have to activate debugging on the phone first.
Comment: I did it already, but no luck.


Data type conversion uint8_t/uint16_t to char[] via snprintf

Question: char data[40] = {'\0'};
uint8_t Plevel= 0xA5;
uint8_t status = 0x21;
uint16_t ID = 0xABCD;

snprintf(data, 5, "%"PRIu8"%"PRIu8"%"PRIu16"",Plevel, status, ID );
printf("data:%s\n",data);

outputs: 1653
I use http://www.asciitohex.com/ to see the conversion but couldn't get why it outputs 1653.
Could anyone please explain the conversions?
Answer: 0xA5 outputs 165. 0x21 outputs 33. 0xABCD outputs 43981. This gives 1653343981. But your output string size is restricted to 5 (including the nul terminator) and so you get 1653.
Comment: thank you:) it is not part of my question, but I would be happy if you could answer it as well. My aim is to store uin8_t as 1 byte (I am trying to do data serialization). Do I need an hex to ASCII converter or can I store it differently via snprintf instead of using "PRIu8"?
Comment: The type `uint8_t` ***is*** stored as one byte. It makes no difference whether you assign a value as hex `0xA5` or a decimal `165`. They both represent the same value. The one byte neither stores `0xA5` nor `165` literally: it holds a bit pattern representing the value.
Comment: I meant, to pass 0xA5 into "data", it requires 3 byte space (string length) on snprintf. but I want to keep it as 1 character instead of 3. Can I use anything else than %"PRIu8" on snprintf for it? or do I need an hex to ASCII converter?
Comment: You can put one or more bytes into a char array (`data[0]=Plevel;`), but you won't be able to use any string functions since the data won't be textual.
Comment: I use snprintf to pass the data to a UDP socket, it is fine if the data is not texual. Do you know if I can pass 0xA5 to the char array as 1 element via snprintf or do I need an ASCII converter?
Comment: I'm sorry I don't understand what you are asking. `snprint(..."%u")` and similar convert a number to ASCII text. You don't need `snprintf()` to put one byte into an array. You just put it in the array.
Comment: Similarly, if you want to put the 16 bit value into a char array, you can do it with `data[0]=ID/256; data[1]=ID%256;`
Comment: Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/83787/discussion-between-sven-and-weather-vane).


SSLProtocolException after parsing CSV lines

Question: I'm downloading a set of CSV lines to my android device through a simple HTTP/GET request via an SSL connection. This worked like a charm until we switch to a new server (Debian 6 -> Debian 7), this may be an issue with the server certificate but I don't think so because the download starts and is parsing about 700 articles before this exception is thrown on .readLine():
(Note that the download have been tested on Android ICS (4.*) and works without any issues, it seems to only affect Android <= 2.3.)
Read error: ssl=0x35e700: Failure in SSL library, usually a protocol error
javax.net.ssl.SSLProtocolException: Read error: ssl=0x35e700: Failure in SSL library, usually a protocol error
    at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_read(Native Method)
    at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketImpl.java:788)
    at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:103)
    at org.apache.http.impl.io.AbstractSessionInputBuffer.read(AbstractSessionInputBuffer.java:134)
    at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:161)
    at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:159)
    at java.io.InputStreamReader.read(InputStreamReader.java:255)
    at java.io.BufferedReader.fillBuf(BufferedReader.java:128)
    at java.io.BufferedReader.readLine(BufferedReader.java:357)
    at xx.xxxxx.services.ArticlesSync.doInBackground(ArticlesSync.java:155)
    at xx.xxxxx.services.ArticlesSync.doInBackground(ArticlesSync.java:26)
    at android.os.AsyncTask$2.call(AsyncTask.java:185)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
    at java.lang.Thread.run(Thread.java:1019)

|
InputStream inputStream = response.getContent();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));

String currentLine = null;
SQLArticleManager articles = SQLArticleManager.createArticles();
while ((currentLine = bufferedReader.readLine()) != null)
{
    if (!progressDialog.isShowing())
    {
        return ERROR_ABORTED;
    }

    String[] data = currentLine.split("`");

    if (data.length == 4)
    {
        articles.addArticle(data[0], data[1], data[2], Float.parseFloat(data[3]));
    }

    rowsRead++;
    publishProgress(createProgress((int) (rowsRead * 100 / rows), ""));
}

Am I doing something wrong here? Can it be due to a timeout somewhere?
Comment: Aside: You said it was a CSV, but then are splitting by not a comma, looks like a '`'?
Comment: The column separator is set to `, yes.
Answer: Sorry to be the bearer of bad news, but this is a known Android bug affecting versions 2.2-2.3.3 (API levels 9 & 10). See this bug and also this bug for more details.
There's a further discussion documenting that this may be an issue with regards to root CA, but the 2nd link there conflicts with this data, so I do not believe this is the case.
What I believe works (though I haven't mocked up a quick sample to verify) is to explicitly use a 4k buffer in conjunction with getInputStream(), i.e.
private static final int BUFFER_SIZE = 4096;

Hope that helps.
Comment: You mean 'new BufferedReader(..., 4096)'? That's the default.
Comment: Incorrect, the default is double that, 8k, 8192 bytes. Check the default constructor here: http://developer.android.com/reference/java/io/BufferedReader.html
Comment: Thanks @Mike. I tried changing the buffer size but no cigar. At least now I know it's a known bug.


How can I trigger Google Spreadsheets script if a specific cell contains a value greater than, say, 10

Question: So I have a script that would launch an e-mail, and I want it to be run when a specific cell (A5) contains a value over 10. Here's the script:
function onEdit() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var rownum = 1; // #of rows
  var rowstart = 2; // where to start row

  // get range of cell
  // column 1 = email, column 2 is first name
  var dataRange = sheet.getRange(rowstart, 1, rownum, 2)

  var data = dataRange.getValues()
  for (i in data) {
    if(sheet.getRange(5,1).getValue()>10){      //change row and column in get range to match what you need
      var row = data[i];
      var emailadr = row[0]; // data select
      var msgcontent = "Hey " + row[1] + ",\n Just:)chilling \n    Sent from my email"; // body
      var sbjt = "You have mail!"; //subject
      MailApp.sendEmail(emailadr, sbjt, msgcontent);}
    }
  }

Under Current project's triggers, I have the following:

Run: onEdit
Events: From spreadsheet On edit

Now, when I set cell "A5" to "21", the script doesn't run. What's the issue? I can't seem to figure it out. Thanks.
Comment: It may be a problem of installable trigger. Was ``onEdit()`` installed as a trigger? When it isn't done, ``authMode=LIMITED``. So e-mail cannot be used.
Comment: Firstly, have you tried to run the function by itself without relying on the trigger? Does it work? Secondly, your code is designed to send  mail to everyone on the list each time you edit anywhere on the sheet. Is that the behavior you want?
Answer: Using logger it shows that it does work. You can see in example below. You may want to try to use a time based trigger and set it to check every x amount of time and send email. Google may not allow the sendemail to run "onedit"

function onEdit() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var rownum = 1; // #of rows
  var rowstart = 2; // where to start row

  // get range of cell
  // column 1 = email, column 2 is first name
  var dataRange = sheet.getRange(rowstart, 1, rownum, 2)

  var data = dataRange.getValues()

 for (i in data) {
   if(sheet.getRange(5,1).getValue()>10){      //change row and column in get range to match what you need
     var row = data[i];
         Logger.log("Yes it is larger than 10");

    //  var emailadr = row[0]; // data select
    //  var msgcontent = "Hey " + row[1] + ",\n Just:)chilling \n    Sent from my email"; // body
    //  var sbjt = "You have mail!"; //subject
    //   MailApp.sendEmail(emailadr, sbjt, msgcontent);
   }
  }
}


Flash access of undefined property

Question: So I am making my first game in flash (more like converting to flash, already have it in JS). I am getting this error:
"access of undefined property item"

and I have no idea why.
addEventListener(Event.ENTER_FRAME, onEnterFrame);

var Entities:Array = new Array();

//Create player
var Player = new Character();
Player.x = stage.stageWidth / 2 - Player.radius;
Player.y = stage.stageHeight / 2 - Player.radius;

Entities.push(Player);
stage.addChild(Player);

function onEnterFrame(event:Event):void
{
    for each (item in Entities)
    {
        item.update();
    }
}

I will be adding many Monsters into entities as well, that's why it's an array.
Answer: The error is because you are referencing a variable called item but you haven't defined it to the compiler.
for each (item in Entities)

Define (var) the item and you will no longer receive the error:
for each (var item:Character in Entities)

I would recommend using a Vector instead of an Array (They are basically the same except in a Vector every object has to be of the defined type. Then you don't have to cast for the compiler to know what kind of object is in your array.
var Entities:Vector.<Character> = new Vector.<Character>();

If you do continue to use Array - you'll need to cast your items in order to access their properties/methods without a compiler error.
Character(item).update(); //since items in arrays are just stored as objects, you need to tell AS3 that this item is a Player class

Comment: so it is impossible to put varius types of objects into one array as in js?
Comment: Not al all, arrays are the same in AS3 as JS.   I'm referring to the difference between `Vector` and `Array` in as3.   If you want multiple class types in your array, then you have to use `Array` and not `Vector` (though if they all have a common base class you could use a vector of said base class).   Vectors (in some cases) are faster, and make life easier while coding because you don't have to cast.
Comment: Thanks a lot for your help, got everything working as I wished now :) also the name of my class is not Player, but Character. Might be confusing for future reference.
Comment: Ah right.  A bit of advice for AS3, recommended practice (though not required so don't feel compelled) is to start all instance names with a lower case letter, and all Class names with an Uppercase letter.  Makes readability easier. (and you'll notice how stackoverflow highlights anything uppercase like it's a class)

Flash access of undefined property


Should I use waterproofing product or caulk at the base of my foundation walls?

Question: So I am about to Drylok my basement to treat old cinder blocks with a hint of moisture. I have the old asbestos tiles on the floor.  I know the dangers of removing these.  Basically all of the tiles along the wall have popped up due to moisture.  So I have the bare slab meeting the wall at the base.
Should I Drylok down to the slab and a couple inches over, or is there some kind of masonry caulk to put down where the slab meets the wall?
Comment: Asbestos is nasty in general, but floor tiles are fairly harmless unless you damage them. Simply removing them carefully should not be a big deal. http://www.cpsc.gov/en/Safety-Education/Safety-Guides/Home/Asbestos-In-The-Home/
Answer: The waterproofing material's spec sheet will tell you how wide of cracks it's designed to accommodate. That should be your guide. If your joints are wider than that, move to a caulk. If they're extremely wide (over 3/8" or so), consider a rope caulk or a masonry patch product as support for the sealer product.


What to do with sprinkler pipe under spiral staircase foundation?

Question: I am planning on adding a spiral staircase to my roof, but after preparing the hole for the concrete foundation, I noticed there is this sprinkler pipe 12 inches under the ground which would be directly under where I would like the foundation to be. Obviously I am worried about the pressure of the staircase/foundation breaking the pipe and causing the ground to sag beneath the foundation. I plan on using about 4" of sand/gravel mix at the bottom of the foundation, and about 8" of concrete above that. The sprinkler pipe (as seen in picture) is about 1/2" wide.
I was thinking about how the options I have to resolve this:
a) re-route sprinkler pipe to go around foundation,
b) increase area of foundation to reduce pressure on pipe (perhaps going from a 1'x1' square to 2'x2' square),
c) encase the pipe in something like a steel cover to protect it from damage.
Option A would be quite challenging, so I was thinking of a combination of option B and C. Does anyone have suggestions as to the best way to tackle this? Appreciate it!
Comment: Option A seems easy to me ...
Comment: Isn't a 1'x1' footer a bit small? I would pour a larger slab so I have not just the footer for the central pillar but also a nice pad as landing-area under the last step of the stairs. Bear in mind that an external spiral staircase is often only attached to the building at the top. Meaning that horizontal load/forces (e.g. wind) may cause over time a small footer to move sideways, especially if the surrounding soil isn't very firm. (It's not the same as footers under a building. There you have multiple footers and a horizontal force that big means you have other things to worry about.)
Comment: Consider yourself coming along in a few years and find that "someone" has put a foundation over the pipe you need to replace,  How mad at them are you for not doing it better?
Answer: Dig the hole bigger.
Buy four elbows, some pipe clamps and some extra pipe.
Turn off the water for that pipe.
Cut the pipe and with the elbows have it go around the box.
Make your footing and no worries about the pipe being under the cement.
The pipe is plastic and easy to cut.
Could make do with just two elbows if you make the hole big enough and have a soft bend in the pipe to go around.  Like a "U".
Comment: Yes. Reroute the pipe now before you have a block of concrete and a structure on top of it. My recommendation would be to cut and abandon the existing pipe in place, leaving the soil as undisturbed as possible, since you're pouring a footing.
Answer: A pipe rupture beneath the foundation could cause soil subsidence that will destroy your staircase.  For that reason I would now route the pipe far from the staircase.  Cut it inside the hole you dug, on both sides, remove the inside piece, backfill with soil and compact that.  Go about 3 feet away from the foundation in both directions, find the pipe, and trench a semicircle staying 3 feet away from the foundation.  Use an elbow at each end to lay a semicircle of pipe.  The two disused pieces of old pipe outside the foundation form can be left in place.
I don't know if 3 feet is the right distance, it's a guess ... hopefully someone can verify or correct that.
Comment: Think three feet would be enough, unless the stream of water was pointed right at the foundation.  This is if the leak was not noticed for some time(wet ground, low pressure).
Answer: It is not even hard PVC pipe which might be ok.
safest option is (a), reroute.
I had few of those (black hoses) suddenly leaking without reason.
Answer: Does the pipe run in a straight line? If not, perhaps it can be rerouted without needing to cut & join it, but rather just digging a new trench offset to the "shorter" side.
Alternatively, consider running an entirely new line, so that you don't have to manage the risk of underground joints failing. If nothing else, it allows you to document where the line goes. (You may get lucky and be able to recycle the existing line.)


Object inside matrix is returning null

Question: I'm having trouble understanding why I'm getting "Cannot read field "pieceColor" because "elem" is null", in this line "if(elem.pieceColor == pieceColor){"
Desired outcome: Given a color of a piece, for example black. Count every black piece in the board, and sum their value, according to the enum "PieceType".
I hope I was clear.
Thank you!
import m2_praticas.xadrez.enums.PieceColor;

public class Main {
    public static void main(String[] args) {
        Board board = new Board();

        System.out.println(board.avalia(PieceColor.BLACK));
    }
}

import m2_praticas.xadrez.enums.PieceColor;
import m2_praticas.xadrez.enums.PieceType;

public class Board {
    Piece board[][];

    public Board(){
        board = new Piece[8][8]; // Creates a new board

        // For loop to set the pieces
        for (int i = 0; i < board.length; i++){ // columns
            for (int j = 0; j < board[i].length; j++){ // rows
                //System.out.println("[" + i + "]" + "[" + j + "]");
                if(i == 0 && j >= 0){ // 0, 0 & 0, 1
                    board[i][j] = new Piece(PieceColor.BLACK, PieceType.ROOK); // 2 black rooks
                }
                if(i == 0 && j >= 2){
                    board[i][j] = new Piece(PieceColor.BLACK, PieceType.KNIGHT); // 2 black knights
                }
                if(i == 0 && j >= 4){
                    board[i][j] = new Piece(PieceColor.BLACK, PieceType.BISHOP); // 2 black bishops
                }
                if(i == 0 && j >= 6){
                    board[i][j] = new Piece(PieceColor.BLACK, PieceType.QUEEN); // 1 black queen
                }
                if(i == 0 && j >= 7){
                    board[i][j] = new Piece(PieceColor.BLACK, PieceType.KING); // 1 black king
                }
                if(i == 1 && j >= 0){
                    board[i][j] = new Piece(PieceColor.BLACK, PieceType.PAWN); // 8 black pawns
                }
                // ---------------------------------
                if(i == 6 && j >= 0){
                    board[i][j] = new Piece(PieceColor.WHITE, PieceType.PAWN); // 8 white pawns
                }
                if(i == 7 && j >= 0){
                    board[i][j] = new Piece(PieceColor.WHITE, PieceType.ROOK); // 2 white rooks
                }
                if(i == 7 && j >= 2){
                    board[i][j] = new Piece(PieceColor.WHITE, PieceType.KNIGHT); // 2 white knights
                }
                if(i == 7 && j >= 4){
                    board[i][j] = new Piece(PieceColor.WHITE, PieceType.BISHOP); // 2 white bishops
                }
                if(i == 7 && j >= 6){
                    board[i][j] = new Piece(PieceColor.WHITE, PieceType.QUEEN); // 1 white queen
                }
                if(i == 7 && j >= 7){
                    board[i][j] = new Piece(PieceColor.WHITE, PieceType.KING); // 1 white king
                }
            }
        }
    }

    public int avalia(PieceColor pieceColor){
        int totalValue = 0;

        for (Piece[] p: board){
            for (Piece elem: p){
                if(elem.pieceColor == pieceColor){
                    switch (elem.pieceType){
                        case PAWN:
                            totalValue = (totalValue + PieceType.PAWN.getPieceValue());
                        break;
                        case ROOK:
                            totalValue = (totalValue + PieceType.ROOK.getPieceValue());
                        break;
                        case KNIGHT:
                            totalValue = (totalValue + PieceType.KNIGHT.getPieceValue());
                        break;
                        case BISHOP:
                            totalValue = (totalValue + PieceType.BISHOP.getPieceValue());
                        break;
                        case QUEEN:
                            totalValue = (totalValue + PieceType.QUEEN.getPieceValue());
                        break;
                        case KING:
                            totalValue = (totalValue + PieceType.KING.getPieceValue());
                        break;

                    }
                }
            }
        }
        return totalValue;
    }
}

import m2_praticas.xadrez.enums.PieceColor;
import m2_praticas.xadrez.enums.PieceType;

public class Piece {
    PieceColor pieceColor;
    PieceType pieceType;

    public Piece(PieceColor pieceColor, PieceType pieceType) {
        this.pieceColor = pieceColor;
        this.pieceType = pieceType;
    }
}

public enum PieceType {
    PAWN(1), ROOK(5), KNIGHT(3), BISHOP(3), QUEEN(9), KING(0);

    private int pieceValue;

    PieceType(int pieceValue){
        this.pieceValue = pieceValue;
    }

    public int getPieceValue() {
        return pieceValue;
    }
}

public enum PieceColor {
    BLACK, WHITE;
}

Comment: When you iterate over the board in
`for (Piece[] p: board){ for (Piece elem: p){`
which is a two-dimensional array, you will get null at every (i, j) where you didn't initialize the value. You can check if `elem != null && elem.pieceColor == pieceColor`. This happens as `p` will always be an array of 8 elements, but only some of them will be initialized. Rest will be `null`.
Comment: Also btw King value is infinite, not 0.
Answer: Items in Java arrays are allowed to be null. Your Board constructor adds pieces to the board but there are no pieces in rows 2, 3, 4 or  5. Those pieces are null.
You must check for null before checking pieceColor
for (Piece elem: p){
  if(elem != null && elem.pieceColor == pieceColor){

or
for (Piece elem: p){
  if (elem == null) continue;
  if(elem.pieceColor == pieceColor){

There are annotations like @CheckForNull that can be used with an IDE or tools like spotbugs to require checking for null. Or you can use the Optional class .
Comment: Yup! I had a faint idea, but was not able to get there. Thank you!

Object inside matrix is returning null


Get height of div in angularjs

Question: I have 3 div in which the data is filling from controller. and the div is dependent on dropdown select (particular div will be shown for particular dropdown value). the problem is that I am unable to get the height of that div when page is loaded and also when I changed the dropdown value. Everytime I am getting 0 height.
here is the code for html:

          <select ng-model="allbrandscategory" ng-change="catChange(allbrandscategory)">
              <option value="all">AllBrands</option>
              <option value="watches">Watches</option>
              <option value="pens">Pens</option>
          </select>

          {{res.name}}

          {{res.name}}

          {{res.name}}

and here is for controller:
// Code goes here

var myapp = angular.module('myModule', []);

myapp.controller('mycntrl',function($scope){

 $scope.allbrandscategory = 'all';
 $scope.firstdiv = true;

 $scope.brands = [
   {name: 'Adidas'},
   {name: 'Armani'}
 ];

  $scope.brands1 = [
    {name: 'Adidas1'},
    {name: 'Armani1'},
    {name: 'Fossil'}
];

  $scope.brands2 = [
    {name: 'Adidas2'},
    {name: 'Armani2'},
    {name: 'Mont blanc'},
    {name: 'calvin'}

];

  $scope.catChange = function(val){

   $scope.firstdiv = false;
   $scope.seconddiv = false;
   $scope.thirddiv = false;
   if(val == 'all')
   {
     $scope.firstdiv = true;
   }
   else if(val == 'watches')
   {
     $scope.seconddiv = true;
   }
   else if(val == 'pens')
   {
       $scope.thirddiv = true;
   }
 };

});

myapp.directive('pensDirective', function($timeout) {
    return {
        restrict: 'A',
        link: function(scope, element) {
        //console.log(element);
        console.log("pens: "+element[0].offsetHeight);
       }
   };
 });
  myapp.directive('watchesDirective', function($timeout) {
    return {
        restrict: 'A',
        link: function(scope, element) {
       // console.log(element);
        console.log('watches: '+element[0].offsetHeight);
       }
    };
  });
  myapp.directive('allbrandsDirective', function($timeout) {
    return {
        restrict: 'A',
        link: function(scope, element) {
        //console.log(element);
        console.log("brand: "+element[0].offsetHeight);
       }
   };
  });

Here is the plunker
Comment: Why do you need height of a div
Comment: Height of div is unknown until it is actually drawn by browser. You can put $timeout() {console.log("brand: "+element[0].offsetHeight);} then you will see some value. However avoid this if you can.
Answer: The link function is executed before the model data is bound to the view (the div does not contain any child elements when you're requesting the offsetHeight. Try wrapping it into a $timeout(function() { /* ... */ }), which will execute at the end of the current digest cycle.
Comment: I have already tried with $timeout function , for eg. I set the interval say 3 sec for all directive but what if I changed the dropdown after 3 sec. I will be getting the height of default selected items but wont be getting other divs height.
Comment: Also; change the `ng-show` to `ng-if` to trigger the `link` function to execute.
Answer: Check out AngularJs event to call after content is loaded
This has a nice answer to your problem and seems to work. Second answer down.
I tested on yours by adding the below to your allbranddirective:
        element.ready(function(){
          console.log("brand: "+element[0].offsetHeight);
        });

EDIT:
HTML:

          <select ng-model="divtoshow" ng-change="catChange(divtoshow)">
              <option value="allbrands-directive">AllBrands</option>
              <option value="watches-directive">Watches</option>
              <option value="pens-directive">Pens</option>
          </select>

{{res.name}}

JS:

var myapp = angular.module('myModule', []);

myapp.controller('mycntrl',function($scope){

  $scope.brands = [{name: 'Adidas'}, {name: 'Armani'}];
  $scope.divtoshow = 'allbrands-directive'

  $scope.catChange = function(val){
    $scope.divtoshow = val;

    if (val == 'allbrands-directive'){
      $scope.brands = [{name: 'Adidas'}, {name: 'Armani'}];
    }else if (val == 'watches-directive') {
      $scope.brands = [{name: 'Adidas1'},{name: 'Armani1'},{name: 'Fossil'}];
    }else if (val == 'pens-directive') {
     $scope.brands = [{name: 'Adidas2'},{name: 'Armani2'},{name: 'Mont blanc'},{name: 'calvin'}];
    }
  }

});

  myapp.directive('allbrandsDirective', function($timeout) {
    return {
        restrict: 'A',
        link: function(scope, element) {

            scope.$watch('brands', function(){
                console.log("brand: "+element[0].offsetHeight);
            });
        }
    };
  });

So I have changed your code a bit, I have set up only one directive and in here I watch on a change of the brands variable, when this changes we then get the height of the element.
See plunker - http://plnkr.co/edit/vZhn2aMRI6wKn3yVharS?p=preview
If you need each section in separate directives see nulls answers
Comment: It will work only for default selected item, what if I change the dropdown value? I wont be getting the other div height when i select other value from dropdown. (Actually I want the height of div related to dropdown. If I select pen then I want the height of thirddiv).
Comment: yes you are right, this is only getting the height of the initial element. I think you may need to create element directives, then call them onto the page with your on change. I don't have time to test this myself at the moment but will later.

Get height of div in angularjs


mac default application for any unknown extension

Question: I have a series of files that are all text files that i want to open with text editor (let's say Sublime).
The extensions on these files follow the pattern:

file.sff123
file.sff124
file.sff125
file.sff126

and so on...
Every time i go to open one of these files, the dialog pops up to select the default application for this file type, but since they all have varying extensions, i have to navigate and select the new file type each time. I literally have 1000s of these files and would like to be able to open all of them. Further, i want to be able to open any unknown file with something like Sublime by default. 99% of the time its a random text file... the 1% that it's not i'll "open with".
Is there a way to get Mac to recognize any unknown file extension and open it with an application of my choosing by default?
Answer: I am not sure if it is possible, but the following (untested) may help you, or someone else work out how to do it.
OSX uses UTIs (Uniform Type Identifiers) to categorise filetypes and map them to applications - and this works in conjunction with Launch Services to launch the appropriate application.
I don't have one of your .sffnnn files available, but I think you need to run mdls on one and see what kMDItemContentType is. You can do that like this in Terminal:
mdls -name kMDItemContentType somefile.sff123

I am  hoping you get the same content type for all your .sffnnn files - if you don't, this approach won't work.
You then need to edit your LaunchServices.plist file which, I think, is in ~/Library/Preferences/com.apple.LaunchServices.plist and make an entry corresponding to the filetype you found above that maps to the sublime application. I suggest you look in there, or the system-wide version to see how entries look.
Once you get the hang of it, you may be able to do it from the command-line  with a command like:
defaults write com.apple.LaunchServices LSHandlers -array-add '{LSHandlerContentType=xxxType;LSHandlerRoleAll=xxx.yyy.sublime;}'


ion-split-pane isn't working as expected

Question: I'm trying to add the split pane to my first view just as say in the documentation, but it isn't working with ionic serve or ionic deploy browser.
I'm using the following:
cli packages: (/usr/lib/node_modules)
@ionic/cli-utils  : 1.19.2
ionic (Ionic CLI) : 3.20.0

global packages:
cordova (Cordova CLI) : 8.0.0

local packages:
@ionic/app-scripts : 3.1.9
Cordova Platforms  : android 7.0.0 browser 5.0.3
Ionic Framework    : ionic-angular 3.9.2

System:
Node : v8.11.0
npm  : 5.6.0
OS   : Linux 4.15

And the code for the view is this:
<ion-split-pane when="xs">

  <ion-menu [content]="content">
    <ion-header>
        <ion-toolbar>
          <ion-title>Menu</ion-title>
        </ion-toolbar>
      </ion-header>
    <ion-content>
      <ion-list>
        <ion-item menuClose ion-item detail-none *ngFor="let p of pages" (click)="openPage(p)">
          {{p.title}}
        </ion-item>
      </ion-list>
    </ion-content>
  </ion-menu>

  <ion-nav [root]="rootPage" main #content></ion-nav>
</ion-split-pane>

I don't now if there was some change from ionic 3 to 4 that wasn't added to the documentation or if I need to add something else for this to work.
Answer: I was using the ionic template super and for some reason it has two menus, one in the app.module.ts template and one  as a page.
The one on app.ts looks like this:
@Component({
  // Menu lateral
  template: `<ion-menu [content]="content">
    <ion-header>
      <ion-toolbar>
        <ion-title>Olá</ion-title>
      </ion-toolbar>
    </ion-header>

    <ion-content>
      <ion-list>
        <button menuClose ion-item detail-none *ngFor="let p of pages" (click)="openPage(p)">
          {{p.title}}
        </button>
      </ion-list>
    </ion-content>

  </ion-menu>
  <ion-nav #content [root]="rootPage"></ion-nav>`
})

So I changed it to :
@Component({
  template: `<ion-nav #content [root]="rootPage"></ion-nav>`
})

And now the ion-split-pane pane is working without any problem.


SCSS / CSS does not select element with two classes if i call only one

Question: I'm working on a wordpress theme, using Mamp Local Server and SCSS to compile CSS.
I have a JS script for menu interaction because my menu has sub-menus.
This is before script:

                            //level 0

                            //level 0

                                 //level 0

            //level 1

                            //level 0

And this is after script:

                            //level 0

                            //level 0

                                 //level 0

 //level 1

                            //level 0

So I set an SCSS rule like this:
.toggled-on {
   display:block;
}

but the element doesn't get the style.
If I change the SCSS rule to this it works:
.children.toggled-on {
   display:block;
}

From what I've learned about CSS it should work in both cases.
Where am I going wrong?
Comment: there is for sure another CSS rule overiding the first one and you fixed the issue by increasing its specificity
Comment: Yes, try `.toggled-on.toggled-on { display:block; }` and if the rule applies, it's a specificity problem
Comment: @elveti It works! i did'nt know that it possible to duplicate class to increase specificity.. thank you for this trick ! This is my first question here on StackOverflow, i need to delete it because is a duplicate?
Answer: As the comments on your original post already suggest, it is probably a specificity problem where another CSS rule is overriding your own.
My Hint: In Firefox you can press Ctrl+Shift+I to open the Inspector. There you can toggle Pseudo Classes like shown in this image:

Then you can see if some other rule is overriding your own CSS rule.
(for example: in the picture shown, min-width of 1264 for html,body is overridden by min-width: auto;) - you can see it is crossed out.
Comment: The problem is that i took a too short look in the inspector , because the rule i set was really deep in the tree, i havent noticed ! Be less lazy, that the point :)  This is my first question here on StackOverflow, i need to delete it because is a duplicate? @DigitalJedi
Comment: @tresor I dont think deleting is necessary. If its a duplicate a moderator will probably take care of it.